-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathats_object2cfg_test.py
106 lines (89 loc) · 3.78 KB
/
ats_object2cfg_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: UTF-8 -*-
'''
Module
ats_object2cfg_test.py
Copyright
Copyright (C) 2017 - 2024 Vladimir Roncevic <elektron.ronca@gmail.com>
ats_utilities is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ats_utilities is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
Info
Defines classes Object2CfgTestCase with attribute(s) and method(s).
Creates test cases for checking functionalities of Object2Cfg.
Execute
python3 -m unittest -v ats_object2cfg_test
'''
import sys
from typing import List
from typing import Any, Dict
from unittest import TestCase, main
from os.path import dirname
try:
from ats_utilities.config_io.cfg.object2cfg import Object2Cfg
from ats_utilities.exceptions.ats_type_error import ATSTypeError
except ImportError as test_error_message:
# Force close python test #################################################
sys.exit(f'\n{__file__}\n{test_error_message}\n')
__author__ = 'Vladimir Roncevic'
__copyright__ = '(C) 2024, https://vroncevic.github.io/ats_utilities'
__credits__: List[str] = ['Vladimir Roncevic', 'Python Software Foundation']
__license__ = 'https://github.com/vroncevic/ats_utilities/blob/dev/LICENSE'
__version__ = '3.3.2'
__maintainer__ = 'Vladimir Roncevic'
__email__ = 'elektron.ronca@gmail.com'
__status__ = 'Updated'
class Object2CfgTestCase(TestCase):
'''
Defines class Object2CfgTestCase with attribute(s) and method(s).
Creates test cases for checking Object2Cfg interfaces.
Object2Cfg unit tests.
It defines:
:attributes:
| obj2cfg - API for checking base Object2Cfg.
:methods:
| setUp - Call before test case.
| tearDown - Call after test case.
| test_not_none - Test is Object2Cfg not None.
| test_read_configuration - Test for read configuration.
| test_none_config_path - Test for None as file path.
'''
def setUp(self) -> None:
'''Call before test case.'''
self.obj2cfg: Object2Cfg = Object2Cfg(
f'{dirname(__file__)}/config/ats_cli_cfg_api.cfg'
)
def tearDown(self) -> None:
'''Call after test case.'''
def test_not_none(self) -> None:
'''Test for create Object2Cfg'''
self.assertIsNotNone(self.obj2cfg)
def test_write_configuration(self) -> None:
'''Test for read configuration'''
configuration: Dict[Any, Any] = {
'ats_name': 'ats_cli_test',
'ats_version': '1.0.0',
'ats_build_date': '24 Apr 2021',
'ats_licence':
'https://github.com/vroncevic/ats_cli_test/blob/dev/LICENSE'
}
self.assertTrue(self.obj2cfg.write_configuration(configuration))
def test_write_none_configuration(self) -> None:
'''Test for read configuration'''
with self.assertRaises(ATSTypeError):
self.obj2cfg.write_configuration(None) # type: ignore
def test_write_empty_configuration(self) -> None:
'''Test for read configuration'''
self.assertFalse(self.obj2cfg.write_configuration({}))
def test_none_config_path(self) -> None:
'''Test for None as file path'''
with self.assertRaises(ATSTypeError):
Object2Cfg(None)
if __name__ == '__main__':
main()