@@ -493,7 +493,7 @@ def test_table_name_set(self, arg):
493
493
self .assertEqual (inst .table_name , str (arg ))
494
494
495
495
def test_list_payload_formatting (self ):
496
- payload = [1 ,"data" , "true" , True ]
496
+ payload = [1 ,"data" , 0.0 , True ]
497
497
498
498
device = CR1000XDevice ("my_device" , self .db , self .conn )
499
499
@@ -514,28 +514,28 @@ def test_list_payload_formatting(self):
514
514
"fields" : [
515
515
{
516
516
"name" : "_0" ,
517
- "type" : "" ,
517
+ "type" : "xsd:short " ,
518
518
"units" : "" ,
519
519
"process" : "" ,
520
520
"settable" : False
521
521
},
522
522
{
523
523
"name" : "_1" ,
524
- "type" : "" ,
524
+ "type" : "xsd:string " ,
525
525
"units" : "" ,
526
526
"process" : "" ,
527
527
"settable" : False
528
528
},
529
529
{
530
530
"name" : "_2" ,
531
- "type" : "" ,
531
+ "type" : "xsd:float " ,
532
532
"units" : "" ,
533
533
"process" : "" ,
534
534
"settable" : False
535
535
},
536
536
{
537
537
"name" : "_3" ,
538
- "type" : "" ,
538
+ "type" : "xsd:boolean " ,
539
539
"units" : "" ,
540
540
"process" : "" ,
541
541
"settable" : False
@@ -557,7 +557,7 @@ def test_list_payload_formatting(self):
557
557
datetime .fromisoformat (formatted ["data" ]["time" ])
558
558
559
559
def test_dict_payload_formatting (self ):
560
- payload = {"temp" : 17.16 , "door_open" : False , "BattV" : 74 , "BattLevel" : 99 }
560
+ payload = {"temp" : 17.16 , "door_open" : False , "BattV" : int ( 1e20 ) , "BattLevel" : 1e-50 }
561
561
562
562
device = CR1000XDevice ("my_dict_device" , self .db , self .conn )
563
563
@@ -578,28 +578,28 @@ def test_dict_payload_formatting(self):
578
578
"fields" : [
579
579
{
580
580
"name" : "temp" ,
581
- "type" : "" ,
581
+ "type" : "xsd:float " ,
582
582
"units" : "" ,
583
583
"process" : "" ,
584
584
"settable" : False
585
585
},
586
586
{
587
587
"name" : "door_open" ,
588
- "type" : "" ,
588
+ "type" : "xsd:boolean " ,
589
589
"units" : "" ,
590
590
"process" : "" ,
591
591
"settable" : False
592
592
},
593
593
{
594
594
"name" : "BattV" ,
595
- "type" : "" ,
595
+ "type" : "xsd:integer " ,
596
596
"units" : "" ,
597
597
"process" : "" ,
598
598
"settable" : False
599
599
},
600
600
{
601
601
"name" : "BattLevel" ,
602
- "type" : "" ,
602
+ "type" : "xsd:double " ,
603
603
"units" : "" ,
604
604
"process" : "" ,
605
605
"settable" : False
@@ -631,5 +631,44 @@ def test_dict_payload_formatting(self):
631
631
632
632
formatted = device ._format_payload (payload )
633
633
datetime .fromisoformat (formatted ["data" ]["time" ])
634
+
635
+ @parameterized .expand ([
636
+ [0 , "xsd:int" ],
637
+ [32767 , "xsd:short" ],
638
+ [- 32768 , "xsd:short" ],
639
+ [- 2147483648 , "xsd:int" ],
640
+ [2147483647 , "xsd:int" ],
641
+ [- 9223372036854775808 , "xsd:long" ],
642
+ [9223372036854775807 , "xsd:long" ],
643
+ [- 9923372036854775808 , "xsd:integer" ],
644
+ [9923372036854775807 , "xsd:integer" ],
645
+ [- 3.4028234663852886e+38 , "xsd:float" ],
646
+ [3.4028234663852886e+38 , "xsd:float" ],
647
+ [- 1.1754943508222875e-38 , "xsd:float" ],
648
+ [1.1754943508222875e-38 , "xsd:float" ],
649
+ [0.0 , "xsd:float" ],
650
+ [1e39 , "xsd:double" ],
651
+ [- 1e39 , "xsd:double" ],
652
+ [1e-39 , "xsd:double" ],
653
+ [- 1e-39 , "xsd:double" ],
654
+ [True , "xsd:boolean" ],
655
+ [False , "xsd:boolean" ],
656
+ [datetime .now ().isoformat (), "xsd:dateTime" ],
657
+ [datetime .now (), "xsd:dateTime" ],
658
+ ["value" , "xsd:string" ]
659
+
660
+ ])
661
+ def test_data_type_matching (self , value , expected ):
662
+ """Tests that the `xsd` data type can be extracted."""
663
+
664
+ result = CR1000XDevice ._get_xsd_type (value )
665
+
666
+ self .assertEqual (result , expected )
667
+
668
+ def test_error_if_xsd_type_not_valid (self ):
669
+
670
+ with self .assertRaises (TypeError ):
671
+ CR1000XDevice ._get_xsd_type (None )
672
+
634
673
if __name__ == "__main__" :
635
674
unittest .main ()
0 commit comments