| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from unittest import mock |
| 14 |
|
| 15 |
import testscenarios |
| 16 |
import testtools |
| 17 |
import yaml |
| 18 |
|
| 19 |
from heatclient.common import template_format |
| 20 |
|
| 21 |
|
| 22 |
load_tests = testscenarios.load_tests_apply_scenarios |
| 23 |
|
| 24 |
|
| 25 |
class YamlParseExceptions(testtools.TestCase): |
| 26 |
|
| 27 |
scenarios = [ |
| 28 |
('scanner', dict(raised_exception=yaml.scanner.ScannerError())), |
| 29 |
('parser', dict(raised_exception=yaml.parser.ParserError())), |
| 30 |
('reader', |
| 31 |
dict(raised_exception=yaml.reader.ReaderError('', '', '', '', ''))), |
| 32 |
] |
| 33 |
|
| 34 |
def test_parse_to_value_exception(self): |
| 35 |
text = 'not important' |
| 36 |
|
| 37 |
with mock.patch.object(yaml, 'load') as yaml_loader: |
| 38 |
yaml_loader.side_effect = self.raised_exception |
| 39 |
|
| 40 |
self.assertRaises(ValueError, |
| 41 |
template_format.parse, text) |
| 42 |
|
| 43 |
def test_parse_no_version_format(self): |
| 44 |
yaml = '' |
| 45 |
self.assertRaises(ValueError, template_format.parse, yaml) |
| 46 |
yaml2 = '''Parameters: {} |
| 47 |
Mappings: {} |
| 48 |
Resources: {} |
| 49 |
Outputs: {} |
| 50 |
''' |
| 51 |
self.assertRaises(ValueError, template_format.parse, yaml2) |
| 52 |
|
| 53 |
|
| 54 |
class DetailedYAMLParseExceptions(testtools.TestCase): |
| 55 |
|
| 56 |
def test_parse_to_value_exception(self): |
| 57 |
yaml = """not important |
| 58 |
but very: |
| 59 |
- incorrect |
| 60 |
""" |
| 61 |
ex = self.assertRaises(ValueError, template_format.parse, yaml) |
| 62 |
self.assertIn('but very:\n ^', str(ex)) |