| [47] | 1 | |
|---|
| 2 | import test_appliance |
|---|
| 3 | |
|---|
| [58] | 4 | from yaml import * |
|---|
| [47] | 5 | |
|---|
| 6 | class TestErrors(test_appliance.TestAppliance): |
|---|
| 7 | |
|---|
| [140] | 8 | def _testLoaderErrors(self, test_name, invalid_filename): |
|---|
| [47] | 9 | #self._load(invalid_filename) |
|---|
| 10 | self.failUnlessRaises(YAMLError, lambda: self._load(invalid_filename)) |
|---|
| 11 | |
|---|
| [140] | 12 | def _testLoaderStringErrors(self, test_name, invalid_filename): |
|---|
| [47] | 13 | #self._load_string(invalid_filename) |
|---|
| 14 | self.failUnlessRaises(YAMLError, lambda: self._load_string(invalid_filename)) |
|---|
| 15 | |
|---|
| 16 | def _load(self, filename): |
|---|
| [52] | 17 | try: |
|---|
| [136] | 18 | return list(load_all(file(filename, 'rb'))) |
|---|
| [52] | 19 | except YAMLError, exc: |
|---|
| 20 | #except ScannerError, exc: |
|---|
| 21 | #except ParserError, exc: |
|---|
| [53] | 22 | #except ComposerError, exc: |
|---|
| [59] | 23 | #except ConstructorError, exc: |
|---|
| [52] | 24 | #print '.'*70 |
|---|
| 25 | #print "%s:" % exc.__class__.__name__, exc |
|---|
| 26 | raise |
|---|
| [47] | 27 | |
|---|
| 28 | def _load_string(self, filename): |
|---|
| [52] | 29 | try: |
|---|
| [136] | 30 | return list(load_all(file(filename, 'rb').read())) |
|---|
| [59] | 31 | except YAMLError, exc: |
|---|
| [52] | 32 | #except ScannerError, exc: |
|---|
| 33 | #except ParserError, exc: |
|---|
| [53] | 34 | #except ComposerError, exc: |
|---|
| [59] | 35 | #except ConstructorError, exc: |
|---|
| 36 | #print '.'*70 |
|---|
| 37 | #print "%s:" % filename |
|---|
| 38 | #print "%s:" % exc.__class__.__name__, exc |
|---|
| [52] | 39 | raise |
|---|
| [47] | 40 | |
|---|
| [140] | 41 | TestErrors.add_tests('testLoaderErrors', '.loader-error') |
|---|
| 42 | TestErrors.add_tests('testLoaderStringErrors', '.loader-error') |
|---|
| [47] | 43 | |
|---|