def testLoadHeaders(self): h1 = Header("Sr (ng/L)", HeaderType.SAMPLE, "Sr", "ng/L", "Sr_(ng/L)") h_last = Header("K (ug/L)", HeaderType.SAMPLE, "K", "ug/L", "K_(ug/L)") with open(os.path.join('csv_files', 'header_input.csv'), 'r') as f: headers = load_headers(f) self.assertEqual(h1, headers[0], "First header is Strontium") self.assertEqual(h_last, headers[len(headers) - 1], "Last header is Potasium")
def setUp(self): self.a = Header("a",HeaderType.YEARS, "aclass", "aunit", "alabel") self.b = Header("b",HeaderType.YEARS, "aclass", "aunit", "alabel") self.c = Header("c",HeaderType.DEPTH, "cclass", "cunit", "clabel") self.d = Header("d",HeaderType.SAMPLE, "dclass", "dunit", "dlabel") self.e = Header("e",HeaderType.SAMPLE, "eclass", "eunit", "elabel") self.abc_dict = {"a": self.a, "b": self.b, "c": self.c, "d": self.d, "e": self.e} pass
def testHeaderEqual(self): h1 = Header('test', HeaderType.YEARS, 'Years', 'BP', 'Year (BP)') h2 = Header('test', HeaderType.YEARS, 'Years', 'BP', 'Year (BP)') h3 = Header('test3', HeaderType.YEARS, 'Years', 'BP', 'Year (BP)') self.assertTrue(h1 == h1) self.assertTrue(h1 == h2) self.assertTrue(h2 == h1) self.assertFalse(h1 == h3) self.assertFalse(h3 == h1) self.assertFalse(h3 == h2) self.assertFalse(h1 == object())
def testParseHeaders(self): noHeaders: Map[str, HeaderType] = [] test_years = Header("test years (BP)", HeaderType.YEARS, "Years", "BP", "test_years_(BP)") test_depth = Header("test depth (m)", HeaderType.DEPTH, "Depth", "m", "test_depth_(m)") test_sample_nounit = Header("test_sample", HeaderType.SAMPLE, "Sample", None, "test_sample") test_sample = Header("test_sample (ppb)", HeaderType.SAMPLE, "Sample", "ppb", "test_sample_(ppb)") testDict: Map[str, Header] = { "test years (BP)": test_years, "test depth (m)": test_depth, "test_sample": test_sample_nounit, "test_sample (ppb)": test_sample } testHeaderDict = HeaderDictionary(testDict) self.assertEqual([], testHeaderDict.parse_headers(noHeaders)) oneHeaderNoUnit = ['test_sample'] self.assertListEqual([test_sample_nounit], testHeaderDict.parse_headers(oneHeaderNoUnit)) oneHeaderWithUnit = ['test_sample (ppb)'] self.assertListEqual([test_sample], testHeaderDict.parse_headers(oneHeaderWithUnit)) oneHeaderWithUnitAndNotExisting = [ 'test_sample (ppb)', 'test2 Not in (ppb)' ] self.assertListEqual([ test_sample, Header('test2 Not in (ppb)', HeaderType.UNKNOWN, None, None, None) ], testHeaderDict.parse_headers(oneHeaderWithUnitAndNotExisting)) oneHeaderWithUnitAndOneWithoutUnit = [ 'test_sample (ppb)', 'test_sample' ] self.assertListEqual( [test_sample, test_sample_nounit], testHeaderDict.parse_headers(oneHeaderWithUnitAndOneWithoutUnit))
def setUp(self): self.a = Header("a", HeaderType.YEARS, "aclass", "aunit", "alabel") self.c = Header("c", HeaderType.SAMPLE, "cclass", "cunit", "clabel") self.d = Header("d", HeaderType.SAMPLE, "dclass", "dunit", "dlabel") self.e = Header("e", HeaderType.YEARS, "eclass", "eunit", "elabel") self.unknown_header = Header("not known", HeaderType.UNKNOWN, None, None, None) self.abcDict = { "a": self.a, "b": self.a, "c": self.c, "d": self.d, "e": self.e } self.hd = HeaderDictionary( ) # Should be the default header dictionaries
def testParseHeader(self): self.assertEqual(('Dat210617', None), Header.parse_header('Dat210617')) self.assertEqual(('Dat011216V2', None), Header.parse_header('Dat011216V2')) self.assertEqual(('depth', 'm abs'), Header.parse_header('depth (m abs)')) self.assertEqual(('Cond', '+ALU-S/cm'), Header.parse_header('Cond (+ALU-S/cm)')) self.assertEqual(('Na', 'ppb'), Header.parse_header('Na (ppb)')) self.assertEqual(('Ca', 'ppb'), Header.parse_header('Ca (ppb)')) self.assertEqual(('Dust', 'part/ml'), Header.parse_header('Dust (part/ml)')) self.assertEqual(('NH4', 'ppb'), Header.parse_header('NH4 (ppb)')) # Test with some additional strange spacing self.assertEqual(('NO3', 'ppb'), Header.parse_header('NO3 (ppb)')) self.assertEqual(('NO3', 'ppb'), Header.parse_header(' NO3 ( ppb ) '))
def testAddHeader(self): self.assertRaises(ValueError, self.hd.add_header, self.unknown_header) hdict = HeaderDictionary(self.abcDict) self.assertEqual(self.a, hdict.add_header(self.a), "Previous header should be returned") h = Header("test", HeaderType.YEARS, "Years", "CE", "test_(BP)") self.assertEqual(None, hdict.add_header(h), "New header should return None") self.assertEqual(h, hdict.add_header(h), "Previous header should be returned")
import unittest from pandas import DataFrame from pandas.util.testing import assert_frame_equal from climatechange.headers import Header, HeaderType from climatechange.laser import load_txt_file, read_input, load_input, raw_data,\ add_year_column, add_depth_column, process_laser_data, resample_laser_by,\ resample_data, run_data from climatechange.common_functions import clean_data, load_csv, to_csv depth_age_file = os.path.join('csv_files', 'depthAge7617.txt') f = read_input(os.path.join('csv_files', '1.txt'), 955, 6008.500, 6012.500, 12, 23) test_sample_header = Header("Cond (+ALU-S/cm)", HeaderType.SAMPLE, "Conductivity", "alu-s/cm", "Cond_(+ALU-S/cm)") test_depth_we_header = Header("depth (m we)", HeaderType.DEPTH, "Depth", "meters", "depth_we_(m)") test_depth_abs_header = Header("depth (m abs) ", HeaderType.DEPTH, "Depth", "meters", "depth_abs_(m)") test_process_laser = os.path.join('csv_files', 'output', 'process_laser_data_test.csv') class Test(unittest.TestCase): def setUp(self): pass def tearDown(self): pass