def test_from_file(self): self.assertEqual(len(self.eoi.bands), 11) for b in self.eoi.bands: self.assertIsInstance(b, Band) self.assertEqual(len(self.eoi.links), 3) href = ('https://odu9mlf7d6.execute-api.us-east-1.amazonaws.com/stage/' 'stac/search?id=LC08_L1TP_107018_20181001_20181001_01_RT') self.assertEqual(self.eoi.get_self_href(), href) with self.assertRaises(STACError): EOItem.from_file(self.URI_2)
def setUp(self): self.maxDiff = None self.URI_1 = TestCases.get_path('data-files/eo/eo-landsat-example.json') self.URI_2 = TestCases.get_path('data-files/eo/eo-landsat-example-INVALID.json') self.eoi = EOItem.from_file(self.URI_1) with open(self.URI_1) as f: self.eo_dict = json.load(f)
def test_from_item(self): i = Item.from_file(self.URI_1) with self.assertRaises(AttributeError): getattr(i, 'bands') self.assertTrue('eo:bands' in i.properties.keys()) eoi = EOItem.from_item(i) self.assertIsNotNone(getattr(eoi, 'bands')) with self.assertRaises(KeyError): eoi.properties['eo:bands']
def test_get_bands(self): eoi = EOItem.from_file(self.EO_ITEM_URI) eoa = EOAsset.from_dict(self.EO_ASSET_DICT) eoi.add_asset('test-asset', eoa) self.assertEqual(eoa.owner, eoi) bd = { "name": "B1", "common_name": "coastal", "gsd": 30, "center_wavelength": 0.44, "full_width_half_max": 0.02 } b1 = Band.from_dict(bd) eoa_bands = eoa.get_bands() compare_bands(self, b1, eoa_bands[0])
def test_validate_eo(self): sv = SchemaValidator() self.assertIsNone(sv.validate_dict(self.eo_dict, EOItem)) with open(self.URI_2) as f: eo_dict_2 = json.load(f) with self.assertRaises(ValidationError): print('[Validation error expected] - ', end='') sv.validate_dict(eo_dict_2, EOItem) with TemporaryDirectory() as tmp_dir: cat_dir = os.path.join(tmp_dir, 'catalog') catalog = TestCases.test_case_1() eo_item = EOItem.from_dict(self.eo_dict) catalog.add_item(eo_item) catalog.normalize_and_save(cat_dir, catalog_type=CatalogType.ABSOLUTE_PUBLISHED) cat_read = Catalog.from_file(os.path.join(cat_dir, 'catalog.json')) eo_item_read = cat_read.get_item("LC08_L1TP_107018_20181001_20181001_01_RT") sv = SchemaValidator() sv.validate_object(eo_item_read) sv.validate_dict(eo_item_read.to_dict(), EOItem)
def test_read_eo_item_owns_asset(self): item = EOItem.from_file(self.URI_1) assert len(item.assets) > 0 for asset_key in item.assets: self.assertEqual(item.assets[asset_key].owner, item)
def test_eo_key(self): self.assertEqual(EOItem._eo_key(''), 'eo:') self.assertEqual(EOItem._eo_key('dsg'), 'eo:dsg')