Skip to content
Snippets Groups Projects
Commit 86a46e43 authored by Erik von Reis's avatar Erik von Reis
Browse files

Fixed build_edc_ini to add newline at end of ini file if not present. Also...

Fixed build_edc_ini to add newline at end of ini file if not present.  Also added some simple tests for build_edc_ini.
parent 8138e4e8
No related branches found
No related tags found
1 merge request!157Fixed build_edc_ini to add newline at end of ini file if not present.
Showing with 81 additions and 1 deletion
......@@ -42,4 +42,5 @@ with open(master_file, "rt") as mf:
for line in mf.readlines():
if nonspace_re.search(line):
with open(line.strip(), "rt") as ini_f:
of.write(ini_f.read())
for ini_line in ini_f.readlines():
of.write(ini_line.rstrip() + "\n")
import unittest
import os
import os.path as path
import filecmp
class NoNewlineTestCase(unittest.TestCase):
"""
A basic set of tests around a set of files where one does not have a newline at the end of the last line.
"""
def setUp(self):
self.working_dir = "nonewline"
self.out_file = f"output.ini"
self.out_path = path.join(self.working_dir, self.out_file)
def test_no_newline_first(self):
status = os.system(f"../build_edc_ini -m {self.working_dir}/nonewlinefirstmaster.txt -o {self.out_file}")
self.assertEqual(status, 0, f"no_newline_first exited with exit code {status}, should be 0")
self.assertTrue(path.exists(self.out_path), f"output file {self.out_file} was not created")
self.assertTrue(filecmp.cmp(self.out_path, f"{self.working_dir}/newline_first_target.ini"))
def test_no_newline_second(self):
status = os.system(f"../build_edc_ini -m {self.working_dir}/nonewlinesecondmaster.txt -o {self.out_file}")
self.assertEqual(status, 0, f"no_newline_second exited with exit code {status}, should be 0")
self.assertTrue(path.exists(self.out_path), f"output file {self.out_file} was not created")
self.assertTrue(filecmp.cmp(self.out_path, f"{self.working_dir}/newline_second_target.ini"))
def test_missing_file(self):
status = os.system(f"../build_edc_ini -m {self.working_dir}/missingfilemaster.txt -o {self.out_file}")
self.assertEqual(status, 256, f"build_edc_ini should throw an error on missing file")
def test_empty_file(self):
status = os.system(f"../build_edc_ini -m {self.working_dir}/emptymaster.txt -o {self.out_file}")
self.assertEqual(status, 0, f"exited with exit code {status}, should be 0")
self.assertTrue(path.exists(self.out_path), f"output file {self.out_file} was not created")
def tearDown(self):
os.remove(self.out_path)
if __name__ == "__main__":
unittest.main()
\ No newline at end of file
newline.ini
nonewline.ini
notafile.ini
\ No newline at end of file
[DUMMY_CHANNEL_3]
[DUMMY_CHANNEL_4]
[default]
gain=1.00
datatype=4
ifoid=0
slope=6.1028e-05
acquire=1
offset=0
units=V
dcuid=52
datarate=16
[DUMMY_CHANNEL]
[DUMMY_CHANNEL_2]
[DUMMY_CHANNEL_3]
[DUMMY_CHANNEL_4]
[default]
gain=1.00
datatype=4
ifoid=0
slope=6.1028e-05
acquire=1
offset=0
units=V
dcuid=52
datarate=16
[DUMMY_CHANNEL_3]
[DUMMY_CHANNEL_4]
[DUMMY_CHANNEL]
[DUMMY_CHANNEL_2]
[DUMMY_CHANNEL]
[DUMMY_CHANNEL_2]
\ No newline at end of file
nonewline.ini
newline.ini
\ No newline at end of file
newline.ini
nonewline.ini
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment