Failed Conditions
Pull Request — master (#2076)
by Abdeali
02:04
created

ConfWriterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %
Metric Value
dl 0
loc 65
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
B test_write() 0 27 2
A tearDown() 0 4 1
A setUp() 0 9 2
A test_exceptions() 0 2 1
1
import os
2
import tempfile
3
import unittest
4
5
from coalib.output.ConfWriter import ConfWriter
6
from coalib.parsing.ConfParser import ConfParser
7
8
9
class ConfWriterTest(unittest.TestCase):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable unittest does not seem to be defined.
Loading history...
10
    example_file = ("to be ignored \n"
11
                    "    save=true\n"
12
                    "    a_default, another = val \n"
13
                    "    TEST = tobeignored  # thats a comment \n"
14
                    "    test = push \n"
15
                    "    t = \n"
16
                    "    [MakeFiles] \n"
17
                    "     j  , ANother = a \n"
18
                    "                   multiline \n"
19
                    "                   value \n"
20
                    "    ; just a omment \n"
21
                    "    ; just a omment \n"
22
                    "    key\\ space = value space\n"
23
                    "    key\\=equal = value=equal\n"
24
                    "    key\\\\backslash = value\\\\backslash\n"
25
                    "    key\\,comma = value,comma\n"
26
                    "    key\\#hash = value\\#hash\n"
27
                    "    key\\.dot = value.dot\n")
28
29
    def setUp(self):
30
        self.file = os.path.join(tempfile.gettempdir(), "ConfParserTestFile")
31
        with open(self.file, "w", encoding='utf-8') as file:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable file does not seem to be defined.
Loading history...
32
            file.write(self.example_file)
33
34
        self.conf_parser = ConfParser()
35
        self.write_file_name = os.path.join(tempfile.gettempdir(),
36
                                            "ConfWriterTestFile")
37
        self.uut = ConfWriter(self.write_file_name)
38
39
    def tearDown(self):
40
        self.uut.close()
41
        os.remove(self.file)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
42
        os.remove(self.write_file_name)
43
44
    def test_exceptions(self):
45
        self.assertRaises(TypeError, self.uut.write_section, 5)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable TypeError does not seem to be defined.
Loading history...
46
47
    def test_write(self):
48
        result_file = ["[Default]\n",
49
                       "save = true\n",
50
                       "a_default, another = val\n",
51
                       "# thats a comment\n",
52
                       "test = push\n",
53
                       "t = \n",
54
                       "\n",
55
                       "[MakeFiles]\n",
56
                       "j, ANother = a\n",
57
                       "multiline\n",
58
                       "value\n",
59
                       "; just a omment\n",
60
                       "; just a omment\n",
61
                       "key\\ space = value space\n",
62
                       "key\\=equal = value=equal\n",
63
                       "key\\\\backslash = value\\\\backslash\n",
64
                       "key\\,comma = value,comma\n",
65
                       "key\\#hash = value\\#hash\n",
66
                       "key\\.dot = value.dot\n"]
67
        self.uut.write_sections(self.conf_parser.parse(self.file))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
68
        self.uut.close()
69
70
        with open(self.write_file_name, "r") as f:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable f does not seem to be defined.
Loading history...
71
            lines = f.readlines()
72
73
        self.assertEqual(result_file, lines)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable result_file does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable lines does not seem to be defined.
Loading history...
74