Merge "Create a constants.py to manage constant variable consistently"
[yardstick.git] / tests / unit / benchmark / scenarios / parser / test_parser.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.parser.Parser
13
14 import mock
15 import unittest
16 import json
17
18 from yardstick.benchmark.scenarios.parser import parser
19
20 @mock.patch('yardstick.benchmark.scenarios.parser.parser.subprocess')
21 class ParserTestCase(unittest.TestCase):
22
23     def setUp(self):
24         pass
25
26     def test_parser_successful_setup(self, mock_subprocess):
27
28         p = parser.Parser({}, {})
29         mock_subprocess.call().return_value = 0
30         p.setup()
31         self.assertEqual(p.setup_done, True)
32
33     def test_parser_successful(self, mock_subprocess):
34         args = {
35             'options': {'yangfile':'/root/yardstick/samples/yang.yaml',
36             'toscafile':'/root/yardstick/samples/tosca.yaml'},
37         }
38         p = parser.Parser(args, {})
39         result = {}
40         mock_subprocess.call().return_value = 0
41         sample_output = '{"yangtotosca": "success"}'
42
43         p.run(result)
44         expected_result = json.loads(sample_output)
45
46     def test_parser_teardown_successful(self, mock_subprocess):
47
48         p = parser.Parser({}, {})
49         mock_subprocess.call().return_value = 0
50         p.teardown()
51         self.assertEqual(p.teardown_done, True)
52
53
54 def main():
55     unittest.main()
56
57 if __name__ == '__main__':
58     main()