source: pyyaml/trunk/tests/test_yaml_ext.py @ 195

Revision 195, 1.7 KB checked in by xi, 8 years ago (diff)

Add pyrex-based bindings for the libyaml scanner.

RevLine 
[195]1
2import unittest, test_appliance
3
4import _yaml, yaml
5
6class TestExtVersion(unittest.TestCase):
7
8    def testExtVersion(self):
9        self.failUnlessEqual("%s.%s.%s" % _yaml.get_version(), _yaml.get_version_string())
10
11class TestExtScanner(test_appliance.TestAppliance):
12
13    def _testExtScanner(self, test_name, data_filename, canonical_filename):
14        data = file(data_filename, 'r').read()
15        tokens = list(yaml.scan(data))
16        ext_tokens = []
17        try:
18            for token in yaml.scan(data, Loader=yaml.ExtLoader):
19                ext_tokens.append(token)
20            self.failUnlessEqual(len(tokens), len(ext_tokens))
21            for token, ext_token in zip(tokens, ext_tokens):
22                self.failUnlessEqual(token.__class__, ext_token.__class__)
23                self.failUnlessEqual((token.start_mark.index, token.start_mark.line, token.start_mark.column),
24                        (ext_token.start_mark.index, ext_token.start_mark.line, ext_token.start_mark.column))
25                self.failUnlessEqual((token.end_mark.index, token.end_mark.line, token.end_mark.column),
26                        (ext_token.end_mark.index, ext_token.end_mark.line, ext_token.end_mark.column))
27                if hasattr(token, 'value'):
28                    self.failUnlessEqual(token.value, ext_token.value)
29        except:
30            print
31            print "DATA:"
32            print file(data_filename, 'rb').read()
33            print "TOKENS:", tokens
34            print "EXT_TOKENS:", ext_tokens
35            raise
36
37TestExtScanner.add_tests('testExtScanner', '.data', '.canonical')
38
39def main(module='__main__'):
40    unittest.main(module)
41
42if __name__ == '__main__':
43    main()
44
Note: See TracBrowser for help on using the repository browser.