Skip to content

Commit a53aaa0

Browse files
committed
Use environment variable for tmp dir location
1 parent 46fbaa7 commit a53aaa0

File tree

11 files changed

+48
-54
lines changed

11 files changed

+48
-54
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,17 @@ jobs:
5454
path: ~\AppData\Local\pip\Cache
5555
# Cache based on OS, Python version, and dependency hash
5656
key: pip-${{ runner.os }}-python${{ matrix.python-version }}-${{ hashFiles('requirements-test.txt') }}
57-
57+
5858
- name: Install dependencies
5959
run: |
6060
pip install -r requirements-test.txt
6161
pip install -e ".[validation]"
62-
62+
6363
- name: Execute test suite
6464
run: ./scripts/test
6565
shell: bash
66+
env:
67+
TMPDIR: "${{ matrix.os == 'windows-latest' && 'D:\\a\\_temp' || '' }}"
6668

6769
- name: Upload All coverage to Codecov
6870
uses: codecov/codecov-action@v1

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
tmp*
21
*.pyc
32
*.egg-info
43
*.eggs

tests/data-files/get_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import argparse
77
import json
88
from subprocess import call
9+
from tempfile import TemporaryDirectory
910
from typing import Any, Dict, List, Optional
1011
from urllib.error import HTTPError
1112

1213
import pystac
1314
from pystac.serialization import identify_stac_object
14-
from tests.utils import get_temp_dir
1515

1616

1717
def remove_bad_collection(js: Dict[str, Any]) -> Dict[str, Any]:
@@ -50,7 +50,7 @@ def remove_bad_collection(js: Dict[str, Any]) -> Dict[str, Any]:
5050

5151
examples_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "examples"))
5252

53-
with get_temp_dir() as tmp_dir:
53+
with TemporaryDirectory() as tmp_dir:
5454
call(
5555
[
5656
"git",

tests/extensions/test_label.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import unittest
4+
from tempfile import TemporaryDirectory
45

56
import pystac
67
from pystac import Catalog, Item, CatalogType
@@ -15,7 +16,7 @@
1516
)
1617
import pystac.validation
1718
from pystac.utils import get_opt
18-
from tests.utils import TestCases, assert_to_from_dict, get_temp_dir
19+
from tests.utils import TestCases, assert_to_from_dict
1920

2021

2122
class LabelTest(unittest.TestCase):
@@ -85,7 +86,7 @@ def test_validate_label(self) -> None:
8586
label_example_1_dict, pystac.STACObjectType.ITEM
8687
)
8788

88-
with get_temp_dir() as tmp_dir:
89+
with TemporaryDirectory() as tmp_dir:
8990
cat_dir = os.path.join(tmp_dir, "catalog")
9091
catalog = TestCases.test_case_1()
9192
catalog.normalize_and_save(cat_dir, catalog_type=CatalogType.SELF_CONTAINED)

tests/test_catalog.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import json
3+
from tempfile import TemporaryDirectory
34
from typing import Any, Dict, List, Tuple, Union, cast
45
import unittest
56
from datetime import datetime
@@ -22,14 +23,13 @@
2223
ARBITRARY_GEOM,
2324
ARBITRARY_BBOX,
2425
MockStacIO,
25-
get_temp_dir,
2626
)
2727

2828

