예제 #1
0
    def test_to_from_dict(self) -> None:
        GridExtension.ext(self.item).apply(code)
        d = self.item.to_dict()
        self.assertEqual(code, d["properties"][grid.CODE_PROP])

        item = pystac.Item.from_dict(d)
        self.assertEqual(code, GridExtension.ext(item).code)
예제 #2
0
    def test_item_ext_add_to(self) -> None:
        item = pystac.Item.from_file(self.sentinel_example_uri)
        item.stac_extensions.remove(GridExtension.get_schema_uri())
        self.assertNotIn(GridExtension.get_schema_uri(), item.stac_extensions)

        _ = GridExtension.ext(item, add_if_missing=True)

        self.assertIn(GridExtension.get_schema_uri(), item.stac_extensions)
예제 #3
0
def make_item() -> pystac.Item:
    """Create basic test items that are only slightly different."""
    asset_id = "an/asset"
    start = datetime.datetime(2018, 1, 2)
    item = pystac.Item(id=asset_id,
                       geometry=None,
                       bbox=None,
                       datetime=start,
                       properties={})

    GridExtension.add_to(item)
    return item
예제 #4
0
    def test_extension_not_implemented(self) -> None:
        # Should raise exception if Item does not include extension URI
        item = pystac.Item.from_file(self.sentinel_example_uri)
        item.stac_extensions.remove(GridExtension.get_schema_uri())

        with self.assertRaises(pystac.ExtensionNotImplemented):
            _ = GridExtension.ext(item)

        # Should raise exception if owning Item does not include extension URI
        item.properties["grid:code"] = None

        with self.assertRaises(pystac.ExtensionNotImplemented):
            _ = GridExtension.ext(item)
예제 #5
0
 def test_from_dict(self) -> None:
     d: Dict[str, Any] = {
         "type": "Feature",
         "stac_version": "1.0.0",
         "id": "an/asset",
         "properties": {
             "grid:code": code,
             "datetime": "2018-01-02T00:00:00Z",
         },
         "geometry": None,
         "links": [],
         "assets": {},
         "stac_extensions": [GridExtension.get_schema_uri()],
     }
     item = pystac.Item.from_dict(d)
     self.assertEqual(code, GridExtension.ext(item).code)
예제 #6
0
    def test_clear_code(self) -> None:
        GridExtension.ext(self.item).apply(code)

        with self.assertRaises(ValueError):
            GridExtension.ext(self.item).code = None
예제 #7
0
 def test_modify(self) -> None:
     GridExtension.ext(self.item).apply(code)
     GridExtension.ext(self.item).apply(code + "a")
     self.assertEqual(code + "a", GridExtension.ext(self.item).code)
     self.item.validate()
예제 #8
0
 def test_invalid_code_value(self) -> None:
     with self.assertRaises(ValueError):
         GridExtension.ext(self.item).apply("not_a_valid_code")
예제 #9
0
 def test_attributes(self) -> None:
     GridExtension.ext(self.item).apply(code)
     self.assertEqual(code, GridExtension.ext(self.item).code)
     self.item.validate()
예제 #10
0
 def test_item_repr(self) -> None:
     grid_item_ext = GridExtension.ext(self.item)
     self.assertEqual(f"<ItemGridExtension Item id={self.item.id}>",
                      grid_item_ext.__repr__())
예제 #11
0
 def test_stac_extensions(self) -> None:
     self.assertTrue(GridExtension.has_extension(self.item))