def test_parse_date(self): ''' Code tested: parse_date(datestring) ''' date1_string = r"04_02_2017" date1 = pqh.parse_date(date1_string) date2_string = r"2017\02\04" date2 = pqh.parse_date(date2_string) self.assertTrue(date1 == date2) self.assertTrue(date1.year == 2017) self.assertTrue(date1.month == 2) self.assertTrue(date1.day == 4)
def test_get_value(self): ''' Code tested: Timeseries.get_value(year, month, day, date=None) ''' ts1 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") #Value before ts value = ts1.get_value(1910, 5, 1) self.assertTrue(math.isnan(value)) #Value at start of ts value = ts1.get_value(1910, 6, 1) self.assertTrue(value == 26.9) #Value inside ts value = ts1.get_value(1910, 6, 2) self.assertTrue(value == 204.2) #Value inside ts (using datetime) value = ts1.get_value(0, 0, 0, date=pqh.parse_date("02-06-1910")) self.assertTrue(value == 204.2) #Missing value inside ts value = ts1.get_value(2012, 6, 26) self.assertTrue(math.isnan(value)) #Value at end of ts value = ts1.get_value(2017, 12, 6) self.assertTrue(value == 36.0) #Value after ts value = ts1.get_value(2017, 12, 7) self.assertTrue(math.isnan(value))
def test_date_of_first_last_data(self): ''' Code tested: Timeseries.bias(other) ''' ts1 = pqh.load_csv( r".\pixiepython\tests\test_data\p040850_headder_missing_start_end.csv" ) first_data_date = ts1.date_of_first_data() self.assertTrue(first_data_date == pqh.parse_date("12/02/1913")) last_data_date = ts1.date_of_last_data() self.assertTrue(last_data_date == pqh.parse_date("15/01/1970")) #Do another one ts2 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") first_data_date = ts2.date_of_first_data() self.assertTrue(first_data_date == pqh.parse_date("01/06/1910")) last_data_date = ts2.date_of_last_data() self.assertTrue(last_data_date == pqh.parse_date("06/12/2017"))
def test_get_dates(self): ''' Code tested: Timeseries.get_dates() ''' ts1 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") dates = ts1.get_dates() self.assertTrue(len(dates) == 39271) self.assertTrue(len(dates) == len(ts1.data)) self.assertTrue(dates[0] == pqh.parse_date("01/06/1910"))