Skip to content

Commit

Permalink
Fix unit tests for Python 3.11+
Browse files Browse the repository at this point in the history
Python 3.11 changed the implementation of Enum.__format__ method, which now
returns the name of the enum (e.g.  "Catalog.SOURCE") rather than the value
("source"). This broke unit tests which relied on regex matching the value.

This patch fixes the problem in a way which keeps the compatibility with
both older and newer versions of Python.
  • Loading branch information
mjuric committed Jan 25, 2024
1 parent 3358fbc commit d7982a1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def test_wrong_type(association_catalog_info_data, catalog_info_data):
with pytest.raises(TypeError, match="unexpected"):
AssociationCatalogInfo(**catalog_info_data)

with pytest.raises(ValueError, match="type association"):
init_data = association_catalog_info_data.copy()
init_data["catalog_type"] = CatalogType.OBJECT
AssociationCatalogInfo(**init_data)
with pytest.raises(ValueError, match=f"{CatalogType.ASSOCIATION}"):
try:
init_data = association_catalog_info_data.copy()
init_data["catalog_type"] = CatalogType.OBJECT
AssociationCatalogInfo(**init_data)
except Exception as e:
print("XXXXXXXXXX", e)
raise
2 changes: 1 addition & 1 deletion tests/hipscat/catalog/index/test_index_catalog_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_wrong_type(index_catalog_info, catalog_info_data):
with pytest.raises(TypeError, match="unexpected"):
IndexCatalogInfo(**catalog_info_data)

with pytest.raises(ValueError, match="type index"):
with pytest.raises(ValueError, match=f"{CatalogType.INDEX}"):
init_data = index_catalog_info.copy()
init_data["catalog_type"] = CatalogType.OBJECT
IndexCatalogInfo(**init_data)
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_wrong_type(margin_cache_catalog_info, catalog_info_data):
with pytest.raises(TypeError, match="unexpected"):
MarginCacheCatalogInfo(**catalog_info_data)

with pytest.raises(ValueError, match="type margin"):
with pytest.raises(ValueError, match=f"{CatalogType.MARGIN}"):
init_data = margin_cache_catalog_info.copy()
init_data["catalog_type"] = CatalogType.OBJECT
MarginCacheCatalogInfo(**init_data)
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def test_type_missing(source_catalog_info):


def test_wrong_type(source_catalog_info, catalog_info_data):
with pytest.raises(ValueError, match="type source"):
with pytest.raises(ValueError, match=f"{CatalogType.SOURCE}"):
SourceCatalogInfo(**catalog_info_data)

with pytest.raises(ValueError, match="type source"):
with pytest.raises(ValueError, match=f"{CatalogType.SOURCE}"):
init_data = source_catalog_info.copy()
init_data["catalog_type"] = CatalogType.OBJECT
SourceCatalogInfo(**init_data)

0 comments on commit d7982a1

Please sign in to comment.