source: branches/pyyaml3000/tests/test_detector.py @ 55

Revision 55, 1.1 KB checked in by xi, 8 years ago (diff)

Working on Constructor.

RevLine 
[55]1
2import test_appliance
3
4from yaml.reader import Reader
5from yaml.scanner import Scanner
6from yaml.parser import *
7from yaml.composer import *
8from yaml.resolver import *
9from yaml.nodes import *
10
11class TestDetector(test_appliance.TestAppliance):
12
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
33
34TestDetector.add_tests('testDetector', '.data', '.detect')
35
36
Note: See TracBrowser for help on using the repository browser.