import unittest import os import io import sys import icartt def compare_files(str_in, str_out, diff=0): str_out.seek(0) str_in.seek(0) input = str_in.readlines() output = str_out.readlines() str_in.close() str_out.close() if not len(input) == len(output): raise Exception("Input ({:d}) and output ({:d}) do not have the same number of lines!".format(len(input), len(output))) for i in range(len(input)): inline = input[i].strip().replace(" ", "") outline = output[i].strip().replace(" ", "") if not inline == outline: print("Line {:d} differs:".format(i)) print(" input: {:s}".format(inline)) print(" output: {:s}".format(outline)) return True class DatasetTestCase(unittest.TestCase): def test_simple_1001_NOx(self): fn = 'tests/examples/NOx_RHBrown_20040830_R0.ict' print(fn) str_in = open(fn) str_out = io.StringIO() ict = icartt.Dataset(fn, loadData=False) ict.read_data() ict.write(str_out) assert compare_files(str_in, str_out) def test_simple_1001_HOx(self): fn = 'tests/examples/HOX_DC8_20040712_R0.ict' print(fn) str_in = open(fn) str_out = io.StringIO() ict = icartt.Dataset(fn, loadData=False) ict.read_data() ict.write(str_out) assert compare_files(str_in, str_out) def test_simple_2110_AR(self): fn = 'tests/examples/AR_DC8_20050203_R0.ict' print(fn) str_in = open(fn) str_out = io.StringIO() ict = icartt.Dataset(fn, loadData=False) ict.read_data() ict.write(str_out) assert compare_files(str_in, str_out) def test_simple_2110_AROTAL(self): fn = 'tests/examples/AROTAL-RAY_DC8_20040715_R1.ict' print(fn) str_in = open(fn) str_out = io.StringIO() ict = icartt.Dataset(fn, loadData=False) ict.read_data() ict.write(str_out) assert compare_files(str_in, str_out) def suite(): suite = unittest.TestSuite() suite.addTest( DatasetTestCase('test_simple_1001_NOx') ) suite.addTest( DatasetTestCase('test_simple_1001_HOx') ) suite.addTest( DatasetTestCase('test_simple_2110_AR') ) suite.addTest( DatasetTestCase('test_simple_2110_AROTAL') ) return suite if __name__ == '__main__': runner = unittest.TextTestRunner() runner.run(suite())