Skip to content
Snippets Groups Projects
Commit 5c8799d9 authored by Florian Obersteiner's avatar Florian Obersteiner
Browse files

prepared fail test

parent 304a3017
Branches
Tags
1 merge request!6code refactor
This commit is part of merge request !6. Comments created here will be created in the context of that merge request.
......@@ -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,46 @@ class Create1001TestCase(unittest.TestCase):
class BulkIOTestCase(unittest.TestCase):
# 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))
if __name__ == "__main__": # pragma: no cover
unittest.main()
\ No newline at end of file
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment