Skip to content

Commit 6aac9ad

Browse files
committed
Tests: Fix Windows compatibility across unit test suite
Enable the full unit test suite to pass on Windows (3803 passed, 0 failures). Changes: - Reduce RANDOM_LENGTH from 20 to 8 to stay under Windows MAX_PATH (260 chars) - Use warehouse.as_posix() in SQLite URIs for cross-platform path formatting - Close file handles before temp directory cleanup (Windows file locking) - Use os.path.abspath() in path assertions instead of hardcoded POSIX paths - Use raw paths instead of file: URIs in pyarrow test fixtures - Relax Rich box-drawing assertions to check content not formatting - Skip Kerberos tests on Windows (puresasl C lib unavailable) - Relax error message assertion ([Errno 2] vs [WinError 2]) Depends on #3721. Related: #2477
1 parent 1314fb4 commit 6aac9ad

6 files changed

Lines changed: 58 additions & 101 deletions

File tree

‎tests/catalog/test_hive.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import base64
1919
import copy
2020
import struct
21+
import sys
2122
import threading
2223
import uuid
2324
from collections.abc import Generator
@@ -300,7 +301,7 @@ def test_create_table(
300301
# it to construct the assert_called_with
301302
metadata_location: str = called_hive_table.parameters["metadata_location"]
302303
assert metadata_location.endswith(".metadata.json")
303-
assert "/database/table/metadata/" in metadata_location
304+
assert "/database/table/metadata/" in metadata_location.replace("\\", "/")
304305
catalog._client.__enter__().create_table.assert_called_with(
305306
HiveTable(
306307
tableName="table",
@@ -481,7 +482,7 @@ def test_create_table_with_given_location_removes_trailing_slash(
481482
# it to construct the assert_called_with
482483
metadata_location: str = called_hive_table.parameters["metadata_location"]
483484
assert metadata_location.endswith(".metadata.json")
484-
assert "/database/table-given-location/metadata/" in metadata_location
485+
assert "/database/table-given-location/metadata/" in metadata_location.replace("\\", "/")
485486
catalog._client.__enter__().create_table.assert_called_with(
486487
HiveTable(
487488
tableName="table",
@@ -1369,6 +1370,7 @@ def test_create_hive_client_failure() -> None:
13691370
assert mock_hive_client.call_count == 2
13701371

13711372

1373+
@pytest.mark.skipif(sys.platform == "win32", reason="Kerberos/puresasl not available on Windows")
13721374
def test_create_hive_client_with_kerberos(
13731375
kerberized_hive_metastore_fake_url: str,
13741376
) -> None:
@@ -1381,6 +1383,7 @@ def test_create_hive_client_with_kerberos(
13811383
assert client is not None
13821384

13831385

1386+
@pytest.mark.skipif(sys.platform == "win32", reason="Kerberos/puresasl not available on Windows")
13841387
def test_create_hive_client_with_kerberos_using_context_manager(
13851388
kerberized_hive_metastore_fake_url: str,
13861389
) -> None:
@@ -1412,6 +1415,7 @@ def test_create_hive_client_with_kerberos_using_context_manager(
14121415
assert open_client._iprot.trans.isOpen()
14131416

14141417

1418+
@pytest.mark.skipif(sys.platform == "win32", reason="Kerberos/puresasl not available on Windows")
14151419
def test_kerberized_client_uses_fresh_transport_on_reuse(
14161420
kerberized_hive_metastore_fake_url: str,
14171421
) -> None:

‎tests/catalog/test_sql.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def catalog_memory(catalog_name: str, warehouse: Path) -> Generator[SqlCatalog,
6161
@pytest.fixture(scope="module")
6262
def catalog_sqlite(catalog_name: str, warehouse: Path) -> Generator[SqlCatalog, None, None]:
6363
props = {
64-
"uri": f"sqlite:////{warehouse}/sql-catalog",
64+
"uri": f"sqlite:///{warehouse.as_posix()}/sql-catalog",
6565
"warehouse": f"file://{warehouse}",
6666
}
6767
catalog = SqlCatalog(catalog_name, **props)
@@ -72,7 +72,7 @@ def catalog_sqlite(catalog_name: str, warehouse: Path) -> Generator[SqlCatalog,
7272

7373
@pytest.fixture(scope="module")
7474
def catalog_uri(warehouse: Path) -> str:
75-
return f"sqlite:////{warehouse}/sql-catalog"
75+
return f"sqlite:///{warehouse.as_posix()}/sql-catalog"
7676

7777

7878
@pytest.fixture(scope="module")
@@ -96,7 +96,7 @@ def test_creation_with_echo_parameter(catalog_name: str, warehouse: Path) -> Non
9696

9797
for echo_param, expected_echo_value in test_cases:
9898
props = {
99-
"uri": f"sqlite:////{warehouse}/sql-catalog",
99+
"uri": f"sqlite:///{warehouse.as_posix()}/sql-catalog",
100100
"warehouse": f"file://{warehouse}",
101101
}
102102
# None is for default value
@@ -119,7 +119,7 @@ def test_creation_with_pool_pre_ping_parameter(catalog_name: str, warehouse: Pat
119119

120120
for pool_pre_ping_param, expected_pool_pre_ping_value in test_cases:
121121
props = {
122-
"uri": f"sqlite:////{warehouse}/sql-catalog",
122+
"uri": f"sqlite:///{warehouse.as_posix()}/sql-catalog",
123123
"warehouse": f"file://{warehouse}",
124124
}
125125
# None is for default value
@@ -139,7 +139,7 @@ def test_creation_from_impl(catalog_name: str, warehouse: Path) -> None:
139139
catalog_name,
140140
**{
141141
"py-catalog-impl": "pyiceberg.catalog.sql.SqlCatalog",
142-
"uri": f"sqlite:////{warehouse}/sql-catalog",
142+
"uri": f"sqlite:///{warehouse.as_posix()}/sql-catalog",
143143
"warehouse": f"file://{warehouse}",
144144
},
145145
),
@@ -268,7 +268,7 @@ def get_columns(engine: Engine) -> set[str]:
268268

269269

270270
def test_adds_iceberg_type_column_to_old_schema(warehouse: Path) -> None:
271-
uri = f"sqlite:////{warehouse}/test-migration-add-col"
271+
uri = f"sqlite:///{warehouse.as_posix()}/test-migration-add-col"
272272
engine = _create_v0_db(uri)
273273

274274
# Verify the column does not exist in the old schema
@@ -334,7 +334,7 @@ def test_list_tables_filters_by_iceberg_type(warehouse: Path) -> None:
334334

335335

336336
def test_migration_to_v1_with_property_set(warehouse: Path) -> None:
337-
uri = f"sqlite:////{warehouse}/test-v1-migrate"
337+
uri = f"sqlite:///{warehouse.as_posix()}/test-v1-migrate"
338338
engine = _create_v0_db(uri)
339339

340340
assert "iceberg_type" not in get_columns(engine)
@@ -361,7 +361,7 @@ def test_invalid_schema_version_raises(warehouse: Path) -> None:
361361

362362
def test_list_tables_works_on_v0_schema(warehouse: Path) -> None:
363363
"""list_tables should work on V0 schemas without iceberg_type column."""
364-
uri = f"sqlite:////{warehouse}/test-v0-list"
364+
uri = f"sqlite:///{warehouse.as_posix()}/test-v0-list"
365365
_create_v0_db(uri)
366366

367367
catalog = SqlCatalog(
@@ -441,15 +441,15 @@ def _make_v0_catalog(uri: str, warehouse: Path) -> SqlCatalog:
441441

442442
def test_namespace_exists_on_v0_schema(warehouse: Path) -> None:
443443
"""namespace_exists should not fail on V0 schema (no iceberg_type column)."""
444-
catalog = _make_v0_catalog(f"sqlite:////{warehouse}/test-v0-ns-exists", warehouse)
444+
catalog = _make_v0_catalog(f"sqlite:///{warehouse.as_posix()}/test-v0-ns-exists", warehouse)
445445
catalog.create_namespace("ns")
446446
assert catalog.namespace_exists("ns")
447447
assert not catalog.namespace_exists("missing")
448448

449449

450450
def test_create_and_load_table_on_v0_schema(warehouse: Path) -> None:
451451
"""create_table and load_table should work on V0 schema without iceberg_type column."""
452-
catalog = _make_v0_catalog(f"sqlite:////{warehouse}/test-v0-create", warehouse)
452+
catalog = _make_v0_catalog(f"sqlite:///{warehouse.as_posix()}/test-v0-create", warehouse)
453453
catalog.create_namespace("ns")
454454
schema = Schema(NestedField(1, "id", StringType(), required=True))
455455
tbl = catalog.create_table(("ns", "tbl"), schema)

‎tests/conftest.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,7 @@ def empty_home_dir_path(tmp_path_factory: pytest.TempPathFactory) -> str:
23882388
return home_path
23892389

23902390

2391-
RANDOM_LENGTH = 20
2391+
RANDOM_LENGTH = 8
23922392
NUM_TABLES = 2
23932393

23942394

@@ -2445,15 +2445,15 @@ def hierarchical_namespace_list(hierarchical_namespace_name: str) -> list[str]:
24452445

24462446
BUCKET_NAME = "test_bucket"
24472447
TABLE_METADATA_LOCATION_REGEX = re.compile(
2448-
r"""s3://test_bucket/my_iceberg_database-[a-z]{20}.db/
2449-
my_iceberg_table-[a-z]{20}/metadata/
2448+
r"""s3://test_bucket/my_iceberg_database-[a-z]{8}.db/
2449+
my_iceberg_table-[a-z]{8}/metadata/
24502450
[0-9]{5}-[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}.metadata.json""",
24512451
re.X,
24522452
)
24532453

24542454
BQ_TABLE_METADATA_LOCATION_REGEX = re.compile(
2455-
r"""gs://alexstephen-test-bq-bucket/my_iceberg_database_[a-z]{20}.db/
2456-
my_iceberg_table-[a-z]{20}/metadata/
2455+
r"""gs://alexstephen-test-bq-bucket/my_iceberg_database_[a-z]{8}.db/
2456+
my_iceberg_table-[a-z]{8}/metadata/
24572457
[0-9]{5}-[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}.metadata.json""",
24582458
re.X,
24592459
)
@@ -3138,7 +3138,7 @@ def _create_sql_without_rowcount_catalog(name: str, warehouse: Path) -> Catalog:
31383138
from pyiceberg.catalog.sql import SqlCatalog
31393139

31403140
props = {
3141-
"uri": f"sqlite:////{warehouse}/sql-catalog",
3141+
"uri": f"sqlite:///{warehouse.as_posix()}/sql-catalog",
31423142
"warehouse": f"file://{warehouse}",
31433143
}
31443144
catalog = SqlCatalog(name, **props)

‎tests/io/test_io.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def test_custom_local_input_file() -> None:
5353
data = f.read()
5454
assert data == b"foo"
5555
assert len(input_file) == 3
56+
f.close()
5657

5758

5859
def test_custom_local_output_file() -> None:
@@ -91,6 +92,7 @@ def test_pickled_pyarrow_round_trip() -> None:
9192
data = f.read()
9293
assert data == b"foo"
9394
assert len(input_file) == 3
95+
f.close()
9496
deserialized_file_io.delete(location=f"{absolute_file_location}")
9597

9698

0 commit comments

Comments
 (0)