2 import unittest
, test_appliance
6 class TestExtVersion(unittest
.TestCase
):
8 def testExtVersion(self
):
9 self
.failUnlessEqual("%s.%s.%s" % _yaml
.get_version(), _yaml
.get_version_string())
11 class TestExtLoader(test_appliance
.TestAppliance
):
13 def _testExtScannerFileInput(self
, test_name
, data_filename
, canonical_filename
):
14 self
._testExtScanner
(test_name
, data_filename
, canonical_filename
, True)
16 def _testExtScanner(self
, test_name
, data_filename
, canonical_filename
, file_input
=False):
18 data
= file(data_filename
, 'r')
20 data
= file(data_filename
, 'r').read()
21 tokens
= list(yaml
.scan(data
))
25 data
= file(data_filename
, 'r')
26 for token
in yaml
.scan(data
, Loader
=yaml
.ExtLoader
):
27 ext_tokens
.append(token
)
28 self
.failUnlessEqual(len(tokens
), len(ext_tokens
))
29 for token
, ext_token
in zip(tokens
, ext_tokens
):
30 self
.failUnlessEqual(token
.__class
__, ext_token
.__class
__)
31 self
.failUnlessEqual((token
.start_mark
.index
, token
.start_mark
.line
, token
.start_mark
.column
),
32 (ext_token
.start_mark
.index
, ext_token
.start_mark
.line
, ext_token
.start_mark
.column
))
33 self
.failUnlessEqual((token
.end_mark
.index
, token
.end_mark
.line
, token
.end_mark
.column
),
34 (ext_token
.end_mark
.index
, ext_token
.end_mark
.line
, ext_token
.end_mark
.column
))
35 if hasattr(token
, 'value'):
36 self
.failUnlessEqual(token
.value
, ext_token
.value
)
40 print file(data_filename
, 'rb').read()
41 print "TOKENS:", tokens
42 print "EXT_TOKENS:", ext_tokens
45 def _testExtParser(self
, test_name
, data_filename
, canonical_filename
):
46 data
= file(data_filename
, 'r').read()
47 events
= list(yaml
.parse(data
))
50 for event
in yaml
.parse(data
, Loader
=yaml
.ExtLoader
):
51 ext_events
.append(event
)
52 #print "EVENT:", event
53 self
.failUnlessEqual(len(events
), len(ext_events
))
54 for event
, ext_event
in zip(events
, ext_events
):
55 self
.failUnlessEqual(event
.__class
__, ext_event
.__class
__)
56 if hasattr(event
, 'anchor'):
57 self
.failUnlessEqual(event
.anchor
, ext_event
.anchor
)
58 if hasattr(event
, 'tag'):
59 self
.failUnlessEqual(event
.tag
, ext_event
.tag
)
60 if hasattr(event
, 'implicit'):
61 self
.failUnlessEqual(event
.implicit
, ext_event
.implicit
)
62 if hasattr(event
, 'value'):
63 self
.failUnlessEqual(event
.value
, ext_event
.value
)
67 print file(data_filename
, 'rb').read()
68 print "EVENTS:", events
69 print "EXT_EVENTS:", ext_events
72 TestExtLoader
.add_tests('testExtScanner', '.data', '.canonical')
73 TestExtLoader
.add_tests('testExtScannerFileInput', '.data', '.canonical')
74 TestExtLoader
.add_tests('testExtParser', '.data', '.canonical')
76 def main(module
='__main__'):
79 if __name__
== '__main__':