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
5 # http://www.apache.org/licenses/LICENSE-2.0
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
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 _
21 class ShellTest(TestCase):
23 tosca_helloworld = os.path.join(
24 os.path.dirname(os.path.abspath(__file__)),
25 "data/tosca_helloworld.yaml")
27 errornous_template = os.path.join(
28 os.path.dirname(os.path.abspath(__file__)),
29 "data/test_multiple_validation_errors.yaml")
31 def test_missing_arg(self):
32 self.assertRaises(SystemExit, shell.main, '')
34 def test_invalid_arg(self):
35 self.assertRaises(SystemExit, shell.main, 'parse me')
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))
42 def test_template_invalid(self):
43 arg = '--template-file=' + self.errornous_template
44 self.assertRaises(exception.ValidationError, shell.main, [arg])
46 def test_template_valid(self):
47 arg = '--template-file=' + self.tosca_helloworld
51 self.fail(_('The program raised an exception unexpectedly.'))