Skip to content

Commit 9c15478

Browse files
committed
coverage
1 parent c40aff1 commit 9c15478

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

tests/datasets/test_bigearthnet.py

+43-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def dataset(
185185
root, split, bands, num_classes, transforms, download=True, checksum=True
186186
)
187187

188-
def test_getitem_s2(self, dataset: BigEarthNetV2) -> None:
189-
"""Test loading S2 or combined data."""
188+
def test_getitem(self, dataset: BigEarthNetV2) -> None:
189+
"""Test loading data."""
190190
x = dataset[0]
191191

192192
if dataset.bands in ['s2', 'all']:
@@ -222,11 +222,52 @@ def test_len(self, dataset: BigEarthNetV2) -> None:
222222
else:
223223
assert len(dataset) == 1
224224

225+
def test_already_downloaded(self, dataset: BigEarthNetV2, tmp_path: Path) -> None:
226+
BigEarthNetV2(
227+
root=tmp_path,
228+
bands=dataset.bands,
229+
split=dataset.split,
230+
num_classes=dataset.num_classes,
231+
download=True,
232+
)
233+
225234
def test_not_downloaded(self, tmp_path: Path) -> None:
226235
"""Test error handling when data not present."""
227236
with pytest.raises(DatasetNotFoundError, match='Dataset not found'):
228237
BigEarthNetV2(tmp_path)
229238

239+
def test_already_downloaded_not_extracted(
240+
self, dataset: BigEarthNetV2, tmp_path: Path
241+
) -> None:
242+
shutil.copy(dataset.metadata_locs['metadata']['url'], tmp_path)
243+
if dataset.bands == 'all':
244+
shutil.rmtree(
245+
os.path.join(dataset.root, dataset.metadata_locs['s1']['directory'])
246+
)
247+
shutil.rmtree(
248+
os.path.join(dataset.root, dataset.metadata_locs['s2']['directory'])
249+
)
250+
shutil.copy(dataset.metadata_locs['s1']['url'], tmp_path)
251+
shutil.copy(dataset.metadata_locs['s2']['url'], tmp_path)
252+
elif dataset.bands == 's1':
253+
shutil.rmtree(
254+
os.path.join(dataset.root, dataset.metadata_locs['s1']['directory'])
255+
)
256+
shutil.copy(dataset.metadata_locs['s1']['url'], tmp_path)
257+
else:
258+
shutil.rmtree(
259+
os.path.join(dataset.root, dataset.metadata_locs['s2']['directory'])
260+
)
261+
shutil.copy(dataset.metadata_locs['s2']['url'], tmp_path)
262+
263+
BigEarthNetV2(
264+
root=tmp_path,
265+
bands=dataset.bands,
266+
split=dataset.split,
267+
num_classes=dataset.num_classes,
268+
download=False,
269+
)
270+
230271
def test_invalid_split(self, tmp_path: Path) -> None:
231272
"""Test error on invalid split."""
232273
with pytest.raises(AssertionError, match='split must be one of'):

torchgeo/datasets/bigearthnet.py

+3
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,9 @@ def _verify(self) -> None:
821821
else:
822822
exists.append(False)
823823

824+
if all(exists):
825+
return
826+
824827
if not self.download:
825828
raise DatasetNotFoundError(self)
826829

0 commit comments

Comments
 (0)