-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a new inventory JSON/dict format that preserves more types
It doesn't convert anymore to string primitive types or collections. Signed-off-by: Alexis Jeandet <[email protected]>
- Loading branch information
Showing
6 changed files
with
128 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import unittest | ||
import os | ||
Check notice Code scanning / CodeQL Unused import Note test
Import of 'os' is not used.
|
||
from ddt import ddt, data, unpack | ||
|
||
import speasy as spz | ||
from speasy.core.inventory.indexes import from_dict, to_dict, SpeasyIndex | ||
from speasy.core.dataprovider import DataProvider | ||
|
||
|
||
def compare_inventories(inventory1: SpeasyIndex, inventory2: SpeasyIndex): | ||
if inventory1.spz_name() != inventory2.spz_name(): | ||
print(f"Name mismatch: {inventory1.spz_name()} != {inventory2.spz_name()}") | ||
return False | ||
for key in inventory1.__dict__.keys(): | ||
if key not in inventory2.__dict__: | ||
print(f"Key missing: {key}") | ||
return False | ||
value1 = inventory1.__dict__[key] | ||
value2 = inventory2.__dict__[key] | ||
if isinstance(value1, SpeasyIndex) and isinstance(value2, SpeasyIndex): | ||
if not compare_inventories(value1, value2): | ||
return False | ||
elif value1 != value2: | ||
print(f"Value mismatch: {value1} != {value2}") | ||
return False | ||
return True | ||
|
||
|
||
@ddt | ||
class FromDictAndToDictPreserveInventory(unittest.TestCase): | ||
|
||
def assertInventoryEqual(self, inventory1: SpeasyIndex, inventory2: SpeasyIndex): | ||
if inventory1.spz_name() != inventory2.spz_name(): | ||
self.fail(f"Name mismatch: {inventory1.spz_name()} != {inventory2.spz_name()}") | ||
for key in inventory1.__dict__.keys(): | ||
if key not in inventory2.__dict__: | ||
self.fail(f"Key missing: {key}") | ||
value1 = inventory1.__dict__[key] | ||
value2 = inventory2.__dict__[key] | ||
if isinstance(value1, SpeasyIndex) and isinstance(value2, SpeasyIndex): | ||
self.assertInventoryEqual(value1, value2) | ||
elif value1 != value2: | ||
self.fail(f"Value mismatch: {value1}({type(value1)}) != {value2}({type(value2)}) for key {key}") | ||
|
||
@data( | ||
(spz.amda,), | ||
(spz.cda,), | ||
(spz.ssc,), | ||
(spz.csa,), | ||
) | ||
@unpack | ||
def test_from_dict_and_to_dict_preserve_inventory(self, provider: DataProvider): | ||
inventory = provider._inventory(provider_name=provider.provider_name, disable_proxy=True) | ||
self.assertInventoryEqual(inventory, from_dict(to_dict(inventory, version=2), version=2)) |