Emitter is done!!!
[pyyaml/python3.git] / tests / test_detector.py
blob491929d455697e823f0529ebca50790a31c383d3
2 import test_appliance
4 from yaml.reader import Reader
5 from yaml.scanner import Scanner
6 from yaml.parser import *
7 from yaml.composer import *
8 from yaml.resolver import *
9 from yaml.nodes import *
11 class TestDetector(test_appliance.TestAppliance):
13 def _testDetector(self, test_name, data_filename, detect_filename):
14 node = None
15 correct_tag = None
16 try:
17 correct_tag = file(detect_filename, 'rb').read().strip()
18 resolver = Resolver(Composer(Parser(Scanner(Reader(file(data_filename, 'rb'))))))
19 node = list(iter(resolver))[0]
20 self.failUnless(isinstance(node, SequenceNode))
21 for scalar in node.value:
22 self.failUnless(isinstance(scalar, ScalarNode))
23 self.failUnlessEqual(scalar.tag, correct_tag)
24 except:
25 print
26 print "DATA:"
27 print file(data_filename, 'rb').read()
28 print "CORRECT_TAG:"
29 print file(detect_filename, 'rb').read()
30 print "ROOT NODE:", node
31 print "SCALAR NODES:", node.value
32 raise
34 TestDetector.add_tests('testDetector', '.data', '.detect')