Fix invalid output of single-quoted scalars in cases when a single
[pyyaml/python3.git] / tests / test_yaml_ext.py
blobffd894f0d28676f5ccdd7079ddd35872fd246585
2 import unittest, test_appliance
4 import _yaml, yaml
6 class TestExtVersion(unittest.TestCase):
8 def testExtVersion(self):
9 self.failUnlessEqual("%s.%s.%s" % _yaml.get_version(), _yaml.get_version_string())
11 class TestExtScanner(test_appliance.TestAppliance):
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
37 TestExtScanner.add_tests('testExtScanner', '.data', '.canonical')
39 def main(module='__main__'):
40 unittest.main(module)
42 if __name__ == '__main__':
43 main()