From 9cafec6bc174290133087338e012553e80ffb506 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Thu, 19 Mar 2026 10:12:37 +0000 Subject: [PATCH 1/7] initial test refactor --- tests/test_catalog.py | 52 +++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/tests/test_catalog.py b/tests/test_catalog.py index be4903a20..df02fcd1d 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -4,31 +4,45 @@ import pygambit as gbt -def test_catalog_load_efg(): - """Test loading an extensive form game""" - g = gbt.catalog.load("selten1975/fig1") - assert isinstance(g, gbt.Game) - assert g.title == "Selten's horse (Selten IJGT 1975, Figure 1)" - - -# TODO: Reintroduce this test once we have a .nfg game in the catalog -# def test_catalog_load_nfg(): -# """Test loading a normal form game""" -# g = gbt.catalog.load("pd") -# assert isinstance(g, gbt.Game) -# assert g.title == "Two person Prisoner's Dilemma game" +@pytest.fixture +def game_slugs(): + """Fixture providing a set of all game slugs in the catalog.""" + game_slugs = set() + for resource_path in gbt.catalog._CATALOG_RESOURCE.rglob("*"): + if resource_path.is_file() and resource_path.suffix in gbt.catalog.READERS: + rel_path = resource_path.relative_to(gbt.catalog._CATALOG_RESOURCE) + slug = rel_path.with_suffix("").as_posix() + game_slugs.add(slug) + return game_slugs + + +def test_catalog_load_all_game_slugs(game_slugs): + """Test loading all valid game files in the catalog.""" + for resource_path in gbt.catalog._CATALOG_RESOURCE.rglob("*"): + if resource_path.is_file() and resource_path.suffix in gbt.catalog.READERS: + rel_path = resource_path.relative_to(gbt.catalog._CATALOG_RESOURCE) + slug = rel_path.with_suffix("").as_posix() + game_slugs.add(slug) + + for slug in game_slugs: + g = gbt.catalog.load(slug) + assert isinstance(g, gbt.Game) def test_catalog_load_invalid_slug(): - """Test loading an invalid game slug""" + """Test loading an invalid game slug.""" with pytest.raises(FileNotFoundError): gbt.catalog.load("invalid_slug") -def test_catalog_games(): - """Test games() function returns df of game slugs and titles""" +def test_catalog_games(game_slugs): + """Test games() function returns df of game slugs and titles.""" all_games = gbt.catalog.games() assert isinstance(all_games, pd.DataFrame) - assert len(all_games) > 0 - assert "myerson1991/fig4_2" in list(all_games.Game) - assert "Myerson (1991) Figure 4.2" in list(all_games.Title) + + # The games() function should return exactly the set of slugs found above + assert set(all_games["Game"]) == game_slugs + + # Test that standard columns are present + assert "Game" in all_games.columns + assert "Title" in all_games.columns From 7662d7bcbde02165ea3d2af73ab7832167334f78 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Thu, 19 Mar 2026 10:13:57 +0000 Subject: [PATCH 2/7] deduplicate game slugs --- tests/test_catalog.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test_catalog.py b/tests/test_catalog.py index df02fcd1d..3a465634c 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -18,12 +18,6 @@ def game_slugs(): def test_catalog_load_all_game_slugs(game_slugs): """Test loading all valid game files in the catalog.""" - for resource_path in gbt.catalog._CATALOG_RESOURCE.rglob("*"): - if resource_path.is_file() and resource_path.suffix in gbt.catalog.READERS: - rel_path = resource_path.relative_to(gbt.catalog._CATALOG_RESOURCE) - slug = rel_path.with_suffix("").as_posix() - game_slugs.add(slug) - for slug in game_slugs: g = gbt.catalog.load(slug) assert isinstance(g, gbt.Game) From eb003b8ba24a579f886e5a654bcf1456182588e7 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Thu, 19 Mar 2026 11:10:49 +0000 Subject: [PATCH 3/7] Update error handling in test_catalog_load_all_game_slugs --- tests/test_catalog.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 3a465634c..c010c2a51 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -18,9 +18,16 @@ def game_slugs(): def test_catalog_load_all_game_slugs(game_slugs): """Test loading all valid game files in the catalog.""" + errors = [] for slug in game_slugs: - g = gbt.catalog.load(slug) - assert isinstance(g, gbt.Game) + try: + g = gbt.catalog.load(slug) + assert isinstance(g, gbt.Game), f"Expected gbt.Game, got {type(g)}" + except Exception as e: + errors.append(f"Slug '{slug}' failed with {type(e).__name__}: {e}") + + if errors: + pytest.fail(f"Errors loading {len(errors)} game(s):\n" + "\n".join(errors)) def test_catalog_load_invalid_slug(): From 051820e5c1a4ec7af9cf93621a5ea27b924daff1 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Thu, 19 Mar 2026 11:24:13 +0000 Subject: [PATCH 4/7] load 2smp game from contrib instead of catalog --- doc/tutorials/04_creating_images.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorials/04_creating_images.ipynb b/doc/tutorials/04_creating_images.ipynb index bd6e7e106..ec15e8f76 100644 --- a/doc/tutorials/04_creating_images.ipynb +++ b/doc/tutorials/04_creating_images.ipynb @@ -38,7 +38,7 @@ "metadata": {}, "outputs": [], "source": [ - "g = gbt.catalog.load(\"2smp\")" + "g = gbt.read_efg(\"../../contrib/games/2smp.efg\")" ] }, { From 9d09619748f0114505711961521a54a8f0f092b8 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Thu, 19 Mar 2026 11:29:37 +0000 Subject: [PATCH 5/7] Update Makefile.am --- Makefile.am | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index 84434fe9a..630907a9c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -171,8 +171,6 @@ EXTRA_DIST = \ contrib/games/palf2.efg \ contrib/games/palf3.efg \ contrib/games/palf.efg \ - contrib/games/poker2.efg \ - contrib/games/poker.efg \ contrib/games/pvw2.efg \ contrib/games/pvw.efg \ contrib/games/sh3.efg \ @@ -188,6 +186,7 @@ EXTRA_DIST = \ contrib/games/work1.efg \ contrib/games/work2.efg \ contrib/games/work3.efg \ + contrib/games/2smp.nfg \ contrib/games/2x2a.nfg \ contrib/games/2x2const.nfg \ contrib/games/2x2.nfg \ @@ -222,7 +221,6 @@ EXTRA_DIST = \ contrib/games/perfect1.nfg \ contrib/games/perfect2.nfg \ contrib/games/perfect3.nfg \ - contrib/games/poker.nfg \ contrib/games/sh3.nfg \ contrib/games/stengel.nfg \ contrib/games/sww1.nfg \ @@ -235,11 +233,15 @@ EXTRA_DIST = \ contrib/games/yamamoto.nfg \ contrib/games/zero.nfg \ src/README.rst \ - catalog/2smp.efg \ + catalog/bagwell1995.efg \ + catalog/myerson1991/fig2_1.efg \ catalog/myerson1991/fig4_2.efg \ + catalog/reiley2008/fig1.efg \ catalog/selten1975/fig1.efg \ catalog/selten1975/fig2.efg \ - catalog/selten1975/fig3.efg + catalog/selten1975/fig3.efg \ + catalog/watson2013/exercise29_6.efg \ + catalog/watson2013/fig29_1.efg core_SOURCES = \ src/core/core.h \ From 010158783137b0d2e84eb6cdd42f4fa35c4e0272 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Thu, 19 Mar 2026 11:36:48 +0000 Subject: [PATCH 6/7] fix reiley game --- catalog/reiley2008/fig1.efg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catalog/reiley2008/fig1.efg b/catalog/reiley2008/fig1.efg index cb3e698a6..9083ff0f6 100644 --- a/catalog/reiley2008/fig1.efg +++ b/catalog/reiley2008/fig1.efg @@ -16,7 +16,7 @@ p "" 1 1 "" { "Bet" "Fold" } 0 p "" 2 1 "" { "Call" "Fold" } 0 t "" 1 "Professor Wins Big" { 2, -2 } t "" 2 "Professor Wins" { 1, -1 } -t "" 4 "Professor Loses" { 1, -1 } +t "" 4 "Professor Loses" { -1, 1 } p "" 1 2 "" { "Bet" "Fold" } 0 p "" 2 1 "" { "Call" "Fold" } 0 t "" 3 "Professor Loses Big" { -2, 2 } From cff6c493920a584577f0da559675cac47e7c0b08 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Thu, 19 Mar 2026 11:40:15 +0000 Subject: [PATCH 7/7] correct ext --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 630907a9c..85fa72068 100644 --- a/Makefile.am +++ b/Makefile.am @@ -186,7 +186,7 @@ EXTRA_DIST = \ contrib/games/work1.efg \ contrib/games/work2.efg \ contrib/games/work3.efg \ - contrib/games/2smp.nfg \ + contrib/games/2smp.efg \ contrib/games/2x2a.nfg \ contrib/games/2x2const.nfg \ contrib/games/2x2.nfg \