def test_create_single_file_stac(self): cat = TestCases.test_case_1() sfs = create_single_file_stac(TestCases.test_case_1()) with TemporaryDirectory() as tmp_dir: path = os.path.join(tmp_dir, 'single_file_stac.json') pystac.write_file(sfs, include_self_link=False, dest_href=path) sfs_read = pystac.read_file(path) sfs_read.validate() self.assertTrue(sfs_read.ext.implements('single-file-stac')) read_fids = set( [f.id for f in sfs_read.ext['single-file-stac'].features]) expected_fids = set([f.id for f in cat.get_all_items()]) self.assertEqual(read_fids, expected_fids) read_col_ids = set([ col.id for col in sfs_read.ext['single-file-stac'].collections ]) expected_col_ids = set( ['area-1-1', 'area-1-2', 'area-2-1', 'area-2-2']) self.assertEqual(read_col_ids, expected_col_ids)
def test_read_item(self) -> None: item = pystac.read_file( TestCases.get_path("data-files/item/sample-item.json")) with tempfile.TemporaryDirectory() as tmp_dir: dest_href = os.path.join(tmp_dir, "item.json") pystac.write_file(item, dest_href=dest_href) self.assertTrue(os.path.exists(dest_href), msg="File was not written.")
def test_read_write_catalog(self) -> None: catalog = pystac.read_file( TestCases.get_path("data-files/catalogs/test-case-1/catalog.json")) with tempfile.TemporaryDirectory() as tmp_dir: dest_href = os.path.join(tmp_dir, "catalog.json") pystac.write_file(catalog, dest_href=dest_href) self.assertTrue(os.path.exists(dest_href), msg="File was not written.")
def test_read_write_collection(self) -> None: collection = pystac.read_file( TestCases.get_path("data-files/collections/multi-extent.json")) with tempfile.TemporaryDirectory() as tmp_dir: dest_href = os.path.join(tmp_dir, "collection.json") pystac.write_file(collection, dest_href=dest_href) self.assertTrue(os.path.exists(dest_href), msg="File was not written.")
def test_relative_self_href(self) -> None: with TemporaryDirectory() as temporary_directory: pystac.write_file( self.item, include_self_link=False, dest_href=os.path.join(temporary_directory, "item.json"), ) previous = os.getcwd() try: os.chdir(temporary_directory) item = pystac.read_file("item.json") href = item.get_self_href() assert href self.assertTrue(os.path.isabs(href), f"Not an absolute path: {href}") finally: os.chdir(previous)