Skip to content

Commit

Permalink
Issue 1470 paths windows (#1475)
Browse files Browse the repository at this point in the history
* test ko

* isolate assertion (very simple check here..)

* test windows correctly

* cleanup comment

* ruff fix

* update changelog

* update changelog

* fix for 3.12

* really cover in new test

* drive supported only on 3.13

* check one

* check two

* correct is_windows in tests

* correct is_windows in tests part 2

* use os path for path count

* use os path for path count in display as well

* use os path for path count in display as well

* rm whitespace

* rm unecc comment

* Update tests/test_catalog.py

* factor out function

* typo

* factor out

---------

Co-authored-by: Pete Gadomski <[email protected]>
  • Loading branch information
KeynesYouDigIt and gadomski authored Dec 9, 2024
1 parent 360081f commit 97f87cb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 11 deletions.
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"
)

0 comments on commit 97f87cb

Please sign in to comment.