Debian Codegraph @

heatclient/tests/unit/test_template_format.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
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))