Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1470 paths windows #1475

Merged
merged 25 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ jobs:
- ubuntu-latest
- windows-latest
- macos-latest
exclude:
# https://github.com/stac-utils/pystac/issues/1470
- os: windows-latest
python-version: "3.13"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ stdout*
/integration*
.idea
.vscode
.actrc


# Sphinx documentation
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Write STAC v1.1.0 ([#1427](https://github.com/stac-utils/pystac/pull/1427))
- Use [uv](https://github.com/astral-sh/uv) for development dependencies and docs ([#1439](https://github.com/stac-utils/pystac/pull/1439))
- Correctly detect absolute file path ref on windows, reflecting change in python 3.13 ([#1475]https://github.com/stac-utils/pystac/pull/1475) (only effects python 3.13)

## [v1.11.0] - 2024-09-26

Expand Down
6 changes: 5 additions & 1 deletion tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,12 +832,16 @@ def test_generate_subcatalogs_works_for_subcatalogs_with_same_ids(self) -> None:
assert len(result) == 6

catalog.normalize_hrefs("/")

for item in catalog.get_items(recursive=True):
item_parent = item.get_parent()
assert item_parent is not None
parent_href = item_parent.self_href
path_to_parent, _ = os.path.split(parent_href)
subcats = [el for el in path_to_parent.split("/") if el]
subcats = list(
Path(path_to_parent).parts[1:]
) # Skip drive letter if present (Windows)

assert len(subcats) == 2, f" for item '{item.id}'"

def test_map_items(self) -> None:
Expand Down
16 changes: 12 additions & 4 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
LayoutTemplate,
TemplateLayoutStrategy,
)
from tests.utils import ARBITRARY_BBOX, ARBITRARY_GEOM, TestCases
from tests.utils import (
ARBITRARY_BBOX,
ARBITRARY_GEOM,
TestCases,
path_includes_drive_letter,
)


class LayoutTemplateTest(unittest.TestCase):
Expand Down Expand Up @@ -412,6 +417,9 @@ def test_produces_layout_for_item(self) -> None:
class AsIsLayoutStrategyTest(unittest.TestCase):
def setUp(self) -> None:
self.strategy = AsIsLayoutStrategy()
self.expected_local_href = (
"/an/href" if not path_includes_drive_letter() else "D:/an/href"
)

def test_catalog(self) -> None:
cat = pystac.Catalog(id="test", description="test desc")
Expand All @@ -421,7 +429,7 @@ def test_catalog(self) -> None:
href = self.strategy.get_href(
cat, parent_dir="https://example.com", is_root=True
)
self.assertEqual(href, "/an/href")
self.assertEqual(href, self.expected_local_href)

def test_collection(self) -> None:
collection = TestCases.case_8()
Expand All @@ -434,7 +442,7 @@ def test_collection(self) -> None:
href = self.strategy.get_href(
collection, parent_dir="https://example.com", is_root=True
)
self.assertEqual(href, "/an/href")
self.assertEqual(href, self.expected_local_href)

def test_item(self) -> None:
collection = TestCases.case_8()
Expand All @@ -444,7 +452,7 @@ def test_item(self) -> None:
self.strategy.get_href(item, parent_dir="http://example.com")
item.set_self_href("/an/href")
href = self.strategy.get_href(item, parent_dir="http://example.com")
self.assertEqual(href, "/an/href")
self.assertEqual(href, self.expected_local_href)


class APILayoutStrategyTest(unittest.TestCase):
Expand Down
20 changes: 18 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
safe_urlparse,
str_to_datetime,
)
from tests.utils import TestCases
from tests.utils import TestCases, path_includes_drive_letter


class UtilsTest(unittest.TestCase):
Expand Down Expand Up @@ -219,17 +219,33 @@ def test_is_absolute_href(self) -> None:
("item.json", False),
("./item.json", False),
("../item.json", False),
("/item.json", True),
("http://stacspec.org/item.json", True),
]

for href, expected in test_cases:
actual = is_absolute_href(href)
self.assertEqual(actual, expected)

def test_is_absolute_href_os_aware(self) -> None:
# Test cases of (href, expected)

is_windows = os.name == "nt"
incl_drive_letter = path_includes_drive_letter()
test_cases = [
("/item.json", not incl_drive_letter),
("/home/someuser/Downloads/item.json", not incl_drive_letter),
("d:/item.json", is_windows),
("c:/files/more_files/item.json", is_windows),
]

for href, expected in test_cases:
actual = is_absolute_href(href)
self.assertEqual(actual, expected)

@pytest.mark.skipif(os.name != "nt", reason="Windows only test")
def test_is_absolute_href_windows(self) -> None:
# Test cases of (href, expected)

test_cases = [
("item.json", False),
(".\\item.json", False),
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ARBITRARY_BBOX",
"ARBITRARY_EXTENT",
"MockStacIO",
"path_includes_drive_letter",
]
from copy import deepcopy
from datetime import datetime
Expand All @@ -12,6 +13,7 @@
from dateutil.parser import parse

import pystac
from tests.utils.os_utils import path_includes_drive_letter
from tests.utils.stac_io_mock import MockStacIO
from tests.utils.test_cases import (
ARBITRARY_BBOX,
Expand Down
8 changes: 8 additions & 0 deletions tests/utils/os_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os
import sys


def path_includes_drive_letter() -> bool:
return (
sys.version_info.major >= 3 and sys.version_info.minor >= 13 and os.name == "nt"
)
Loading