Sync upstream code
[parser.git] / tosca2heat / tosca-parser / toscaparser / tests / test_shell.py
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 import os
14
15 from toscaparser.common import exception
16 import toscaparser.shell as shell
17 from toscaparser.tests.base import TestCase
18 from toscaparser.utils.gettextutils import _
19
20
21 class ShellTest(TestCase):
22
23     tosca_helloworld = os.path.join(
24         os.path.dirname(os.path.abspath(__file__)),
25         "data/tosca_helloworld.yaml")
26
27     errornous_template = os.path.join(
28         os.path.dirname(os.path.abspath(__file__)),
29         "data/test_multiple_validation_errors.yaml")
30
31     def test_missing_arg(self):
32         self.assertRaises(SystemExit, shell.main, '')
33
34     def test_invalid_arg(self):
35         self.assertRaises(SystemExit, shell.main, 'parse me')
36
37     def test_template_not_exist(self):
38         error = self.assertRaises(
39             ValueError, shell.main, ['--template-file=template.txt'])
40         self.assertEqual(_('"template.txt" is not a valid file.'), str(error))
41
42     def test_template_invalid(self):
43         arg = '--template-file=' + self.errornous_template
44         self.assertRaises(exception.ValidationError, shell.main, [arg])
45
46     def test_template_valid(self):
47         arg = '--template-file=' + self.tosca_helloworld
48         try:
49             shell.main([arg])
50         except Exception:
51             self.fail(_('The program raised an exception unexpectedly.'))