coala-analyzer /
coala
| 1 | import os |
||
| 2 | |||
| 3 | import sys |
||
| 4 | |||
| 5 | sys.path.insert(0, ".") |
||
| 6 | from coalib.output.ConfWriter import ConfWriter |
||
| 7 | from coalib.parsing.ConfParser import ConfParser |
||
| 8 | import unittest |
||
| 9 | import tempfile |
||
| 10 | |||
| 11 | |||
| 12 | class ConfWriterTest(unittest.TestCase): |
||
| 13 | example_file = ("to be ignored \n" |
||
| 14 | " save=true\n" |
||
| 15 | " a_default, another = val \n" |
||
| 16 | " TEST = tobeignored # do you know that thats a comment \n" |
||
|
0 ignored issues
–
show
|
|||
| 17 | " test = push \n" |
||
| 18 | " t = \n" |
||
| 19 | " [MakeFiles] \n" |
||
| 20 | " j , ANother = a \n" |
||
| 21 | " multiline \n" |
||
| 22 | " value \n" |
||
| 23 | " ; just a omment \n" |
||
| 24 | " ; just a omment \n") |
||
| 25 | |||
| 26 | def setUp(self): |
||
| 27 | self.file = os.path.join(tempfile.gettempdir(), "ConfParserTestFile") |
||
| 28 | with open(self.file, "w", encoding='utf-8') as filehandler: |
||
| 29 | filehandler.write(self.example_file) |
||
| 30 | |||
| 31 | self.conf_parser = ConfParser() |
||
| 32 | self.write_file_name = os.path.join(tempfile.gettempdir(), |
||
| 33 | "ConfWriterTestFile") |
||
| 34 | self.uut = ConfWriter(self.write_file_name) |
||
| 35 | |||
| 36 | def tearDown(self): |
||
| 37 | self.uut.close() |
||
| 38 | os.remove(self.file) |
||
| 39 | os.remove(self.write_file_name) |
||
| 40 | |||
| 41 | def test_exceptions(self): |
||
| 42 | self.assertRaises(TypeError, self.uut.write_section, 5) |
||
| 43 | |||
| 44 | def test_write(self): |
||
| 45 | result_file = ["[Default]\n", |
||
| 46 | "save = true\n", |
||
| 47 | "a_default, another = val\n", |
||
| 48 | "# do you know that thats a comment\n", |
||
| 49 | "test = push\n", |
||
| 50 | "t = \n", |
||
| 51 | "\n", |
||
| 52 | "[MakeFiles]\n", |
||
| 53 | "j, ANother = a\n", |
||
| 54 | "multiline\n", |
||
| 55 | "value\n", |
||
| 56 | "; just a omment\n", |
||
| 57 | "; just a omment\n"] |
||
| 58 | self.uut.write_sections(self.conf_parser.parse(self.file)) |
||
| 59 | self.uut.close() |
||
| 60 | |||
| 61 | with open(self.write_file_name, "r") as f: |
||
| 62 | lines = f.readlines() |
||
| 63 | |||
| 64 | self.assertEqual(result_file, lines) |
||
| 65 | |||
| 66 | |||
| 67 | if __name__ == '__main__': |
||
| 68 | unittest.main(verbosity=2) |
||
| 69 |
This check looks for lines that are too long. You can specify the maximum line length.