~ubuntu-branches/ubuntu/vivid/python-heatclient/vivid

« back to all changes in this revision

Viewing changes to heatclient/tests/test_template_format.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-03-06 17:41:15 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20140306174115-ecpzxbyb30tl5i7a
Tags: upstream-0.2.8
ImportĀ upstreamĀ versionĀ 0.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
#    not use this file except in compliance with the License. You may obtain
 
5
#    a copy of the License at
 
6
#
 
7
#         http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
#    Unless required by applicable law or agreed to in writing, software
 
10
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
#    License for the specific language governing permissions and limitations
 
13
#    under the License.
 
14
 
 
15
import mock
 
16
import testscenarios
 
17
import testtools
 
18
import yaml
 
19
 
 
20
from heatclient.common import template_format
 
21
 
 
22
 
 
23
load_tests = testscenarios.load_tests_apply_scenarios
 
24
 
 
25
 
 
26
class YamlParseExceptions(testtools.TestCase):
 
27
 
 
28
    scenarios = [
 
29
        ('scanner', dict(raised_exception=yaml.scanner.ScannerError())),
 
30
        ('parser', dict(raised_exception=yaml.parser.ParserError())),
 
31
        ('reader',
 
32
         dict(raised_exception=yaml.reader.ReaderError('', '', '', '', ''))),
 
33
    ]
 
34
 
 
35
    def test_parse_to_value_exception(self):
 
36
        text = 'not important'
 
37
 
 
38
        with mock.patch.object(yaml, 'load') as yaml_loader:
 
39
            yaml_loader.side_effect = self.raised_exception
 
40
 
 
41
            self.assertRaises(ValueError,
 
42
                              template_format.parse, text)
 
43
 
 
44
    def test_parse_no_version_format(self):
 
45
        yaml = ''
 
46
        self.assertRaises(ValueError, template_format.parse, yaml)
 
47
        yaml2 = '''Parameters: {}
 
48
Mappings: {}
 
49
Resources: {}
 
50
Outputs: {}
 
51
'''
 
52
        self.assertRaises(ValueError, template_format.parse, yaml2)