Debian Codegraph @

src/tinycss/tests/__init__.py

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3
4
5 __license__ = 'GPL v3'
6 __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
7
8 import unittest
9
10
11 def jsonify(tokens):
12 """Turn tokens into "JSON-compatible" data structures."""
13 for token in tokens:
14 if token.type == 'FUNCTION':
15 yield (token.type, token.function_name,
16 list(jsonify(token.content)))
17 elif token.is_container:
18 yield token.type, list(jsonify(token.content))
19 else:
20 yield token.type, token.value
21
22
23 class BaseTest(unittest.TestCase):
24
25 longMessage = True
26 maxDiff = None
27 ae = unittest.TestCase.assertEqual
28
29 def assert_errors(self, errors, expected_errors):
30 """Test not complete error messages but only substrings."""
31 self.ae(len(errors), len(expected_errors))
32 for error, expected in zip(errors, expected_errors):
33 self.assertIn(expected, type(u'')(error))
34
35 def jsonify_declarations(self, rule):
36 return [(decl.name, list(jsonify(decl.value)))
37 for decl in rule.declarations]