1 from pathlib
import Path
3 if '' in sys
.path
: sys
.path
.remove('')
4 sys
.path
.append(str(Path(__file__
).parent
.parent
.parent
))
6 from os
.path
import exists
7 from unittest
import TestCase
8 from ya2
.utils
.dictfile
import DctFile
11 class DictFileTests(TestCase
):
14 if exists('./tests/test.ini'): remove('./tests/test.ini')
15 self
.dctfile
= DctFile(
17 {'test': {'a': 0, 'b': 1, 'c': 2}})
21 remove('./tests/test.ini')
24 self
.assertIsNotNone(self
.dctfile
)
26 def test_deepupdate(self
):
27 self
.dctfile
['a'] = {'b': {'c': 4}}
28 self
.assertEqual(self
.dctfile
['a']['b']['c'], 4)
30 DctFile
.deepupdate(self
.dctfile
['a'], {'b': {'c': 5}})
31 self
.assertEqual(self
.dctfile
['a']['b']['c'], 5)
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)
40 other
= DctFile('./tests/test.ini')
41 self
.assertEqual(other
['test']['c'], 3)
43 def test_operations(self
):
44 self
.assertEqual(self
.dctfile
['test']['c'], 2)
46 self
.assertEqual(self
.dctfile
['d'], 3)
47 self
.assertIn('d', self
.dctfile
.dct
)
49 self
.assertNotIn('d', self
.dctfile
.dct
)