File: test_cardsetparser.py

package info (click to toggle)
pysolfc 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 94,856 kB
  • sloc: python: 82,020; tcl: 4,529; makefile: 65; sh: 57; perl: 48
file content (62 lines) | stat: -rw-r--r-- 1,701 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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')