Skip to content

Commit 0e63c74

Browse files
author
Bryan Lawrence
committed
Fixed various test issues
1 parent 1a61ec9 commit 0e63c74

11 files changed

Lines changed: 43 additions & 34 deletions

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ addopts = """
7474
pythonpath = ["."]
7575
markers = [
7676
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
77-
"integration: marks tests requiring external services (SSH, remote servers)",
77+
"integration: marks tests that exercise multiple internal components together (local/loopback integration)",
78+
"external_service: marks tests that depend on externally hosted network services",
7879
]
7980

8081
[tool.coverage.run]

tests/integration/test_bigger_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@pytest.fixture
1818
def test_data_path():
1919
"""Path to test data for CMOR fixes."""
20-
return Path(__file__).resolve().parent / 'test_data'
20+
return Path(__file__).resolve().parents[1] / 'test_data'
2121

2222

2323
def create_hyb_pres_file_without_ap(dataset, short_name):

tests/integration/test_cfdm_local.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _stop_loopback_server(
6363
def test_cfdm_read_local_file_handle_repeatedly() -> None:
6464
"""cfdm.read should work with a local file-handle repeatedly."""
6565

66-
data_path = Path(__file__).parent / "data" / "test1.nc"
66+
data_path = Path(__file__).parents[1] / "test_data" / "test1.nc"
6767
local_fs = fsspec.filesystem("local")
6868
with local_fs.open(str(data_path), "rb") as handle:
6969
handle.seek(0)
@@ -79,7 +79,7 @@ def test_cfdm_read_local_file_handle_repeatedly() -> None:
7979
def test_cfdm_read_open_pyfive_file() -> None:
8080
"""cfdm.read should work when given an actual open pyfive.File object."""
8181

82-
data_path = Path(__file__).parent / "data" / "test1.nc"
82+
data_path = Path(__file__).parents[1] / "test_data" / "test1.nc"
8383
with pyfive.File(str(data_path)) as file_obj:
8484
print(f"\n[DEBUG] pyfive.File test")
8585
print(f" type: {type(file_obj)}")
@@ -94,7 +94,7 @@ def test_cfdm_read_remote_rfile_over_loopback() -> None:
9494

9595
connection = _start_loopback_server(ServerStub)
9696
session = connection[0]
97-
data_path = str(Path(__file__).parent / "data" / "test1.nc")
97+
data_path = str(Path(__file__).parents[1] / "test_data" / "test1.nc")
9898
try:
9999
with session.open(data_path) as remote_file:
100100
fields = cfdm.read(remote_file)
@@ -108,7 +108,7 @@ def test_remote_dataset_read_after_rfile_close_matches_pyfive() -> None:
108108

109109
connection = _start_loopback_server(ServerStub)
110110
session = connection[0]
111-
data_path = str(Path(__file__).parent / "data" / "test1.nc")
111+
data_path = str(Path(__file__).parents[1] / "test_data" / "test1.nc")
112112
try:
113113
remote_file = session.open(data_path)
114114
dataset = remote_file["tas"]

tests/integration/test_compression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_compression_and_filters_cmip6_data(storage_options, active_storage_url)
101101
Test use of datasets with compression and filters applied for a real
102102
CMIP6 dataset (CMIP6_IPSL-CM6A-LR_tas).
103103
"""
104-
test_file = str(Path(__file__).resolve().parent / 'test_data' / 'CMIP6_IPSL-CM6A-LR_tas.nc')
104+
test_file = str(Path(__file__).resolve().parents[1] / 'test_data' / 'CMIP6_IPSL-CM6A-LR_tas.nc')
105105
with Dataset(test_file) as nc_data:
106106
nc_min = np.min(nc_data["tas"][0:2,4:6,7:9])
107107
print(f"Numpy min from compressed file {nc_min}")
@@ -131,7 +131,7 @@ def test_compression_and_filters_obs4mips_data(storage_options, active_storage_u
131131
obs4mips dataset (obs4MIPS_CERES-EBAF_L3B_Ed2-8_rlut.nc) at CMIP5 MIP standard
132132
but with CMIP6-standard file packaging.
133133
"""
134-
test_file = str(Path(__file__).resolve().parent / 'test_data' / 'obs4MIPS_CERES-EBAF_L3B_Ed2-8_rlut.nc')
134+
test_file = str(Path(__file__).resolve().parents[1] / 'test_data' / 'obs4MIPS_CERES-EBAF_L3B_Ed2-8_rlut.nc')
135135
with Dataset(test_file) as nc_data:
136136
nc_min = np.min(nc_data["rlut"][0:2,4:6,7:9])
137137
print(f"Numpy min from compressed file {nc_min}")

tests/integration/test_compression_remote_reductionist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_compression_and_filters_cmip6_data(storage_options, active_storage_url)
4747
S3 anon=True Bucket and File: bnl CMIP6-test.nc
4848
Reductionist request data dictionary: {'source': 'https://uor-aces-o.s3-ext.jc.rl.ac.uk', 'bucket': 'bnl', 'object': 'CMIP6-test.nc', 'dtype': 'float32', 'byte_order': 'little', 'offset': 29385, 'size': 942518, 'order': 'C', 'shape': (15, 143, 144), 'selection': [[0, 2, 1], [4, 6, 1], [7, 9, 1]], 'compression': {'id': 'zlib'}}
4949
"""
50-
test_file = str(Path(__file__).resolve().parent / 'test_data' / 'CMIP6-test.nc')
50+
test_file = str(Path(__file__).resolve().parents[1] / 'test_data' / 'CMIP6-test.nc')
5151
with Dataset(test_file) as nc_data:
5252
nc_min = np.min(nc_data["tas"][0:2,4:6,7:9])
5353
print(f"Numpy min from compressed file {nc_min}")
@@ -93,7 +93,7 @@ def test_compression_and_filters_cmip6_forced_s3_from_local(storage_options, act
9393
9494
This is for a special anon=True bucket ONLY.
9595
"""
96-
test_file = str(Path(__file__).resolve().parent / 'test_data' / 'CMIP6-test.nc')
96+
test_file = str(Path(__file__).resolve().parents[1] / 'test_data' / 'CMIP6-test.nc')
9797
with Dataset(test_file) as nc_data:
9898
nc_min = np.min(nc_data["tas"][0:2,4:6,7:9])
9999
print(f"Numpy min from compressed file {nc_min}")
@@ -128,7 +128,7 @@ def test_compression_and_filters_cmip6_forced_s3_from_local_2():
128128
'client_kwargs': {'endpoint_url': "https://uor-aces-o.s3-ext.jc.rl.ac.uk"}
129129
}
130130
active_storage_url = "https://192.171.169.248:8080"
131-
test_file = str(Path(__file__).resolve().parent / 'test_data' / 'CMIP6-test.nc')
131+
test_file = str(Path(__file__).resolve().parents[1] / 'test_data' / 'CMIP6-test.nc')
132132
with Dataset(test_file) as nc_data:
133133
nc_min = np.min(nc_data["tas"][0:2,4:6,7:9])
134134
print(f"Numpy min from compressed file {nc_min}")
@@ -170,7 +170,7 @@ def test_compression_and_filters_cmip6_forced_s3_using_local_Reductionist():
170170
'client_kwargs': {'endpoint_url': "https://uor-aces-o.s3-ext.jc.rl.ac.uk"}
171171
}
172172

173-
test_file = str(Path(__file__).resolve().parent / 'test_data' / 'CMIP6-test.nc')
173+
test_file = str(Path(__file__).resolve().parents[1] / 'test_data' / 'CMIP6-test.nc')
174174
with Dataset(test_file) as nc_data:
175175
nc_min = np.min(nc_data["tas"][0:2,4:6,7:9])
176176
print(f"Numpy min from compressed file {nc_min}")

tests/integration/test_loopback.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_server_detect_file_format_from_magic(tmp_path: Path) -> None:
183183
def test_loopback_proxy_round_trip() -> None:
184184
connection = _start_loopback_server(ServerStub)
185185
session = connection[0]
186-
data_path = str(Path(__file__).parent / "data" / "test1.nc")
186+
data_path = str(Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc")
187187
try:
188188
with session.open(data_path) as proxy:
189189
assert "tas" in proxy.keys()
@@ -228,7 +228,7 @@ def test_loopback_proxy_round_trip() -> None:
228228
def test_loopback_get_chunk_recovers_when_server_loses_file_state() -> None:
229229
connection = _start_loopback_server(DropFileStateBeforeGetChunkServer)
230230
session = connection[0]
231-
data_path = str(Path(__file__).parent / "data" / "contiguous_eg.nc")
231+
data_path = str(Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "contiguous_eg.nc")
232232
try:
233233
with session.open(data_path) as proxy:
234234
q = proxy["q"]
@@ -241,7 +241,7 @@ def test_loopback_get_chunk_recovers_when_server_loses_file_state() -> None:
241241
def test_loopback_get_chunks_recovers_when_server_loses_file_state() -> None:
242242
connection = _start_loopback_server(DropFileStateBeforeGetChunksServer)
243243
session = connection[0]
244-
data_path = str(Path(__file__).parent / "data" / "test1.nc")
244+
data_path = str(Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc")
245245
try:
246246
with session.open(data_path) as proxy:
247247
tas = proxy["tas"]
@@ -254,7 +254,7 @@ def test_loopback_get_chunks_recovers_when_server_loses_file_state() -> None:
254254
def test_loopback_reduce_recovers_when_server_loses_file_state() -> None:
255255
connection = _start_loopback_server(DropFileStateBeforeReduceServer)
256256
session = connection[0]
257-
data_path = str(Path(__file__).parent / "data" / "test1.nc")
257+
data_path = str(Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc")
258258
try:
259259
session.file_open(data_path)
260260
response = session.reduce_selection(
@@ -272,7 +272,7 @@ def test_loopback_reduce_recovers_when_server_loses_file_state() -> None:
272272
def test_contiguous_file_data_and_coordinates_round_trip() -> None:
273273
connection = _start_loopback_server(ServerStub)
274274
session = connection[0]
275-
data_path = str(Path(__file__).parent / "data" / "contiguous_eg.nc")
275+
data_path = str(Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "contiguous_eg.nc")
276276
try:
277277
with session.open(data_path) as proxy:
278278
ref_file = pyfive.File(data_path)
@@ -310,7 +310,7 @@ def test_contiguous_file_data_and_coordinates_round_trip() -> None:
310310
def test_enum_file_round_trip() -> None:
311311
connection = _start_loopback_server(ServerStub)
312312
session = connection[0]
313-
data_path = str(Path(__file__).parent / "data" / "enum_variable.nc")
313+
data_path = str(Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "enum_variable.nc")
314314
try:
315315
with session.open(data_path) as proxy:
316316
ref_file = pyfive.File(data_path)
@@ -341,7 +341,7 @@ def test_enum_file_round_trip() -> None:
341341
def test_loopback_shared_roundtrip_assertions(filename: str) -> None:
342342
connection = _start_loopback_server(ServerStub)
343343
session = connection[0]
344-
data_path = Path(__file__).parent / "data" / filename
344+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / filename
345345
try:
346346
assert_roundtrip_file_matches(session, data_path, str(data_path))
347347
finally:
@@ -371,7 +371,7 @@ def test_unexpected_response_type_raises() -> None:
371371
def test_real_server_var_open_includes_rich_metadata() -> None:
372372
connection = _start_loopback_server(ServerStub)
373373
session = connection[0]
374-
data_path = Path(__file__).parent / "data" / "test1.nc"
374+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
375375
try:
376376
file_info = session.file_open(str(data_path))
377377
assert "tas" in file_info["keys"]
@@ -421,7 +421,7 @@ def __getitem__(self, key: str) -> FakeDataset:
421421
def close(self) -> None:
422422
self.closed = True
423423

424-
data_path = Path(__file__).parent / "data" / "test1.nc"
424+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
425425
first_file = FakeFile("old_var", FakeDataset("old_var", 1))
426426
second_file = FakeFile("new_var", FakeDataset("new_var", 2))
427427
opened_files = iter([first_file, second_file])
@@ -465,7 +465,7 @@ def test_get_dataset_rejects_stale_cache_when_file_not_open() -> None:
465465
def test_real_server_get_chunk_for_chunked_and_contiguous() -> None:
466466
connection = _start_loopback_server(ServerStub)
467467
session = connection[0]
468-
data_path = Path(__file__).parent / "data" / "test1.nc"
468+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
469469
try:
470470
session.file_open(str(data_path))
471471

@@ -504,7 +504,7 @@ def test_real_server_get_chunk_for_chunked_and_contiguous() -> None:
504504
def test_real_server_reduce_supports_selection_and_chunk_modes() -> None:
505505
connection = _start_loopback_server(ServerStub)
506506
session = connection[0]
507-
data_path = Path(__file__).parent / "data" / "contiguous_eg.nc"
507+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "contiguous_eg.nc"
508508
try:
509509
session.file_open(str(data_path))
510510

@@ -543,7 +543,7 @@ def test_real_server_reduce_supports_selection_and_chunk_modes() -> None:
543543
def test_real_server_reduce_selection_parallel_full_dataset() -> None:
544544
connection = _start_loopback_server(ServerStub)
545545
session = connection[0]
546-
data_path = Path(__file__).parent / "data" / "test1.nc"
546+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
547547
try:
548548
session.file_open(str(data_path))
549549
response = session.reduce_selection(
@@ -568,7 +568,7 @@ def test_real_server_reduce_selection_parallel_full_dataset() -> None:
568568
def test_real_server_reduce_selection_parallel_partial_selection() -> None:
569569
connection = _start_loopback_server(ServerStub)
570570
session = connection[0]
571-
data_path = Path(__file__).parent / "data" / "test1.nc"
571+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
572572
try:
573573
session.file_open(str(data_path))
574574
response = session.reduce_selection(
@@ -597,7 +597,7 @@ def test_real_server_reduce_selection_parallel_partial_selection() -> None:
597597
def test_real_server_reduce_selection_chunk_planned_with_single_thread() -> None:
598598
connection = _start_loopback_server(ServerStub)
599599
session = connection[0]
600-
data_path = Path(__file__).parent / "data" / "test1.nc"
600+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
601601
try:
602602
session.file_open(str(data_path))
603603
response = session.reduce_selection(
@@ -639,7 +639,7 @@ def test_real_server_reduce_selection_chunk_planned_with_single_thread() -> None
639639
def test_reduce_selection_chunked_all_operations_full_dataset(operation, ref_fn) -> None:
640640
connection = _start_loopback_server(ServerStub)
641641
session = connection[0]
642-
data_path = Path(__file__).parent / "data" / "test1.nc"
642+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
643643
try:
644644
session.file_open(str(data_path))
645645
response = session.reduce_selection(str(data_path), "tas", operation, selection=None, thread_count=4)
@@ -670,7 +670,7 @@ def test_reduce_selection_chunked_all_operations_full_dataset(operation, ref_fn)
670670
def test_reduce_selection_chunked_all_operations_partial_selection(operation, ref_fn) -> None:
671671
connection = _start_loopback_server(ServerStub)
672672
session = connection[0]
673-
data_path = Path(__file__).parent / "data" / "test1.nc"
673+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
674674
sel = [
675675
{"type": "slice", "start": 2, "stop": 10, "step": 1},
676676
{"type": "slice", "start": 10, "stop": 50, "step": 1},
@@ -707,7 +707,7 @@ def test_reduce_selection_chunked_all_operations_partial_selection(operation, re
707707
def test_reduce_selection_contiguous_all_operations_full_dataset(operation, ref_fn) -> None:
708708
connection = _start_loopback_server(ServerStub)
709709
session = connection[0]
710-
data_path = Path(__file__).parent / "data" / "contiguous_eg.nc"
710+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "contiguous_eg.nc"
711711
try:
712712
session.file_open(str(data_path))
713713
response = session.reduce_selection(str(data_path), "q", operation, selection=None)
@@ -730,7 +730,7 @@ def test_reduce_selection_contiguous_all_operations_full_dataset(operation, ref_
730730
def test_reduce_chunk_on_chunked_variable() -> None:
731731
connection = _start_loopback_server(ServerStub)
732732
session = connection[0]
733-
data_path = Path(__file__).parent / "data" / "test1.nc"
733+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
734734
try:
735735
session.file_open(str(data_path))
736736
meta = session.var_open(str(data_path), "tas")
@@ -754,7 +754,7 @@ def test_reduce_chunk_on_chunked_variable() -> None:
754754
def test_reduce_chunk_on_contiguous_variable() -> None:
755755
connection = _start_loopback_server(ServerStub)
756756
session = connection[0]
757-
data_path = Path(__file__).parent / "data" / "contiguous_eg.nc"
757+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "contiguous_eg.nc"
758758
try:
759759
session.file_open(str(data_path))
760760
meta = session.var_open(str(data_path), "q")
@@ -791,7 +791,7 @@ def test_reduce_chunk_on_contiguous_variable() -> None:
791791
def test_reduce_selection_unknown_operation_chunked_raises() -> None:
792792
connection = _start_loopback_server(ServerStub)
793793
session = connection[0]
794-
data_path = Path(__file__).parent / "data" / "test1.nc"
794+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
795795
try:
796796
session.file_open(str(data_path))
797797
with pytest.raises(ResponseError, match="unsupported reduction operation"):
@@ -807,7 +807,7 @@ def test_reduce_selection_unknown_operation_chunked_raises() -> None:
807807
def test_reduce_selection_thread_count_exceeds_chunk_count() -> None:
808808
connection = _start_loopback_server(ServerStub)
809809
session = connection[0]
810-
data_path = Path(__file__).parent / "data" / "test1.nc"
810+
data_path = Path(__file__).parents[2] / "p5rem" / "tests" / "data" / "test1.nc"
811811
try:
812812
session.file_open(str(data_path))
813813
# A 1-timestep selection hits at most a handful of chunks; use 1000 workers.

tests/integration/test_real_https.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from requests.exceptions import MissingSchema
55
from activestorage.active import Active, load_from_https
66

7+
pytestmark = [pytest.mark.external_service]
8+
79

810
def test_https():
911
"""

tests/integration/test_real_https_extras.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from activestorage.active import Active, load_from_https
55

6+
pytestmark = [pytest.mark.external_service]
7+
68

79
@pytest.mark.skip(
810
reason="save time: test_https_implicit_storage is more general.")

tests/integration/test_real_s3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from activestorage.active import Active, load_from_s3
77
from activestorage.reductionist import ReductionistError
88

9+
pytestmark = [pytest.mark.external_service]
10+
911

1012
S3_BUCKET = "bnl"
1113

tests/integration/test_real_s3_with_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from activestorage.active import Active
77

8+
pytestmark = [pytest.mark.external_service]
9+
810

911
S3_BUCKET = "bnl"
1012

0 commit comments

Comments
 (0)