Skip to content

Commit 9524c6d

Browse files
author
Emma Ai
committed
allow test access remote csv
1 parent 2846b64 commit 9524c6d

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

odc/stats/plugins/lc_level34.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
raise ValueError("Missing level34 class definition csv")
4242

4343
if class_def_path.startswith("s3://"):
44-
if not s3fs.S3FileSystem().exists(class_def_path):
44+
if not s3fs.S3FileSystem(anon=True).exists(class_def_path):
4545
raise FileNotFoundError(f"{class_def_path} not found")
4646
elif not os.path.exists(class_def_path):
4747
raise FileNotFoundError(f"{class_def_path} not found")

tests/test_lc_level34.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
from odc.stats.plugins._utils import generate_numexpr_expressions
33

44
import re
5+
import os
56
import numpy as np
67
import pandas as pd
78
import xarray as xr
89
import dask.array as da
910
from datacube.utils.geometry import GeoBox
1011
from affine import Affine
12+
from unittest.mock import patch
13+
1114

1215
import pytest
1316

@@ -178,27 +181,35 @@ def test_l4_classes(image_groups, urban_shape):
178181
expected_l3 = [[216, 216, 215], [216, 216, 216], [220, 215, 215], [220, 220, 220]]
179182

180183
expected_l4 = [[95, 97, 93], [97, 96, 96], [100, 93, 93], [101, 101, 101]]
181-
stats_l4 = StatsLccsLevel4(
182-
measurements=["level3", "level4"],
183-
class_def_path="s3://dea-public-data-dev/lccs_validation/c3/data_to_plot/"
184-
"lccs_colour_scheme_golden_dark_au_c3.csv",
185-
class_condition={
186-
"level3": ["level1", "artificial_surface", "cultivated"],
187-
"level4": [
188-
"level1",
189-
"level3",
190-
"woody",
191-
"water_season",
192-
"water_frequency",
193-
"pv_pc_50",
194-
"bs_pc_50",
195-
],
184+
with patch.dict(
185+
os.environ,
186+
{
187+
"AWS_ACCESS_KEY_ID": "fake-access-key",
188+
"AWS_SECRET_ACCESS_KEY": "fake-secret-key",
189+
"AWS_SESSION_TOKEN": "fake-session-token", # Optional
196190
},
197-
data_var_condition={"level1": "level_3_4"},
198-
urban_mask=urban_shape,
199-
filter_expression="mock > 9",
200-
mask_threshold=0.3,
201-
)
191+
):
192+
stats_l4 = StatsLccsLevel4(
193+
measurements=["level3", "level4"],
194+
class_def_path="s3://dea-public-data-dev/lccs_validation/c3/data_to_plot/"
195+
"lccs_colour_scheme_golden_dark_au_c3.csv",
196+
class_condition={
197+
"level3": ["level1", "artificial_surface", "cultivated"],
198+
"level4": [
199+
"level1",
200+
"level3",
201+
"woody",
202+
"water_season",
203+
"water_frequency",
204+
"pv_pc_50",
205+
"bs_pc_50",
206+
],
207+
},
208+
data_var_condition={"level1": "level_3_4"},
209+
urban_mask=urban_shape,
210+
filter_expression="mock > 9",
211+
mask_threshold=0.3,
212+
)
202213
ds = stats_l4.reduce(image_groups)
203214

204215
assert (ds.level3.compute() == expected_l3).all()

0 commit comments

Comments
 (0)