class Test(unittest.TestCase): @classmethod def setUpClass(self): self.rootpath = os.path.join(curpath(), 'data', 'src_test') self.dest_nan_value = -99 self.dest_regions = ['AU'] self.dest_sp_res = 1 self.dest_temp_res = 'daily' self.dest_start_date = datetime(2013, 1, 7) self.enddate = datetime(2013, 1, 13) self.testdate = datetime(2013, 1, 10) self.name = 'TEST' self.filename = "test_{YYYY}_{MM}_{TT}.png" self.filedate = {'YYYY': (5, 9), 'MM': (10, 12), 'DD': (13, 15)} self.temp_res = 'daily' self.protocol = 'local' self.begin_date = datetime(2013, 1, 7) if os.path.exists(self.rootpath): shutil.rmtree(self.rootpath) os.mkdir(self.rootpath) os.mkdir(os.path.join(self.rootpath, 'RAWDATA')) os.mkdir(os.path.join(self.rootpath, 'DATA')) os.mkdir(os.path.join(self.rootpath, 'TMP')) # setup test png files self.pngdir = os.path.join(curpath(), 'data', 'testpngs') self.host = self.pngdir if os.path.exists(self.pngdir): shutil.rmtree(self.pngdir) os.mkdir(self.pngdir) self.dtindex = get_dtindex('day', self.dest_start_date, self.enddate) for i, dat in enumerate(self.dtindex): if i == 3: continue year = str(dat.year) month = "%02d" % (dat.month) day = "%02d" % (dat.day) fname = ('test_' + year + '_' + month + '_' + day + '.png') shutil.copy(os.path.join(curpath(), 'data', 'test.png'), os.path.join(self.pngdir, fname)) self.source = BasicSource(self.name, self.filename, self.filedate, self.temp_res, self.rootpath, self.host, self.protocol, begin_date=self.begin_date, dest_nan_value=-self.dest_nan_value, dest_regions=self.dest_regions, dest_sp_res=self.dest_sp_res, dest_temp_res=self.dest_temp_res, dest_start_date=self.dest_start_date) @classmethod def tearDownClass(self): if os.path.exists(self.rootpath): shutil.rmtree(self.rootpath) if os.path.exists(self.pngdir): shutil.rmtree(self.pngdir) def test_download_and_resample(self): self.source.download_and_resample(end=self.enddate) for date in self.dtindex: img, _, _, _ = self.source.read_img(date) if date == self.testdate: assert img[2, 4] is np.ma.masked else: assert img[2, 4] == 177. def test_fill_gaps(self): shutil.copy(os.path.join(curpath(), 'data', 'test.png'), os.path.join(self.pngdir, 'test_2013_01_10.png')) self.source.fill_gaps(begin=self.dest_start_date, end=self.enddate) img, _, _, _ = self.source.read_img(self.testdate) assert img[1, 1] == 145.