File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77from abc import abstractmethod
88from enum import Enum
99from math import log
10+ from numbers import Real
1011from pathlib import Path
1112from typing import Generator , Sequence , TypeAlias
1213
@@ -139,7 +140,7 @@ def __init__(
139140 if guid is not None :
140141 self .guid = guid
141142 # use a common UnitRegistry for all variables:
142- self .ureg = UnitRegistry (system = unit_system )
143+ self .ureg : UnitRegistry = UnitRegistry (system = unit_system )
143144 self .copyright , self .license = self .make_copyright_license (copyright , license )
144145 self .guid = guid if guid is not None else uuid .uuid4 ().hex
145146 # print("FLAGS", flags)
@@ -538,8 +539,14 @@ def xml_unit_definitions(self):
538539 "substance" : "mol" ,
539540 "luminosity" : "cd" ,
540541 }.items ():
541- if "[" + key + "]" in dim :
542- exponents .update ({value : str (int (dim ["[" + key + "]" ]))})
542+ dim_key = f"[{ key } ]"
543+ if dim_key not in dim :
544+ continue
545+ dim_value = dim [dim_key ]
546+ if not isinstance (dim_value , Real ):
547+ logger .debug ("Skipping non-real dimensionality entry for %s" , dim_key )
548+ continue
549+ exponents .update ({value : str (int (float (dim_value )))})
543550 if (
544551 "radian" in str (ubase .units )
545552 ): # radians are formally a dimensionless quantity. To include 'rad' as specified in FMI standard this dirty trick is used
Original file line number Diff line number Diff line change 77
88logger = logging .getLogger (__name__ )
99
10- _reg = UnitRegistry (system = "SI" , autoconvert_offset_to_baseunit = True ) # , auto_reduce_dimensions=True)
10+ _reg : UnitRegistry = UnitRegistry (system = "SI" , autoconvert_offset_to_baseunit = True ) # , auto_reduce_dimensions=True)
1111
1212
1313def test_needed_functions ():
14- _reg = UnitRegistry (system = "SI" , autoconvert_offset_to_baseunit = True ) # , auto_reduce_dimensions=True)
14+ _reg : UnitRegistry = UnitRegistry (system = "SI" , autoconvert_offset_to_baseunit = True ) # , auto_reduce_dimensions=True)
1515 print ("AVAILABLE UNITS" , dir (_reg .sys .SI ))
1616 print (
1717 "degrees_Celsius defined?" ,
Original file line number Diff line number Diff line change @@ -28,12 +28,24 @@ def dicts_equal(d1: dict, d2: dict):
2828 assert isinstance (d2 , dict ), f"Dict expected. Found { d2 } "
2929 for key in d1 :
3030 assert key in d2 , f"Key { key } not found in { d2 } "
31- if key != "copyright" : # copyright changes with the year!
32- assert d1 [key ] == d2 [key ], f"Value of key { key } { d1 [key ]} != { d2 [key ]} "
31+ if key == "copyright" :
32+ continue # copyright changes with the year!
33+ if key == "license" :
34+ assert " " .join (str (d1 [key ]).split ()) == " " .join (str (d2 [key ]).split ()), (
35+ f"Value of key { key } differs after whitespace normalization\n { d1 [key ]!r} \n !=\n { d2 [key ]!r} "
36+ )
37+ continue
38+ assert d1 [key ] == d2 [key ], f"Value of key { key } { d1 [key ]} != { d2 [key ]} "
3339 for key in d2 :
3440 assert key in d1 , f"Key { key } not found in { d1 } "
35- if key != "copyright" : # copyright changes with the year!
36- assert d1 [key ] == d2 [key ], f"Value of key { key } { d1 [key ]} != { d2 [key ]} "
41+ if key == "copyright" :
42+ continue # copyright changes with the year!
43+ if key == "license" :
44+ assert " " .join (str (d1 [key ]).split ()) == " " .join (str (d2 [key ]).split ()), (
45+ f"Value of key { key } differs after whitespace normalization\n { d1 [key ]!r} \n !=\n { d2 [key ]!r} "
46+ )
47+ continue
48+ assert d1 [key ] == d2 [key ], f"Value of key { key } { d1 [key ]} != { d2 [key ]} "
3749
3850
3951def test_xml_to_python_val ():
You can’t perform that action at this time.
0 commit comments