File size: 1,523 Bytes
4bc63c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Every entry in the catalog is verifiable, and the catalog has no undeclared conflict."""

import os
import sys
import unittest

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT)

from lingologos_thinkingpython import catalog, shapes  # noqa: E402


class CatalogIntegrity(unittest.TestCase):
    def setUp(self):
        self.entries = catalog.load_entries()

    def test_no_defects(self):
        self.assertEqual(catalog.integrity(self.entries), [])

    def test_every_shape_is_implemented(self):
        available = set(shapes.shapes())
        for entry in self.entries:
            self.assertIn(entry["shape"], available, entry["id"])
            self.assertIn(entry["id"], shapes.EDITORS, entry["id"])
            self.assertIn(entry["id"], shapes.LOCKS, entry["id"])

    def test_every_pair_between_entries_has_a_policy(self):
        policies = catalog.load_policies()
        ids = sorted(entry["id"] for entry in self.entries)
        for i, first in enumerate(ids):
            for second in ids[i + 1:]:
                self.assertIsNotNone(catalog.policy_for(policies, first, second),
                                     "%s|%s" % (first, second))

    def test_lock_text_parses(self):
        import ast
        for entry in self.entries:
            text = shapes.lock(entry["id"], {"symbol": "demo", "value": "255",
                                             "param": "value"})
            ast.parse(text)


if __name__ == "__main__":
    unittest.main()