def test_write_climate_point1_overwrite(self): """ Test case where there is a single data file the station, the entry is overwritten """ station = ClimatePointStation() station.type = "GHCN" station.id = "US1MDBL0027" station.longitude = -76.716 station.latitude = 39.317 station.elevation = 128.0 station.name = "My station name" station.data = "clim.txt" station.startDate = datetime.strptime("201007", "%Y%m") station.endDate = datetime.strptime("201110", "%Y%m") station.variables = [ClimatePointStation.VAR_PRECIP, \ ClimatePointStation.VAR_SNOW] station.writeToMetadata(self.context) climatePointStation = GenericMetadata.readClimatePointStations(self.context)[0] self.assertTrue(station.type.lower() == climatePointStation.type) self.assertTrue(station.id.lower() == climatePointStation.id) self.assertTrue(station.longitude == climatePointStation.longitude) self.assertTrue(station.latitude == climatePointStation.latitude) self.assertTrue(station.elevation == climatePointStation.elevation) self.assertTrue(station.name == climatePointStation.name) self.assertTrue(station.data == climatePointStation.data) self.assertTrue(station.startDate == climatePointStation.startDate) self.assertTrue(station.endDate == climatePointStation.endDate) self.assertTrue(station.variables == climatePointStation.variables) station.longitude = -76.716 station.latitude = 39.317 station.elevation = 128.0 station.name = "My (longer) station name" station.data = "clim.dat" station.startDate = datetime.strptime("201006", "%Y%m") station.endDate = datetime.strptime("201310", "%Y%m") station.variables = [ClimatePointStation.VAR_PRECIP, \ ClimatePointStation.VAR_SNOW] station.writeToMetadata(self.context) climatePointStation = GenericMetadata.readClimatePointStations(self.context)[0] self.assertTrue(station.type.lower() == climatePointStation.type) self.assertTrue(station.id.lower() == climatePointStation.id) self.assertTrue(station.longitude == climatePointStation.longitude) self.assertTrue(station.latitude == climatePointStation.latitude) self.assertTrue(station.elevation == climatePointStation.elevation) self.assertTrue(station.name == climatePointStation.name) self.assertTrue(station.data == climatePointStation.data) self.assertTrue(station.startDate == climatePointStation.startDate) self.assertTrue(station.endDate == climatePointStation.endDate) self.assertTrue(station.variables == climatePointStation.variables)
def test_write_climate_point2(self): """ Test case where there are separate data files for each variable and there are two climate stations """ station = ClimatePointStation() station.type = "GHCN" station.id = "US1MDBL0027" station.longitude = -76.716 station.latitude = 39.317 station.elevation = 128.0 station.name = "My station name" station.startDate = datetime.strptime("201007", "%Y%m") station.endDate = datetime.strptime("201110", "%Y%m") station.variables = [ClimatePointStation.VAR_PRECIP, \ ClimatePointStation.VAR_SNOW] station.variablesData[ClimatePointStation.VAR_PRECIP] = ClimatePointStation.VAR_PRECIP + '.txt' station.variablesData[ClimatePointStation.VAR_SNOW] = ClimatePointStation.VAR_SNOW + '.txt' station.writeToMetadata(self.context) station2 = ClimatePointStation() station2.type = "GHCN" station2.id = "US1MDBL4242" station2.longitude = -42.716 station2.latitude = 42.317 station2.elevation = 42.0 station2.name = "My 42 station" station2.startDate = datetime.strptime("199907", "%Y%m") station2.endDate = datetime.strptime("200110", "%Y%m") station2.variables = [ClimatePointStation.VAR_PRECIP, \ ClimatePointStation.VAR_SNOW] station2.variablesData[ClimatePointStation.VAR_PRECIP] = ClimatePointStation.VAR_PRECIP + '.txt' station2.variablesData[ClimatePointStation.VAR_SNOW] = ClimatePointStation.VAR_SNOW + '.txt' station2.writeToMetadata(self.context) climatePointStation = GenericMetadata.readClimatePointStations(self.context)[0] self.assertTrue(station.type.lower() == climatePointStation.type) self.assertTrue(station.id.lower() == climatePointStation.id) self.assertTrue(station.longitude == climatePointStation.longitude) self.assertTrue(station.latitude == climatePointStation.latitude) self.assertTrue(station.elevation == climatePointStation.elevation) self.assertTrue(station.name == climatePointStation.name) self.assertTrue(station.startDate == climatePointStation.startDate) self.assertTrue(station.endDate == climatePointStation.endDate) self.assertTrue(station.variables == climatePointStation.variables) self.assertTrue(station.variablesData[ClimatePointStation.VAR_PRECIP] == climatePointStation.variablesData[ClimatePointStation.VAR_PRECIP]) self.assertTrue(station.variablesData[ClimatePointStation.VAR_SNOW] == climatePointStation.variablesData[ClimatePointStation.VAR_SNOW])