From 8c9b5a10594cd5407374f68cda7f6be73272446a Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Fri, 16 Feb 2024 16:32:33 +0000 Subject: [PATCH] validate_atlases.py: updated validate_mesh_structure_pairs function, test_validation.py: updated tests --- bg_atlasgen/validate_atlases.py | 8 ++++++-- tests/test_unit/test_validation.py | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index b9568bf..fe1373a 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -136,12 +136,16 @@ def validate_mesh_structure_pairs(atlas: BrainGlobeAtlas): if id not in ids_from_mesh_files: in_bg_not_mesh.append(id) - if len(in_mesh_not_bg) or len(in_bg_not_mesh): + if len(in_mesh_not_bg) != 0: raise AssertionError( - f"Structures with ID {in_bg_not_mesh} are in the atlas, but don't have a corresponding mesh file; " f"Structures with IDs {in_mesh_not_bg} have a mesh file, but are not accessible through the atlas." ) + if len(in_bg_not_mesh) != 0: + raise AssertionError( + f"Structures with IDs {in_bg_not_mesh} are in the atlas, but don't have a corresponding mesh file." + ) + def validate_atlas(atlas_name, version, validation_functions): """Validates the latest version of a given atlas""" diff --git a/tests/test_unit/test_validation.py b/tests/test_unit/test_validation.py index 1426242..3670a21 100644 --- a/tests/test_unit/test_validation.py +++ b/tests/test_unit/test_validation.py @@ -84,11 +84,12 @@ def test_validate_mesh_structure_pairs_no_obj(atlas): False for "admba_3d_e11_5_mouse_16um" (it has all pairs): no error is raised by the validation function --> this test function catches it - """ + with pytest.raises( AssertionError, - match=r"Structures with ID \[.*?\] are in the atlas, but don't have a corresponding mesh file;", + #match=r"Structures with IDs \[.*?\] are in the atlas, but don't have a corresponding mesh file.", + match=r"\[.*?\]", ): validate_mesh_structure_pairs(atlas) @@ -102,8 +103,13 @@ def test_validate_mesh_structure_pairs_not_in_atlas(atlas): Currently no atlas fails the validation function this way so the [] is always empty --> this test function should always raise an error """ + with pytest.raises( AssertionError, - match=r"Structures with IDs \[.*?\] have a mesh file, but are not accessible through the atlas.", + #match=r"Structures with IDs \[.*?\] have a mesh file, but are not accessible through the atlas.", + + # Only checks if there's anything in the []. If there isn't --> error + # It runs without an error with "allen_mouse_10um" as it fills the [] + match=r"\[.*?\]", ): validate_mesh_structure_pairs(atlas)