Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_serialize(self):
with open("tests/api/examples/vessel_entity1.json", "r") as f:
serialized = f.read()
deserialized = jsons.loads(serialized, VesselEntity)
assert ve == deserialized
def _read(example_file) -> List[Dict]:
with open(f"tests/api/examples/{example_file}", "r") as f:
return jsons.loads(f.read(), List)
def test_exception_wrong_json(self):
with self.assertRaises(DecodeError):
jsons.loads('{this aint no JSON!')
try:
jsons.loads('{this aint no JSON!')
except DecodeError as err:
self.assertEqual(None, err.target)
self.assertEqual('{this aint no JSON!', err.source)
def test_loads(self):
class A:
def __init__(self):
self.name = 'A'
class B:
def __init__(self, a: A):
self.a = a
self.name = 'B'
s = json.dumps({'a': {'name': 'A'}, 'name': 'B'})
loaded_dict = jsons.loads(s)
self.assertEqual('B', loaded_dict['name'])
self.assertEqual('A', loaded_dict['a']['name'])
loaded_obj = jsons.loads(s, B)
self.assertEqual('B', loaded_obj.name)
self.assertEqual('A', loaded_obj.a.name)
def test_serialize(self):
with open("tests/api/examples/product_entity1.json", "r") as f:
serialized = f.read()
deserialized = jsons.loads(serialized, ProductEntity)
expected = ProductEntity(
id="6f11b0724c9a4e85ffa7f1445bc768f054af755a090118dcf99f14745c261653",
layer="group",
probability=0.9369364,
label="Crude & Condensates",
source="model",
)
assert expected == deserialized
def test_serialize(self):
with open("tests/api/examples/cargo_movements.json", "r") as f:
serialized = f.read()
deserialized = jsons.loads(serialized, List[CargoMovement])
assert [self.cm] == deserialized