@@ -557,6 +557,110 @@ def test_name_start_with_hash(self):
557
557
self .assertEqual ('#hash_start,location=europe level=2.2' , point .to_line_protocol ())
558
558
self .assertEqual (1 , len (warnings ))
559
559
560
+ def test_equality_from_dict (self ):
561
+ point_dict = {
562
+ "measurement" : "h2o_feet" ,
563
+ "tags" : {"location" : "coyote_creek" },
564
+ "fields" : {
565
+ "water_level" : 1.0 ,
566
+ "some_counter" : 108913123234
567
+ },
568
+ "field_types" : {"some_counter" : "float" },
569
+ "time" : 1
570
+ }
571
+ point_a = Point .from_dict (point_dict )
572
+ point_b = Point .from_dict (point_dict )
573
+ self .assertEqual (point_a , point_b )
574
+
575
+ def test_equality (self ):
576
+ # https://github.com/influxdata/influxdb-client-python/issues/623#issue-2048573579
577
+ point_a = (
578
+ Point ("asd" )
579
+ .tag ("foo" , "bar" )
580
+ .field ("value" , 123.45 )
581
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
582
+ )
583
+
584
+ point_b = (
585
+ Point ("asd" )
586
+ .tag ("foo" , "bar" )
587
+ .field ("value" , 123.45 )
588
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
589
+ )
590
+ self .assertEqual (point_a , point_b )
591
+
592
+ def test_not_equal_if_tags_differ (self ):
593
+ point_a = (
594
+ Point ("asd" )
595
+ .tag ("foo" , "bar" )
596
+ .field ("value" , 123.45 )
597
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
598
+ )
599
+
600
+ point_b = (
601
+ Point ("asd" )
602
+ .tag ("foo" , "baz" ) # not "bar"
603
+ .field ("value" , 123.45 )
604
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
605
+ )
606
+ self .assertNotEqual (point_a , point_b )
607
+
608
+ def test_not_equal_if_fields_differ (self ):
609
+ point_a = (
610
+ Point ("asd" )
611
+ .tag ("foo" , "bar" )
612
+ .field ("value" , 123.45 )
613
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
614
+ )
615
+
616
+ point_b = (
617
+ Point ("asd" )
618
+ .tag ("foo" , "bar" )
619
+ .field ("value" , 678.90 ) # not 123.45
620
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
621
+ )
622
+ self .assertNotEqual (point_a , point_b )
623
+
624
+ def test_not_equal_if_measurements_differ (self ):
625
+ point_a = (
626
+ Point ("asd" )
627
+ .tag ("foo" , "bar" )
628
+ .field ("value" , 123.45 )
629
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
630
+ )
631
+
632
+ point_b = (
633
+ Point ("fgh" ) # not "asd"
634
+ .tag ("foo" , "bar" )
635
+ .field ("value" , 123.45 )
636
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
637
+ )
638
+ self .assertNotEqual (point_a , point_b )
639
+
640
+ def test_not_equal_if_times_differ (self ):
641
+ point_a = (
642
+ Point ("asd" )
643
+ .tag ("foo" , "bar" )
644
+ .field ("value" , 123.45 )
645
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
646
+ )
647
+
648
+ point_b = (
649
+ Point ("asd" )
650
+ .tag ("foo" , "bar" )
651
+ .field ("value" , 123.45 )
652
+ .time (datetime (2024 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
653
+ )
654
+ self .assertNotEqual (point_a , point_b )
655
+ def test_not_equal_if_other_is_no_point (self ):
656
+ point_a = (
657
+ Point ("asd" )
658
+ .tag ("foo" , "bar" )
659
+ .field ("value" , 123.45 )
660
+ .time (datetime (2023 , 12 , 19 , 13 , 27 , 42 , 215000 , tzinfo = timezone .utc ))
661
+ )
662
+ not_a_point = "not a point but a string"
663
+ self .assertNotEqual (point_a , not_a_point )
560
664
561
665
if __name__ == '__main__' :
562
666
unittest .main ()
0 commit comments