def test_scene_interpreter(self): # Test with correct input self.assertDictEqual(self.interpreted_product_id, Landsat8.scene_interpreter(self.product_id)) # Test with incorrect input self.assertRaises(Exception, Landsat8.scene_interpreter, 'LC80030172015001LGN')
def test_download_google_when_amazon_is_unavailable(self, fake_google): """ Test whether google or amazon are correctly selected based on input """ fake_google.return_value = Scenes() # Test if google is used when an image from 2014 is passed even if bands are provided scenes = [self.all_scenes[-1]] l = Landsat8(download_dir=self.temp_folder) l.download(scenes, bands=[432]) fake_google.assert_called_with(scenes)
def test_download_with_band_name(self, fake_fetch): """ Test downloading from S3 for a given sceneID with band names """ fake_fetch.return_value = 'file.tif' l = Landsat8(download_dir=self.temp_folder) results = l.download(self.s3_products, ['red', 'green', 'blue']) self.assertTrue(isinstance(results, Scenes)) self.assertEqual(self.s3_products, results.scenes) self.assertEqual(len(results[self.s3_products[0]].files), 6)
def test_s3(self, fake_fetch): """ Test downloading from S3 for a given sceneID """ fake_fetch.return_value = 'file.tif' l = Landsat8(download_dir=self.temp_folder) results = l.s3(self.s3_products, [4, 3, 2]) self.assertTrue(isinstance(results, Scenes)) self.assertEqual(self.s3_products, results.scenes) self.assertEqual(len(results[self.s3_products[0]].files), 3)
def test_google(self, fake_fetch): """ Test downloading from google for a given sceneID """ fake_fetch.return_value = True l = Landsat8(download_dir=self.temp_folder) results = l.google(self.all_scenes) self.assertTrue(isinstance(results, Scenes)) self.assertEqual(len(results), len(self.all_scenes)) for i, scene in enumerate(self.all_scenes): self.assertEqual(results[scene].zip_file, os.path.join(self.temp_folder, scene + '.tar.bz'))
def test_usgs(self, fake_fetch, fake_api, fake_login): """ Test downloading from google for a given sceneID """ fake_login.return_value = True fake_fetch.return_value = 'file.tar.bz' fake_api.return_value = ['example.com/%s.tar.bz' % scene for scene in self.all_scenes] l = Landsat8(download_dir=self.temp_folder, usgs_user='******', usgs_pass='******') results = l.usgs(self.all_scenes) self.assertTrue(isinstance(results, Scenes)) self.assertEqual(len(results), len(self.all_scenes)) self.assertEqual(results[0].zip_file, os.path.join(self.temp_folder, self.all_scenes[0] + '.tar.bz'))
def test_download_google_when_amazon_is_unavailable( self, fake_google, fake_s3): """ Test whether google or amazon are correctly selected based on input """ fake_google.return_value = Scene(self.all_scenes[-1]) fake_s3.side_effect = RemoteFileDoesntExist() # Test if google is used when an image from 2014 is passed even if bands are provided scenes = [self.all_scenes[-1]] bands = {2, 3, 4, 5} l = Landsat8(download_dir=self.temp_folder) l.download(scenes, bands=bands) fake_google.assert_called_with(scenes[0], bands.union({'QA', 'ANG', 'MTL'}))
def test_google(self, fake_download): fake_download.side_effect = self._landsat_download l = Landsat8(download_dir=self.temp_folder) bands = [2, 3, 4, 'QA', 'MTL', 'ANG'] results = l.download( self.all_scenes, service_chain=[GOOGLE_PUBLIC_DATA_STORAGE_SERVICE], bands=bands) self.assertTrue(isinstance(results, Scenes)) self.assertEqual(len(results), len(self.all_scenes)) self.assertEqual(fake_download.call_count, len(self.all_scenes) * len(bands)) self.assertListEqual([r.name for r in results], self.all_scenes) for i, scene in enumerate(self.all_scenes): self.assertEqual( len(results[scene].files), len(self.band_ids) if bands is None else len(bands)) for band_filepath in results[scene].files: self.assertTrue(band_filepath.startswith(self.temp_folder))
def test_google_storage_url(self): string = Landsat8.google_storage_url(self.interpreted_product_id, 11) expect = 'LC08/01/174/037/LC08_L1TP_174037_20170426_20170502_01_T1/' + \ 'LC08_L1TP_174037_20170426_20170502_01_T1_B11.TIF' self.assertIn(expect, string)
def test_amazon_s3_url(self): string = Landsat8.amazon_s3_url(self.interpreted_product_id, 11) expect = 'L8/174/037/LC08_L1TP_174037_20170426_20170502_01_T1/LC08_L1TP_174037_20170426_20170502_01_T1_B11.TIF' self.assertIn(expect, string)
def test_download_with_unknown_band(self): l = Landsat8(download_dir=self.temp_folder) with self.assertRaises(IncorrectLandsat8SceneId): l.download(self.all_scenes, bands=[432]) with self.assertRaises(IncorrectLandsat8SceneId): l.download(self.all_scenes, bands=['CirrUs'])