pyyaml / tests / test_errors.py

Kirill Simonov ed172c1 

Kirill Simonov 9434779 


Kirill Simonov ed172c1 




Kirill Simonov 19493c1 
Kirill Simonov ed172c1 


Kirill Simonov 19493c1 
Kirill Simonov ed172c1 


Kirill Simonov 9434779 



















Kirill Simonov 2d77d67 
Kirill Simonov 9434779 



Kirill Simonov ed172c1 

Kirill Simonov 6932ece 
Kirill Simonov ed172c1 










Kirill Simonov 6932ece 
Kirill Simonov ed172c1 









Kirill Simonov 19493c1 

Kirill Simonov 9434779 

Kirill Simonov ed172c1 
import test_appliance
import test_emitter

import StringIO

from yaml import *

class TestErrors(test_appliance.TestAppliance):

    def _testLoaderErrors(self, test_name, invalid_filename):
        #self._load(invalid_filename)
        self.failUnlessRaises(YAMLError, lambda: self._load(invalid_filename))

    def _testLoaderStringErrors(self, test_name, invalid_filename):
        #self._load_string(invalid_filename)
        self.failUnlessRaises(YAMLError, lambda: self._load_string(invalid_filename))

    def _testEmitterErrors(self, test_name, invalid_filename):
        events = list(load(file(invalid_filename, 'rb').read(),
            Loader=test_emitter.EventsLoader))
        self.failUnlessRaises(YAMLError, lambda: self._emit(events))

    def _testDumperErrors(self, test_name, invalid_filename):
        code = file(invalid_filename, 'rb').read()
        self.failUnlessRaises(YAMLError, lambda: self._dump(code))

    def _dump(self, code):
        try:
            exec code
        except YAMLError, exc:
            #print '.'*70
            #print "%s:" % exc.__class__.__name__, exc
            raise

    def _emit(self, events):
        try:
            emit(events)
        except YAMLError, exc:
            #print '.'*70
            #print "%s:" % exc.__class__.__name__, exc
            raise

    def _load(self, filename):
        try:
            return list(load_all(file(filename, 'rb')))
        except YAMLError, exc:
        #except ScannerError, exc:
        #except ParserError, exc:
        #except ComposerError, exc:
        #except ConstructorError, exc:
            #print '.'*70
            #print "%s:" % exc.__class__.__name__, exc
            raise

    def _load_string(self, filename):
        try:
            return list(load_all(file(filename, 'rb').read()))
        except YAMLError, exc:
        #except ScannerError, exc:
        #except ParserError, exc:
        #except ComposerError, exc:
        #except ConstructorError, exc:
            #print '.'*70
            #print "%s:" % filename
            #print "%s:" % exc.__class__.__name__, exc
            raise

TestErrors.add_tests('testLoaderErrors', '.loader-error')
TestErrors.add_tests('testLoaderStringErrors', '.loader-error')
TestErrors.add_tests('testEmitterErrors', '.emitter-error')
TestErrors.add_tests('testDumperErrors', '.dumper-error')
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.