22import copy
33
44from hed .schema import schema_attribute_validators
5- from hed import schema
5+ from hed import load_schema_version
66
77
88class Test (unittest .TestCase ):
99 @classmethod
1010 def setUpClass (cls ):
11- cls .hed_schema = schema . load_schema_version ("8.1 .0" )
11+ cls .hed_schema = load_schema_version ("8.2 .0" )
1212
1313 def test_util_placeholder (self ):
1414 tag_entry = self .hed_schema .tags ["Event" ]
@@ -39,4 +39,108 @@ def test_util_rooted(self):
3939 self .assertFalse (schema_attribute_validators .tag_exists_base_schema_check (self .hed_schema , tag_entry , attribute_name ))
4040 tag_entry = copy .deepcopy (tag_entry )
4141 tag_entry .attributes ["rooted" ] = "NotRealTag"
42- self .assertTrue (schema_attribute_validators .tag_exists_base_schema_check (self .hed_schema , tag_entry , attribute_name ))
42+ self .assertTrue (schema_attribute_validators .tag_exists_base_schema_check (self .hed_schema , tag_entry , attribute_name ))
43+
44+ def test_unit_class_exists (self ):
45+ tag_entry = self .hed_schema .tags ["Weight/#" ]
46+ attribute_name = "unitClass"
47+ self .assertFalse (schema_attribute_validators .unit_class_exists (self .hed_schema , tag_entry , attribute_name ))
48+
49+ tag_entry = copy .deepcopy (tag_entry )
50+ tag_entry .attributes ["unitClass" ] = "fakeClass"
51+ self .assertTrue (schema_attribute_validators .unit_class_exists (self .hed_schema , tag_entry , attribute_name ))
52+
53+ def test_value_class_exists (self ):
54+ tag_entry = self .hed_schema .tags ["Weight/#" ]
55+ attribute_name = "valueClass"
56+ self .assertFalse (schema_attribute_validators .value_class_exists (self .hed_schema , tag_entry , attribute_name ))
57+
58+ tag_entry = copy .deepcopy (tag_entry )
59+ tag_entry .attributes ["valueClass" ] = "fakeClass"
60+ self .assertTrue (schema_attribute_validators .value_class_exists (self .hed_schema , tag_entry , attribute_name ))
61+
62+ def test_unit_exists (self ):
63+ tag_entry = self .hed_schema .unit_classes ["accelerationUnits" ]
64+ attribute_name = "defaultUnits"
65+ self .assertFalse (schema_attribute_validators .unit_exists (self .hed_schema , tag_entry , attribute_name ))
66+
67+ tag_entry = copy .deepcopy (tag_entry )
68+ tag_entry .attributes ["defaultUnits" ] = "bad_unit"
69+ self .assertTrue (schema_attribute_validators .unit_exists (self .hed_schema , tag_entry , attribute_name ))
70+
71+ def test_deprecatedFrom (self ):
72+ tag_entry = self .hed_schema .tags ["Event/Measurement-event" ]
73+ attribute_name = "deprecatedFrom"
74+ self .assertFalse (schema_attribute_validators .tag_is_deprecated_check (self .hed_schema , tag_entry , attribute_name ))
75+
76+ tag_entry = copy .deepcopy (tag_entry )
77+ tag_entry .attributes ["deprecatedFrom" ] = "200.3.0"
78+ self .assertTrue (schema_attribute_validators .tag_is_deprecated_check (self .hed_schema , tag_entry , attribute_name ))
79+
80+ tag_entry .attributes ["deprecatedFrom" ] = "invalid"
81+ self .assertTrue (schema_attribute_validators .tag_is_deprecated_check (self .hed_schema , tag_entry , attribute_name ))
82+
83+ tag_entry .attributes ["deprecatedFrom" ] = "1"
84+ self .assertTrue (schema_attribute_validators .tag_is_deprecated_check (self .hed_schema , tag_entry , attribute_name ))
85+
86+ tag_entry .attributes ["deprecatedFrom" ] = "8.0.0"
87+ self .assertFalse (schema_attribute_validators .tag_is_deprecated_check (self .hed_schema , tag_entry , attribute_name ))
88+
89+ def test_conversionFactor (self ):
90+ tag_entry = self .hed_schema .unit_classes ["accelerationUnits" ].units ['m-per-s^2' ]
91+ attribute_name = "conversionFactor"
92+ self .assertFalse (schema_attribute_validators .conversion_factor (self .hed_schema , tag_entry , attribute_name ))
93+
94+ tag_entry = copy .deepcopy (tag_entry )
95+ tag_entry .attributes [attribute_name ] = "-1.0"
96+ self .assertTrue (schema_attribute_validators .conversion_factor (self .hed_schema , tag_entry , attribute_name ))
97+
98+ tag_entry .attributes [attribute_name ] = "10^3"
99+ self .assertFalse (schema_attribute_validators .conversion_factor (self .hed_schema , tag_entry , attribute_name ))
100+
101+ tag_entry .attributes [attribute_name ] = None
102+ self .assertTrue (schema_attribute_validators .conversion_factor (self .hed_schema , tag_entry , attribute_name ))
103+
104+ def test_conversionFactor_modifier (self ):
105+ tag_entry = self .hed_schema .unit_classes ["magneticFieldUnits" ].units ['tesla' ]
106+ attribute_name = "conversionFactor"
107+ self .assertFalse (schema_attribute_validators .conversion_factor (self .hed_schema , tag_entry , attribute_name ))
108+
109+ tag_entry = copy .deepcopy (tag_entry )
110+ tag_entry .attributes [attribute_name ] = "-1.0"
111+ self .assertTrue (schema_attribute_validators .conversion_factor (self .hed_schema , tag_entry , attribute_name ))
112+
113+ tag_entry .attributes [attribute_name ] = "10^3"
114+ self .assertFalse (schema_attribute_validators .conversion_factor (self .hed_schema , tag_entry , attribute_name ))
115+
116+ tag_entry .attributes [attribute_name ] = None
117+ self .assertTrue (schema_attribute_validators .conversion_factor (self .hed_schema , tag_entry , attribute_name ))
118+
119+ def test_allowed_characters_check (self ):
120+ tag_entry = self .hed_schema .value_classes ["dateTimeClass" ]
121+ attribute_name = "allowedCharacter"
122+ valid_attributes = {'letters' , 'blank' , 'digits' , 'alphanumeric' , ":" , "$" , "a" }
123+ self .assertFalse (schema_attribute_validators .allowed_characters_check (self .hed_schema , tag_entry , attribute_name ))
124+
125+ tag_entry = copy .deepcopy (tag_entry )
126+ for attribute in valid_attributes :
127+ tag_entry .attributes [attribute_name ] = attribute
128+ self .assertFalse (schema_attribute_validators .allowed_characters_check (self .hed_schema , tag_entry , attribute_name ))
129+
130+ invalid_attributes = {'lettersdd' , 'notaword' , ":a" }
131+ for attribute in invalid_attributes :
132+ tag_entry .attributes [attribute_name ] = attribute
133+ self .assertTrue (schema_attribute_validators .allowed_characters_check (self .hed_schema , tag_entry , attribute_name ))
134+
135+ def test_in_library_check (self ):
136+ score = load_schema_version ("score_" )
137+ tag_entry = score .tags ["Modulator" ]
138+ attribute_name = "inLibrary"
139+ self .assertFalse (schema_attribute_validators .in_library_check (score , tag_entry , attribute_name ))
140+
141+ tag_entry = copy .deepcopy (tag_entry )
142+ tag_entry .attributes [attribute_name ] = "invalid"
143+ self .assertTrue (schema_attribute_validators .in_library_check (score , tag_entry , attribute_name ))
144+
145+ tag_entry .attributes [attribute_name ] = ""
146+ self .assertTrue (schema_attribute_validators .in_library_check (score , tag_entry , attribute_name ))
0 commit comments