Skip to content

Commit 88e1346

Browse files
use game description field if no docstring is provided
1 parent 510b135 commit 88e1346

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/pygambit/catalog/catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _extract_metadata_from_game(cls, game: Game) -> None:
4343
if cls.__doc__:
4444
cls.description = inspect.cleandoc(cls.__doc__)
4545
else:
46-
cls.description = game.comment
46+
cls.description = game.description
4747

4848
def __init_subclass__(cls, **kwargs):
4949
"""Extract metadata when subclass is defined (if not a file-based game)."""

src/pygambit/game.pxi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,16 +661,16 @@ class Game:
661661
self.game.deref().SetTitle(value.encode("ascii"))
662662

663663
@property
664-
def comment(self) -> str:
665-
"""Get or set the comment of the game.
664+
def description(self) -> str:
665+
"""Get or set the description of the game.
666666

667-
A game's comment is an arbitrary string, and may be more discursive
667+
A game's description/comment is an arbitrary string, and may be more discursive
668668
than a title.
669669
"""
670670
return self.game.deref().GetComment().decode("ascii")
671671

672-
@comment.setter
673-
def comment(self, value: str) -> None:
672+
@description.setter
673+
def description(self, value: str) -> None:
674674
self.game.deref().SetComment(value.encode("ascii"))
675675

676676
@property

tests/test_catalog.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55

66

77
class ExampleGame(CatalogGame):
8-
"""
9-
Test game description.
10-
"""
118

129
game_type = "efg"
1310

1411
@staticmethod
1512
def _game(some_param: bool = False):
1613
if some_param:
17-
return Game.new_tree(
14+
g = Game.new_tree(
1815
players=["A", "B"], title="Test game T"
1916
)
20-
return Game.new_tree(
21-
players=["A", "B"], title="Test game F"
22-
)
17+
else:
18+
g = Game.new_tree(
19+
players=["A", "B"], title="Test game F"
20+
)
21+
g.description = "Test game description."
22+
return g
23+
24+
25+
class ExampleGameWithDocstring(ExampleGame):
26+
"""
27+
Alternative test game description.
28+
"""
2329

2430

2531
class TestCatalogGame:
@@ -37,6 +43,10 @@ def test_custom_game_subclass_extracts_metadata(self):
3743
assert ExampleGame.title == "Test game F"
3844
assert ExampleGame.description == "Test game description."
3945

46+
def test_can_get_game_description_from_docstring(self):
47+
"""CatalogGame should get description from docstring over game description."""
48+
assert ExampleGameWithDocstring.description == "Alternative test game description."
49+
4050
def test_catalog_py_game_with_parameters(self):
4151
"""
4252
Custom CatalogGame subclass should return Game

0 commit comments

Comments
 (0)