ya2 · news · projects · code · about

removed uml diagrams
[pmachines.git] / tests / lib / test_dictfile.py
1 from pathlib import Path
2 import sys
3 if '' in sys.path: sys.path.remove('')
4 sys.path.append(str(Path(__file__).parent.parent.parent))
5 from os import remove
6 from os.path import exists
7 from unittest import TestCase
8 from ya2.dictfile import DctFile
9
10
11 class DictFileTests(TestCase):
12
13 def setUp(self):
14 if exists('./tests/test.ini'): remove('./tests/test.ini')
15 self.dctfile = DctFile(
16 './tests/test.ini',
17 {'test': {'a': 0, 'b': 1, 'c': 2}})
18 self.dctfile.store()
19
20 def tearDown(self):
21 remove('./tests/test.ini')
22
23 def test_init(self):
24 self.assertIsNotNone(self.dctfile)
25
26 def test_deepupdate(self):
27 self.dctfile['a'] = {'b': {'c': 4}}
28 self.assertEqual(self.dctfile['a']['b']['c'], 4)
29 self.dctfile['a'] = \
30 DctFile.deepupdate(self.dctfile['a'], {'b': {'c': 5}})
31 self.assertEqual(self.dctfile['a']['b']['c'], 5)
32
33 def test_store(self):
34 self.assertEqual(self.dctfile['test']['c'], 2)
35 other = DctFile('./tests/test.ini')
36 self.dctfile['test']['c'] = 3
37 self.assertEqual(self.dctfile['test']['c'], 3)
38 self.assertEqual(other['test']['c'], 2)
39 self.dctfile.store()
40 other = DctFile('./tests/test.ini')
41 self.assertEqual(other['test']['c'], 3)
42
43 def test_operations(self):
44 self.assertEqual(self.dctfile['test']['c'], 2)
45 self.dctfile['d'] = 3
46 self.assertEqual(self.dctfile['d'], 3)
47 self.assertIn('d', self.dctfile.dct)
48 del self.dctfile['d']
49 self.assertNotIn('d', self.dctfile.dct)