3 # The software in this package is distributed under the GNU General
4 # Public License version 2 (with a special exception described below).
6 # A copy of GNU General Public License (GPL) is included in this distribution,
7 # in the file COPYING.GPL.
9 # As a special exception, if other files instantiate templates or use macros
10 # or inline functions from this file, or you compile this file and link it
11 # with other works to produce a work based on this file, this file
12 # does not by itself cause the resulting work to be covered
13 # by the GNU General Public License.
15 # However the source code for this file must still be made available
16 # in accordance with section (3) of the GNU General Public License.
18 # This exception does not invalidate any other reasons why a work based
19 # on this file might be covered by the GNU General Public License.
21 # Copyright (c) 2016-2018 Intra2net AG <info@intra2net.com>
24 from src.cnfline.cnfline import CnfLine
25 from src.cnfline.build_nic import BuildNIC
28 class CnfLineTest(unittest.TestCase):
29 def test_simple(self):
30 line = CnfLine('MY_NAME', 123, 'my_data', 888, 456)
32 self.assertEqual('MY_NAME', line.name)
33 self.assertEqual(123, line.instance)
34 self.assertEqual('my_data', line.data)
35 self.assertEqual(888, line.line_no)
36 self.assertEqual(456, line.parent_line_no)
38 def test_deny_empty_name(self):
39 with self.assertRaises(ValueError):
42 def test_deny_lineno_zero(self):
43 with self.assertRaises(ValueError):
44 CnfLine('foobar', 0, 'some_data', 0)
46 def test_str_output_parent(self):
47 line = CnfLine('MY_NAME', 123, 'my_data', 10, 0)
48 self.assertEqual('10 MY_NAME,123: "my_data"', str(line))
50 def test_str_output_child(self):
51 line = CnfLine('MY_NAME', 123, 'my_data', 10, 456)
52 self.assertEqual('10 (456) MY_NAME,123: "my_data"', str(line))
55 class BuildNICTest(unittest.TestCase):
56 def test_nic_comment(self):
57 nic = BuildNIC('my comment', 10, 100)
60 self.assertTrue('NIC_COMMENT,0: "my comment"' in cnf_text)
61 self.assertEqual('', nic.data)
63 def test_change_comment(self):
64 nic = BuildNIC('initial comment', 10, 100)
65 nic.comment('new comment')
68 self.assertTrue('NIC_COMMENT,0: "new comment"' in cnf_text)
69 self.assertTrue('initial comment"' not in cnf_text)
70 self.assertEqual('', nic.data)
73 if __name__ == '__main__':