Skip to content
Snippets Groups Projects

code refactor

Merged Florian Obersteiner requested to merge (removed):master into master
1 file
+ 17
12
Compare changes
  • Side-by-side
  • Inline
+ 19
12
@@ -7,7 +7,8 @@ import icartt
# working directory, example files
wd = pathlib.Path(__file__).parent
fns = (wd / "example_data").glob("*.ict")
fns_pass = (wd / "example_data").glob("*.ict")
fns_fail = (wd / "example_data" / "will_fail").glob("*.ict")
def compareFiles(fn, strIn, strOut, skiplines=0, nlines=-1): # pragma: no cover
@@ -310,42 +311,48 @@ class Create1001TestCase(unittest.TestCase):
class BulkIOTestCase(unittest.TestCase):
# TODO: need to test invalid input
# def testInvalid(self):
# for fn in fns_fail:
# with self.subTest(msg=f"Opening invalid file {str(fn)}"):
# try:
# _ = icartt.Dataset(fn, loadData=True)
# except: # TODO: failure tests could be more specific
# pass
# else:
# self.fail('expected to fail')
def testOpen(self):
for fn in fns:
for fn in fns_pass:
with self.subTest(msg=f"Opening test file {str(fn)}"):
ict = icartt.Dataset(fn, loadData=False)
self.assertEqual(type(ict), icartt.Dataset)
def testReadData(self):
for fn in fns:
for fn in fns_pass:
with self.subTest(msg=f"Reading data from test file {str(fn)}"):
ict = icartt.Dataset(fn, loadData=True)
self.assertEqual(type(ict), icartt.Dataset)
def testWriteHeader(self):
for fn in fns:
for fn in fns_pass:
with self.subTest(msg=f"Writing header for test file {str(fn)}"):
ict = icartt.Dataset(fn, loadData=False)
strIn = open(fn)
strOut = io.StringIO()
ict.writeHeader(f=strOut)
self.assertTrue(compareFiles(fn, strIn, strOut, nlines=ict.nHeader))
def testWrite(self):
for fn in fns:
for fn in fns_pass:
with self.subTest(msg=f"Writing data for test file {str(fn)}"):
ict = icartt.Dataset(fn, loadData=True)
strIn = open(fn)
strOut = io.StringIO()
ict.write(f=strOut)
self.assertTrue(compareFiles(fn, strIn, strOut))
# TODO: should also test dataset methods, e.g. .times
if __name__ == "__main__": # pragma: no cover
unittest.main()
\ No newline at end of file
unittest.main()
Loading