Skip to content

Commit 82446c4

Browse files
Fix dev samples (#814)
* initial test refactor * deduplicate game slugs * Update error handling in test_catalog_load_all_game_slugs * load 2smp game from contrib instead of catalog * Update Makefile.am * fix reiley game * correct ext
1 parent 3d64e03 commit 82446c4

4 files changed

Lines changed: 43 additions & 26 deletions

File tree

Makefile.am

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ EXTRA_DIST = \
171171
contrib/games/palf2.efg \
172172
contrib/games/palf3.efg \
173173
contrib/games/palf.efg \
174-
contrib/games/poker2.efg \
175-
contrib/games/poker.efg \
176174
contrib/games/pvw2.efg \
177175
contrib/games/pvw.efg \
178176
contrib/games/sh3.efg \
@@ -188,6 +186,7 @@ EXTRA_DIST = \
188186
contrib/games/work1.efg \
189187
contrib/games/work2.efg \
190188
contrib/games/work3.efg \
189+
contrib/games/2smp.efg \
191190
contrib/games/2x2a.nfg \
192191
contrib/games/2x2const.nfg \
193192
contrib/games/2x2.nfg \
@@ -222,7 +221,6 @@ EXTRA_DIST = \
222221
contrib/games/perfect1.nfg \
223222
contrib/games/perfect2.nfg \
224223
contrib/games/perfect3.nfg \
225-
contrib/games/poker.nfg \
226224
contrib/games/sh3.nfg \
227225
contrib/games/stengel.nfg \
228226
contrib/games/sww1.nfg \
@@ -235,11 +233,15 @@ EXTRA_DIST = \
235233
contrib/games/yamamoto.nfg \
236234
contrib/games/zero.nfg \
237235
src/README.rst \
238-
catalog/2smp.efg \
236+
catalog/bagwell1995.efg \
237+
catalog/myerson1991/fig2_1.efg \
239238
catalog/myerson1991/fig4_2.efg \
239+
catalog/reiley2008/fig1.efg \
240240
catalog/selten1975/fig1.efg \
241241
catalog/selten1975/fig2.efg \
242-
catalog/selten1975/fig3.efg
242+
catalog/selten1975/fig3.efg \
243+
catalog/watson2013/exercise29_6.efg \
244+
catalog/watson2013/fig29_1.efg
243245

244246
core_SOURCES = \
245247
src/core/core.h \

catalog/reiley2008/fig1.efg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ p "" 1 1 "" { "Bet" "Fold" } 0
1616
p "" 2 1 "" { "Call" "Fold" } 0
1717
t "" 1 "Professor Wins Big" { 2, -2 }
1818
t "" 2 "Professor Wins" { 1, -1 }
19-
t "" 4 "Professor Loses" { 1, -1 }
19+
t "" 4 "Professor Loses" { -1, 1 }
2020
p "" 1 2 "" { "Bet" "Fold" } 0
2121
p "" 2 1 "" { "Call" "Fold" } 0
2222
t "" 3 "Professor Loses Big" { -2, 2 }

doc/tutorials/04_creating_images.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"metadata": {},
3939
"outputs": [],
4040
"source": [
41-
"g = gbt.catalog.load(\"2smp\")"
41+
"g = gbt.read_efg(\"../../contrib/games/2smp.efg\")"
4242
]
4343
},
4444
{

tests/test_catalog.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,46 @@
44
import pygambit as gbt
55

66

7-
def test_catalog_load_efg():
8-
"""Test loading an extensive form game"""
9-
g = gbt.catalog.load("selten1975/fig1")
10-
assert isinstance(g, gbt.Game)
11-
assert g.title == "Selten's horse (Selten IJGT 1975, Figure 1)"
12-
13-
14-
# TODO: Reintroduce this test once we have a .nfg game in the catalog
15-
# def test_catalog_load_nfg():
16-
# """Test loading a normal form game"""
17-
# g = gbt.catalog.load("pd")
18-
# assert isinstance(g, gbt.Game)
19-
# assert g.title == "Two person Prisoner's Dilemma game"
7+
@pytest.fixture
8+
def game_slugs():
9+
"""Fixture providing a set of all game slugs in the catalog."""
10+
game_slugs = set()
11+
for resource_path in gbt.catalog._CATALOG_RESOURCE.rglob("*"):
12+
if resource_path.is_file() and resource_path.suffix in gbt.catalog.READERS:
13+
rel_path = resource_path.relative_to(gbt.catalog._CATALOG_RESOURCE)
14+
slug = rel_path.with_suffix("").as_posix()
15+
game_slugs.add(slug)
16+
return game_slugs
17+
18+
19+
def test_catalog_load_all_game_slugs(game_slugs):
20+
"""Test loading all valid game files in the catalog."""
21+
errors = []
22+
for slug in game_slugs:
23+
try:
24+
g = gbt.catalog.load(slug)
25+
assert isinstance(g, gbt.Game), f"Expected gbt.Game, got {type(g)}"
26+
except Exception as e:
27+
errors.append(f"Slug '{slug}' failed with {type(e).__name__}: {e}")
28+
29+
if errors:
30+
pytest.fail(f"Errors loading {len(errors)} game(s):\n" + "\n".join(errors))
2031

2132

2233
def test_catalog_load_invalid_slug():
23-
"""Test loading an invalid game slug"""
34+
"""Test loading an invalid game slug."""
2435
with pytest.raises(FileNotFoundError):
2536
gbt.catalog.load("invalid_slug")
2637

2738

28-
def test_catalog_games():
29-
"""Test games() function returns df of game slugs and titles"""
39+
def test_catalog_games(game_slugs):
40+
"""Test games() function returns df of game slugs and titles."""
3041
all_games = gbt.catalog.games()
3142
assert isinstance(all_games, pd.DataFrame)
32-
assert len(all_games) > 0
33-
assert "myerson1991/fig4_2" in list(all_games.Game)
34-
assert "Myerson (1991) Figure 4.2" in list(all_games.Title)
43+
44+
# The games() function should return exactly the set of slugs found above
45+
assert set(all_games["Game"]) == game_slugs
46+
47+
# Test that standard columns are present
48+
assert "Game" in all_games.columns
49+
assert "Title" in all_games.columns

0 commit comments

Comments
 (0)