2929
class CatalogTypeTest(unittest.TestCase):
3030
def test_determine_type_for_absolute_published(self) -> None:
3131
cat = TestCases.test_case_1()
32-
with get_temp_dir() as tmp_dir:
32+
with TemporaryDirectory() as tmp_dir:
3333
cat.normalize_and_save(tmp_dir, catalog_type=CatalogType.ABSOLUTE_PUBLISHED)
3434
cat_json = pystac.StacIO.default().read_json(
3535
os.path.join(tmp_dir, "catalog.json")
@@ -40,7 +40,7 @@ def test_determine_type_for_absolute_published(self) -> None:
4040

4141
def test_determine_type_for_relative_published(self) -> None:
4242
cat = TestCases.test_case_2()
43-
with get_temp_dir() as tmp_dir:
43+
with TemporaryDirectory() as tmp_dir:
4444
cat.normalize_and_save(tmp_dir, catalog_type=CatalogType.RELATIVE_PUBLISHED)
4545
cat_json = pystac.StacIO.default().read_json(
4646
os.path.join(tmp_dir, "catalog.json")
@@ -68,7 +68,7 @@ def test_determine_type_for_unknown(self) -> None:
6868

6969
class CatalogTest(unittest.TestCase):
7070
def test_create_and_read(self) -> None:
71-
with get_temp_dir() as tmp_dir:
71+
with TemporaryDirectory() as tmp_dir:
7272
cat_dir = os.path.join(tmp_dir, "catalog")
7373
catalog = TestCases.test_case_1()
7474

@@ -288,7 +288,7 @@ def test_clone_generates_correct_links(self) -> None:
288288
def test_save_uses_previous_catalog_type(self) -> None:
289289
catalog = TestCases.test_case_1()
290290
assert catalog.catalog_type == CatalogType.SELF_CONTAINED
291-
with get_temp_dir() as tmp_dir:
291+
with TemporaryDirectory() as tmp_dir:
292292
catalog.normalize_hrefs(tmp_dir)
293293
href = catalog.self_href
294294
catalog.save()
@@ -365,7 +365,7 @@ def test_generate_subcatalogs_does_not_change_item_count(self) -> None:
365365

366366
catalog.generate_subcatalogs("${year}/${day}")
367367

368-
with get_temp_dir() as tmp_dir:
368+
with TemporaryDirectory() as tmp_dir:
369369
catalog.normalize_hrefs(tmp_dir)
370370
catalog.save(pystac.CatalogType.SELF_CONTAINED)
371371

@@ -494,7 +494,7 @@ def item_mapper(item: pystac.Item) -> pystac.Item:
494494
item.properties["ITEM_MAPPER"] = "YEP"
495495
return item
496496

497-
with get_temp_dir() as tmp_dir:
497+
with TemporaryDirectory() as tmp_dir:
498498
catalog = TestCases.test_case_1()
499499

500500
new_cat = catalog.map_items(item_mapper)
@@ -518,7 +518,7 @@ def item_mapper(item: pystac.Item) -> List[pystac.Item]:
518518
item2.properties["ITEM_MAPPER_2"] = "YEP"
519519
return [item, item2]
520520

521-
with get_temp_dir() as tmp_dir:
521+
with TemporaryDirectory() as tmp_dir:
522522
catalog = TestCases.test_case_1()
523523
catalog_items = catalog.get_all_items()
524524

@@ -623,7 +623,7 @@ def asset_mapper(key: str, asset: pystac.Asset) -> pystac.Asset:
623623

624624
return asset
625625

626-
with get_temp_dir() as tmp_dir:
626+
with TemporaryDirectory() as tmp_dir:
627627
catalog = TestCases.test_case_2()
628628

629629
new_cat = catalog.map_assets(asset_mapper)
@@ -656,7 +656,7 @@ def asset_mapper(
656656
else:
657657
return asset
658658

659-
with get_temp_dir() as tmp_dir:
659+
with TemporaryDirectory() as tmp_dir:
660660
catalog = TestCases.test_case_2()
661661

662662
new_cat = catalog.map_assets(asset_mapper)
@@ -696,7 +696,7 @@ def asset_mapper(
696696
else:
697697
return asset
698698

699-
with get_temp_dir() as tmp_dir:
699+
with TemporaryDirectory() as tmp_dir:
700700
catalog = TestCases.test_case_2()
701701

702702
new_cat = catalog.map_assets(asset_mapper)
@@ -771,7 +771,7 @@ def check_all_absolute(cat: Catalog) -> None:
771771
test_cases = TestCases.all_test_catalogs()
772772

773773
for catalog in test_cases:
774-
with get_temp_dir() as tmp_dir:
774+
with TemporaryDirectory() as tmp_dir:
775775
c2 = catalog.full_copy()
776776
c2.normalize_hrefs(tmp_dir)
777777
c2.catalog_type = CatalogType.RELATIVE_PUBLISHED
@@ -797,7 +797,7 @@ def test_extra_fields(self) -> None:
797797

798798
catalog.extra_fields["custom_field"] = "Special content"
799799

800-
with get_temp_dir() as tmp_dir:
800+
with TemporaryDirectory() as tmp_dir:
801801
p = os.path.join(tmp_dir, "catalog.json")
802802
catalog.save_object(include_self_link=False, dest_href=p)
803803
with open(p) as f:
@@ -822,7 +822,7 @@ def test_validate_all(self) -> None:
822822
item = cat.get_item("area-1-1-labels", recursive=True)
823823
assert item is not None
824824
item.geometry = {"type": "INVALID", "coordinates": "NONE"}
825-
with get_temp_dir() as tmp_dir:
825+
with TemporaryDirectory() as tmp_dir:
826826
cat.normalize_hrefs(tmp_dir)
827827
cat.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)
828828

@@ -843,7 +843,7 @@ def test_set_hrefs_manually(self) -> None:
843843
year += 1
844844
month += 1
845845

846-
with get_temp_dir() as tmp_dir:
846+
with TemporaryDirectory() as tmp_dir:
847847
for root, _, items in catalog.walk():
848848

849849
# Set root's HREF based off the parent
@@ -933,7 +933,7 @@ def test_reading_iterating_and_writing_works_as_expected(self) -> None:
933933
for item in cat.get_all_items():
934934
pass
935935

936-
with get_temp_dir() as tmp_dir:
936+
with TemporaryDirectory() as tmp_dir:
937937
new_stac_uri = os.path.join(tmp_dir, "test-case-6")
938938
cat.normalize_hrefs(new_stac_uri)
939939
cat.save(catalog_type=CatalogType.SELF_CONTAINED)
@@ -1003,7 +1003,7 @@ def check_catalog(self, c: Catalog, tag: str) -> None:
10031003
self.check_item(item, tag)
10041004

10051005
def test_full_copy_1(self) -> None:
1006-
with get_temp_dir() as tmp_dir:
1006+
with TemporaryDirectory() as tmp_dir:
10071007
cat = Catalog(id="test", description="test catalog")
10081008

10091009
item = Item(
@@ -1024,7 +1024,7 @@ def test_full_copy_1(self) -> None:
10241024
self.check_catalog(cat2, "dest")
10251025

10261026
def test_full_copy_2(self) -> None:
1027-
with get_temp_dir() as tmp_dir:
1027+
with TemporaryDirectory() as tmp_dir:
10281028
cat = Catalog(id="test", description="test catalog")
10291029
image_item = Item(
10301030
id="Imagery",
@@ -1071,7 +1071,7 @@ def test_full_copy_2(self) -> None:
10711071
self.check_catalog(cat2, "dest")
10721072

10731073
def test_full_copy_3(self) -> None:
1074-
with get_temp_dir() as tmp_dir:
1074+
with TemporaryDirectory() as tmp_dir:
10751075
root_cat = TestCases.test_case_1()
10761076
root_cat.normalize_hrefs(
10771077
os.path.join(tmp_dir, "catalog-full-copy-3-source")
@@ -1085,7 +1085,7 @@ def test_full_copy_3(self) -> None:
10851085
self.check_catalog(cat2, "dest")
10861086

10871087
def test_full_copy_4(self) -> None:
1088-
with get_temp_dir() as tmp_dir:
1088+
with TemporaryDirectory() as tmp_dir:
10891089
root_cat = TestCases.test_case_2()
10901090
root_cat.normalize_hrefs(
10911091
os.path.join(tmp_dir, "catalog-full-copy-4-source")

tests/test_collection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import json
44
from datetime import datetime
55
from dateutil import tz
6+
from tempfile import TemporaryDirectory
67

78
import pystac
89
from pystac.extensions.eo import EOExtension
910
from pystac.validation import validate_dict
1011
from pystac import Collection, Item, Extent, SpatialExtent, TemporalExtent, CatalogType
1112
from pystac.utils import datetime_to_str
12-
from tests.utils import TestCases, ARBITRARY_GEOM, ARBITRARY_BBOX, get_temp_dir
13+
from tests.utils import TestCases, ARBITRARY_GEOM, ARBITRARY_BBOX
1314

1415
TEST_DATETIME = datetime(2020, 3, 14, 16, 32)
1516

@@ -34,7 +35,7 @@ def test_save_uses_previous_catalog_type(self) -> None:
3435
collection = TestCases.test_case_8()
3536
assert collection.STAC_OBJECT_TYPE == pystac.STACObjectType.COLLECTION
3637
self.assertEqual(collection.catalog_type, CatalogType.SELF_CONTAINED)
37-
with get_temp_dir() as tmp_dir:
38+
with TemporaryDirectory() as tmp_dir:
3839
collection.normalize_hrefs(tmp_dir)
3940
href = collection.self_href
4041
collection.save()
@@ -83,7 +84,7 @@ def test_extra_fields(self) -> None:
8384

8485
collection.extra_fields["test"] = "extra"
8586

86-
with get_temp_dir() as tmp_dir:
87+
with TemporaryDirectory() as tmp_dir:
8788
p = os.path.join(tmp_dir, "collection.json")
8889
collection.save_object(include_self_link=False, dest_href=p)
8990
with open(p) as f:

tests/test_item.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from datetime import datetime
33
import json
4+
from tempfile import TemporaryDirectory
45
from typing import Any, Dict, List
56
import unittest
67

@@ -10,7 +11,7 @@
1011
import pystac.serialization.common_properties
1112
from pystac.item import CommonMetadata
1213
from pystac.utils import datetime_to_str, get_opt, str_to_datetime, is_absolute_href
13-
from tests.utils import TestCases, assert_to_from_dict, get_temp_dir
14+
from tests.utils import TestCases, assert_to_from_dict
1415

1516

1617
class ItemTest(unittest.TestCase):
@@ -72,7 +73,7 @@ def test_extra_fields(self) -> None:
7273

7374
item.extra_fields["test"] = "extra"
7475

75-
with get_temp_dir() as tmp_dir:
76+
with TemporaryDirectory() as tmp_dir:
7677
p = os.path.join(tmp_dir, "item.json")
7778
item.save_object(include_self_link=False, dest_href=p)
7879
with open(p) as f:

tests/test_stac_io.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
22
import unittest
33
import warnings
4+
from tempfile import TemporaryDirectory
45

56
import pystac
67
from pystac.stac_io import STAC_IO
7-
from tests.utils import TestCases, get_temp_dir
8+
from tests.utils import TestCases
89

910

1011
class StacIOTest(unittest.TestCase):
@@ -25,14 +26,14 @@ def test_read_write_collection(self) -> None:
2526
collection = pystac.read_file(
2627
TestCases.get_path("data-files/collections/multi-extent.json")
2728
)
28-
with get_temp_dir() as tmp_dir:
29+
with TemporaryDirectory() as tmp_dir:
2930
dest_href = os.path.join(tmp_dir, "collection.json")
3031
pystac.write_file(collection, dest_href=dest_href)
3132
self.assertTrue(os.path.exists(dest_href), msg="File was not written.")
3233

3334
def test_read_item(self) -> None:
3435
item = pystac.read_file(TestCases.get_path("data-files/item/sample-item.json"))
35-
with get_temp_dir() as tmp_dir:
36+
with TemporaryDirectory() as tmp_dir:
3637
dest_href = os.path.join(tmp_dir, "item.json")
3738
pystac.write_file(item, dest_href=dest_href)
3839
self.assertTrue(os.path.exists(dest_href), msg="File was not written.")
@@ -41,7 +42,7 @@ def test_read_write_catalog(self) -> None:
4142
catalog = pystac.read_file(
4243
TestCases.get_path("data-files/catalogs/test-case-1/catalog.json")
4344
)
44-
with get_temp_dir() as tmp_dir:
45+
with TemporaryDirectory() as tmp_dir:
4546
dest_href = os.path.join(tmp_dir, "catalog.json")
4647
pystac.write_file(catalog, dest_href=dest_href)
4748
self.assertTrue(os.path.exists(dest_href), msg="File was not written.")

tests/test_writing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import unittest
2+
from tempfile import TemporaryDirectory
23
from typing import Any, List
34

45
import pystac
56
from pystac import Collection, CatalogType, HIERARCHICAL_LINKS
67
from pystac.utils import is_absolute_href, make_absolute_href, make_relative_href
78
from pystac.validation import validate_dict
89

9-
from tests.utils import TestCases, get_temp_dir
10+
from tests.utils import TestCases
1011

1112

1213
class STACWritingTest(unittest.TestCase):
@@ -104,7 +105,7 @@ def validate_catalog_link_type(
104105
def do_test(
105106
self, catalog: pystac.Catalog, catalog_type: pystac.CatalogType
106107
) -> None:
107-
with get_temp_dir() as tmp_dir:
108+
with TemporaryDirectory() as tmp_dir:
108109
catalog.normalize_hrefs(tmp_dir)
109110
self.validate_catalog(catalog)
110111

0 commit comments

Comments
 (0)