Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Check out repository code
uses: actions/checkout@v5
Expand Down
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.PHONY: help install install-hooks test test-unit test-doctest build clean format lint check mypy
.DEFAULT_GOAL := help

# Use copy mode to avoid filesystem reflink issues
export UV_LINK_MODE = copy

help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
Expand All @@ -11,15 +14,15 @@ install: ## Install development dependencies
uv sync --group dev

install-hooks: ## Install pre-commit hooks (optional)
uv run pre-commit install
uv run --group dev pre-commit install

test: test-unit test-doctest ## Run all tests

test-unit: ## Run unit tests
uv run pytest tests/
uv run --group dev pytest tests/

test-doctest: ## Run doctests from README
uv run pytest README.md --markdown-docs
uv run --group dev pytest README.md --markdown-docs

build: ## Build package
uv build
Expand All @@ -30,18 +33,18 @@ clean: ## Clean build artifacts
find . -type d -name "__pycache__" -delete

format: ## Format code with ruff
uv run ruff format
uv run --group dev ruff format

format-check: ## Check if code is formatted
uv run ruff format --check
uv run --group dev ruff format --check

lint: ## Lint code with ruff
uv run ruff check
uv run --group dev ruff check

lint-fix: ## Lint and fix code with ruff
uv run ruff check --fix
uv run --group dev ruff check --fix

mypy: ## Run mypy type checking
uv run mypy urlpath/ tests/
uv run --group dev mypy urlpath/ tests/

check: format-check lint mypy test ## Run format check, linting, type checking, and tests
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",
]
Expand Down
32 changes: 32 additions & 0 deletions tests/test_url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env python3
from pathlib import PurePosixPath
from typing import Any, cast

import pytest

try:
Expand Down Expand Up @@ -52,6 +55,20 @@ def test_join() -> None:
assert str(url.with_name("other_file")) == "http://www.example.com/path/to/other_file"


def test_join_with_absolute_segment_resets_path() -> None:
url = URL("http://example.com/base/path") / "child"

assert str(url) == "http://example.com/base/path/child"
assert str(url / "/absolute") == "http://example.com/absolute"
assert str((url / "deeper") / "/absolute/child") == "http://example.com/absolute/child"


def test_constructor_with_absolute_segment_resets_path() -> None:
url = URL("http://example.com/base", "/absolute/path")

assert str(url) == "http://example.com/absolute/path"


def test_path() -> None:
url = URL("http://www.example.com/path/to/file.ext?query#fragment")

Expand Down Expand Up @@ -214,6 +231,21 @@ def test_init_with_empty_string() -> None:
assert str(url) == ""


def test_bytes_arguments_are_canonicalized_without_str_roundtrip() -> None:
url = URL(b"http://example.com/base")

assert str(url) == "http://example.com/base"
assert str(URL("http://example.com") / cast(Any, b"path")) == "http://example.com/path"


def test_pathlike_arguments_are_supported() -> None:
pathlike: Any = PurePosixPath("path/like/segment")

url = URL("http://example.com") / pathlike

assert str(url) == "http://example.com/path/like/segment"


def test_encoding() -> None:
assert URL("http://www.xn--alliancefranaise-npb.nu/").hostname == "www.alliancefran\xe7aise.nu"
assert (
Expand Down
Loading