forked from stac-utils/pystac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
107 lines (70 loc) · 2.6 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# TODO move all test case code to this file
import json
import shutil
import uuid
from datetime import datetime
from pathlib import Path
from typing import Any
import pytest
from pystac import Asset, Catalog, Collection, Item, ItemCollection, Link
from .utils import ARBITRARY_BBOX, ARBITRARY_EXTENT, ARBITRARY_GEOM, TestCases
here = Path(__file__).resolve().parent
@pytest.fixture
def catalog() -> Catalog:
return Catalog("test-catalog", "A test catalog")
@pytest.fixture
def collection() -> Catalog:
return Collection("test-collection", "A test collection", ARBITRARY_EXTENT)
@pytest.fixture
def item() -> Item:
return Item("test-item", ARBITRARY_GEOM, ARBITRARY_BBOX, datetime.now(), {})
@pytest.fixture
def asset(item: Item) -> Asset:
item.add_asset("foo", Asset("https://example.tif"))
return item.assets["foo"]
@pytest.fixture
def link(item: Item) -> Link:
item.add_link(Link(rel="child", target="https://example.tif"))
return item.links[0]
@pytest.fixture
def test_case_1_catalog() -> Catalog:
return TestCases.case_1()
@pytest.fixture
def test_case_8_collection() -> Collection:
return TestCases.case_8()
@pytest.fixture
def projection_landsat8_item() -> Item:
path = TestCases.get_path("data-files/projection/example-landsat8.json")
return Item.from_file(path)
def get_data_file(rel_path: str) -> str:
return str(here / "data-files" / rel_path)
@pytest.fixture
def sample_item_dict() -> dict[str, Any]:
m = TestCases.get_path("data-files/item/sample-item.json")
with open(m) as f:
item_dict: dict[str, Any] = json.load(f)
return item_dict
@pytest.fixture
def sample_item() -> Item:
return Item.from_file(TestCases.get_path("data-files/item/sample-item.json"))
@pytest.fixture
def sample_item_collection() -> ItemCollection:
return ItemCollection.from_file(
TestCases.get_path("data-files/item-collection/sample-item-collection.json")
)
@pytest.fixture
def sample_items(sample_item_collection: ItemCollection) -> list[Item]:
return list(sample_item_collection)
@pytest.fixture(scope="function")
def tmp_asset(tmp_path: Path) -> Asset:
"""Copy the entirety of test-case-2 to tmp and"""
src = get_data_file("catalogs/test-case-2")
dst = str(tmp_path / str(uuid.uuid4()))
shutil.copytree(src, dst)
catalog = Catalog.from_file(f"{dst}/catalog.json")
item = next(catalog.get_items(recursive=True))
return next(v for v in item.assets.values())
@pytest.fixture(autouse=True)
def clear_validator() -> None:
from pystac.validation import RegisteredValidator
RegisteredValidator._validator = None