1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00
PySolFC/tests/lib/pysol_tests/test_cardsetparser.py
Juhani Numminen 076ee8d11a Run unittests via a single TAP test
Enable standard unittest discovery by creating __init__.py files
and renaming test modules to test*.py.
2021-07-07 18:13:34 +03:00

62 lines
1.7 KiB
Python

# Written by Juhani Numminen, under the MIT Expat License.
import unittest
from pysollib.cardsetparser import parse_cardset_config
from pysollib.resource import CSI, CardsetConfig
class CardsetParserTests(unittest.TestCase):
def _assertCcEqual(self, a, b, msg=None):
"""Assert that CardsetConfig objects a and b have equal attributes."""
return self.assertDictEqual(a.__dict__, b.__dict__, msg)
def test_good_cardset(self):
config_txt = """\
PySolFC solitaire cardset;4;.gif;1;52;7
123-dondorf;Dondorf
79 123 8
16 25 7 7
back01.gif
back01.gif
"""
reference = CardsetConfig()
reference.update(dict(
version=4,
ext='.gif',
type=CSI.TYPE_FRENCH,
ncards=52,
styles=[7],
ident='123-dondorf;Dondorf',
name='Dondorf',
CARDW=79,
CARDH=123,
CARDD=8,
CARD_XOFFSET=16,
CARD_YOFFSET=25,
SHADOW_XOFFSET=7,
SHADOW_YOFFSET=7,
backindex=0,
backnames=['back01.gif'],
))
self._assertCcEqual(
parse_cardset_config(config_txt.split('\n')),
reference,
'parse_cardset_config should parse well-formed v4 config.txt ' +
'correctly')
def test_reject_too_few_fields(self):
config_txt = """\
PySolFC solitaire cardset;4;.gif;1;52
123-dondorf;Dondorf
79 123 8
16 25 7 7
back01.gif
back01.gif
"""
self.assertIsNone(
parse_cardset_config(config_txt.split('\n')),
'parse_cardset_config should reject v4 config.txt with ' +
'a missing field on the first line')