get tests working again

This commit is contained in:
sneakers-the-rat 2024-10-17 22:15:30 -07:00
parent fcd8b652ea
commit 1701ef9d7e
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
4 changed files with 17 additions and 20 deletions

View file

@ -20,12 +20,12 @@ def jsonize_array(value: Any, info: SerializationInfo) -> Union[list, dict]:
# pdb.set_trace()
interface_cls = Interface.match_output(value)
array = interface_cls.to_json(value, info)
array = postprocess_json(array, info)
array = postprocess_json(array, info, interface_cls)
return array
def postprocess_json(
array: Union[dict, list], info: SerializationInfo
array: Union[dict, list], info: SerializationInfo, interface_cls: type[Interface]
) -> Union[dict, list]:
"""
Modify json after dumping from an interface

View file

@ -136,7 +136,7 @@ def all_passing_cases_instance(all_passing_cases, tmp_output_dir_func):
for p in DTYPE_AND_INTERFACE_CASES_PASSING
)
)
def dtype_by_interface(request):
def all_passing_cases(request):
"""
Tests for all dtypes by all interfaces
"""
@ -144,7 +144,7 @@ def dtype_by_interface(request):
@pytest.fixture()
def dtype_by_interface_instance(dtype_by_interface, tmp_output_dir_func):
array = dtype_by_interface.array(path=tmp_output_dir_func)
instance = dtype_by_interface.model(array=array)
def dtype_by_interface_instance(all_passing_cases, tmp_output_dir_func):
array = all_passing_cases.array(path=tmp_output_dir_func)
instance = all_passing_cases.model(array=array)
return instance

View file

@ -220,8 +220,8 @@ def test_empty_dataset(dtype, tmp_path):
(H5Proxy(file="test_file.h5", path="/subpath", field="sup"), True),
(H5Proxy(file="test_file.h5", path="/subpath"), False),
(H5Proxy(file="different_file.h5", path="/subpath"), False),
(("different_file.h5", "/subpath", "sup"), ValueError),
("not even a proxy-like thing", ValueError),
(("different_file.h5", "/subpath", "sup"), False),
("not even a proxy-like thing", False),
],
)
def test_proxy_eq(comparison, valid):
@ -232,8 +232,5 @@ def test_proxy_eq(comparison, valid):
proxy_a = H5Proxy(file="test_file.h5", path="/subpath", field="sup")
if valid is True:
assert proxy_a == comparison
elif valid is False:
assert proxy_a != comparison
else:
with pytest.raises(valid):
assert proxy_a == comparison
assert proxy_a != comparison

View file

@ -91,15 +91,15 @@ def test_interface_dump_json(dtype_by_interface_instance):
@pytest.mark.serialization
def test_interface_roundtrip_json(dtype_by_interface, tmp_output_dir_func):
def test_interface_roundtrip_json(all_passing_cases, tmp_output_dir_func):
"""
All interfaces should be able to roundtrip to and from json
"""
if "subclass" in dtype_by_interface.id.lower():
if "subclass" in all_passing_cases.id.lower():
pytest.xfail()
array = dtype_by_interface.array(path=tmp_output_dir_func)
case = dtype_by_interface.model(array=array)
array = all_passing_cases.array(path=tmp_output_dir_func)
case = all_passing_cases.model(array=array)
dumped_json = case.model_dump_json(round_trip=True)
model = case.model_validate_json(dumped_json)
@ -123,16 +123,16 @@ def test_interface_mark_interface(an_interface):
@pytest.mark.serialization
@pytest.mark.parametrize("valid", [True, False])
@pytest.mark.filterwarnings("ignore:Mismatch between serialized mark")
def test_interface_mark_roundtrip(dtype_by_interface, valid, tmp_output_dir_func):
def test_interface_mark_roundtrip(all_passing_cases, valid, tmp_output_dir_func):
"""
All interfaces should be able to roundtrip with the marked interface,
and a mismatch should raise a warning and attempt to proceed
"""
if "subclass" in dtype_by_interface.id.lower():
if "subclass" in all_passing_cases.id.lower():
pytest.xfail()
array = dtype_by_interface.array(path=tmp_output_dir_func)
case = dtype_by_interface.model(array=array)
array = all_passing_cases.array(path=tmp_output_dir_func)
case = all_passing_cases.model(array=array)
dumped_json = case.model_dump_json(
round_trip=True, context={"mark_interface": True}