diff options
author | Hind-M <hind.montassif@gmail.com> | 2021-06-07 15:03:14 +0200 |
---|---|---|
committer | Hind-M <hind.montassif@gmail.com> | 2021-06-07 15:03:14 +0200 |
commit | 82524c5b0a6ab02b020574b2200a8721f3ed424c (patch) | |
tree | e9874a6ec8cca6db1aa4cbab8ee6c0c725bb8d2a /src | |
parent | 16867ca9321e50531307253e957b91c4df7e564c (diff) |
Add test with wrong checksum
Add functions to avoid redundant code
Diffstat (limited to 'src')
-rw-r--r-- | src/python/test/test_remote_datasets.py | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/python/test/test_remote_datasets.py b/src/python/test/test_remote_datasets.py index 6c9217c8..e252980d 100644 --- a/src/python/test/test_remote_datasets.py +++ b/src/python/test/test_remote_datasets.py @@ -10,36 +10,37 @@ from gudhi.datasets import remote import re +import os.path +import pytest -def test_fetch_remote_datasets(): - # Test files download from given urls - path_file_dw = remote.fetch("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/spiral_2d.csv", "spiral_2d.csv") - names_dw = re.split(r' |/|\\', path_file_dw) - assert 'remote_datasets' == names_dw[0] - assert 'spiral_2d.csv' == names_dw[1] +def check_dir_file_names(path_file_dw, filename, dirname): + assert os.path.isfile(path_file_dw) - path_file_dw = remote.fetch("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/sphere3D_pts_on_grid.off", "sphere3D_pts_on_grid.off") names_dw = re.split(r' |/|\\', path_file_dw) - assert 'remote_datasets' == names_dw[0] - assert 'sphere3D_pts_on_grid.off' == names_dw[1] + assert dirname == names_dw[0] + assert filename == names_dw[1] +def check_fetch_output(url, filename, dirname = "remote_datasets", file_checksum = None): + path_file_dw = remote.fetch(url, filename, dirname, file_checksum) + check_dir_file_names(path_file_dw, filename, dirname) + +def test_fetch_remote_datasets(): + # Test fetch with a wrong checksum + with pytest.raises(OSError): + check_fetch_output("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/spiral_2d.csv", "spiral_2d.csv", file_checksum = 'XXXXXXXXXX') - # Test files download with checksums provided - path_file_dw = remote.fetch("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/spiral_2d.csv", "spiral_2d.csv", + # Test files download from given urls with checksums provided + check_fetch_output("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/spiral_2d.csv", "spiral_2d.csv", file_checksum = '37530355d980d957c4ec06b18c775f90a91e446107d06c6201c9b4000b077f38') - names_dw = re.split(r' |/|\\', path_file_dw) - assert 'remote_datasets' == names_dw[0] - assert 'spiral_2d.csv' == names_dw[1] - path_file_dw = remote.fetch("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/sphere3D_pts_on_grid.off", "sphere3D_pts_on_grid.off", + check_fetch_output("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/sphere3D_pts_on_grid.off", "sphere3D_pts_on_grid.off", file_checksum = '32f96d2cafb1177f0dd5e0a019b6ff5658e14a619a7815ae55ad0fc5e8bd3f88') - names_dw = re.split(r' |/|\\', path_file_dw) - assert 'remote_datasets' == names_dw[0] - assert 'sphere3D_pts_on_grid.off' == names_dw[1] + # Test files download from given urls without checksums + check_fetch_output("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/spiral_2d.csv", "spiral_2d.csv") + + check_fetch_output("https://raw.githubusercontent.com/GUDHI/gudhi-data/main/points/sphere3D_pts_on_grid.off", "sphere3D_pts_on_grid.off") # Test spiral_2d.csv wrapping function path_file_dw = remote.fetch_spiral_2d() - names_dw = re.split(r' |/|\\', path_file_dw) - assert 'remote_datasets' == names_dw[0] - assert 'spiral_2d.csv' == names_dw[1] + check_dir_file_names(path_file_dw, 'spiral_2d.csv', 'remote_datasets') |