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 _testExtScanner(self
, test_name
, data_filename
, canonical_filename
):
14 data
= file(data_filename
, 'r').read()
15 tokens
= list(yaml
.scan(data
))
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
)
32 print file(data_filename
, 'rb').read()
33 print "TOKENS:", tokens
34 print "EXT_TOKENS:", ext_tokens
37 def _testExtParser(self
, test_name
, data_filename
, canonical_filename
):
38 data
= file(data_filename
, 'r').read()
39 events
= list(yaml
.parse(data
))
42 for event
in yaml
.parse(data
, Loader
=yaml
.ExtLoader
):
43 ext_events
.append(event
)
44 #print "EVENT:", event
45 self
.failUnlessEqual(len(events
), len(ext_events
))
46 for event
, ext_event
in zip(events
, ext_events
):
47 self
.failUnlessEqual(event
.__class
__, ext_event
.__class
__)
48 if hasattr(event
, 'anchor'):
49 self
.failUnlessEqual(event
.anchor
, ext_event
.anchor
)
50 if hasattr(event
, 'tag'):
51 self
.failUnlessEqual(event
.tag
, ext_event
.tag
)
52 if hasattr(event
, 'implicit'):
53 self
.failUnlessEqual(event
.implicit
, ext_event
.implicit
)
54 if hasattr(event
, 'value'):
55 self
.failUnlessEqual(event
.value
, ext_event
.value
)
59 print file(data_filename
, 'rb').read()
60 print "EVENTS:", events
61 print "EXT_EVENTS:", ext_events
64 TestExtLoader
.add_tests('testExtScanner', '.data', '.canonical')
65 TestExtLoader
.add_tests('testExtParser', '.data', '.canonical')
67 def main(module
='__main__'):
70 if __name__
== '__main__':