Kirill Simonov avatar Kirill Simonov committed ae29f09

Fixed test errors for LibYAML bindings; added a test on emitting nodes in all possible styles.

Comments (0)

Files changed (9)

Add a comment to this file

tests/data/emitting-unacceptable-unicode-character-bug.skip-ext

Empty file added.

Add a comment to this file

tests/data/no-alias-anchor.skip-ext

Empty file added.

Add a comment to this file

tests/data/spec-07-01.skip-ext

Empty file added.

Add a comment to this file

tests/data/spec-07-02.skip-ext

Empty file added.

Add a comment to this file

tests/data/spec-08-13.skip-ext

Empty file added.

Add a comment to this file

tests/data/spec-09-20.skip-ext

Empty file added.

tests/test_appliance.py

 class TestAppliance(unittest.TestCase):
 
     DATA = 'tests/data'
+    SKIP_EXT = '.skip'
 
     all_tests = {}
     for filename in os.listdir(DATA):
     def add_tests(cls, method_name, *extensions):
         for test in cls.all_tests:
             available_extensions = cls.all_tests[test]
+            if cls.SKIP_EXT in available_extensions:
+                continue
             for ext in extensions:
                 if ext not in available_extensions:
                     break

tests/test_emitter.py

                     self.failUnlessEqual(event.tag, new_event.tag)
                 self.failUnlessEqual(event.value, new_event.value)
 
+    def _testEmitterStyles(self, test_name, canonical_filename, data_filename):
+        for filename in [canonical_filename, data_filename]:
+            events = list(parse(file(filename, 'rb')))
+            for flow_style in [False, True]:
+                for style in ['|', '>', '"', '\'', '']:
+                    styled_events = []
+                    for event in events:
+                        if isinstance(event, ScalarEvent):
+                            event = ScalarEvent(event.anchor, event.tag,
+                                    event.implicit, event.value, style=style)
+                        elif isinstance(event, SequenceStartEvent):
+                            event = SequenceStartEvent(event.anchor, event.tag,
+                                    event.implicit, flow_style=flow_style)
+                        elif isinstance(event, MappingStartEvent):
+                            event = MappingStartEvent(event.anchor, event.tag,
+                                    event.implicit, flow_style=flow_style)
+                        styled_events.append(event)
+                    stream = StringIO.StringIO()
+                    emit(styled_events, stream)
+                    data = stream.getvalue()
+                    #print data
+                    new_events = list(parse(data))
+                    for event, new_event in zip(events, new_events):
+                        self.failUnlessEqual(event.__class__, new_event.__class__)
+                        if isinstance(event, NodeEvent):
+                            self.failUnlessEqual(event.anchor, new_event.anchor)
+                        if isinstance(event, CollectionStartEvent):
+                            self.failUnlessEqual(event.tag, new_event.tag)
+                        if isinstance(event, ScalarEvent):
+                            #self.failUnlessEqual(event.implicit, new_event.implicit)
+                            if True not in event.implicit+new_event.implicit:
+                                self.failUnlessEqual(event.tag, new_event.tag)
+                            self.failUnlessEqual(event.value, new_event.value)
+
+
     def _dump(self, filename, events, canonical):
         print "="*30
         print "ORIGINAL DOCUMENT:"
 TestEmitter.add_tests('testEmitterOnData', '.canonical', '.data')
 TestEmitter.add_tests('testEmitterOnCanonicalNormally', '.canonical')
 TestEmitter.add_tests('testEmitterOnCanonicalCanonically', '.canonical')
+TestEmitter.add_tests('testEmitterStyles', '.canonical', '.data')
 
 class EventsLoader(Loader):
 

tests/test_yaml_ext.py

 
 import _yaml, yaml
 
+test_appliance.TestAppliance.SKIP_EXT = '.skip-ext'
+
 class TestCVersion(unittest.TestCase):
 
     def testCVersion(self):
                     self.failUnlessEqual(event.implicit, ext_event.implicit)
                 if hasattr(event, 'value'):
                     self.failUnlessEqual(event.value, ext_event.value)
-                if hasattr(event, 'explicit'):
+                if hasattr(event, 'explicit') and event.explicit:
                     self.failUnlessEqual(event.explicit, ext_event.explicit)
                 if hasattr(event, 'version'):
                     self.failUnlessEqual(event.version, ext_event.version)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.