From b3b0e3f62549225f89349e420a09f5bd7b8ab780 Mon Sep 17 00:00:00 2001 From: Dobson Date: Thu, 21 Mar 2024 15:03:37 +0000 Subject: [PATCH 1/6] Mock downloads with option to turn on --- swmmanywhere/prepare_data.py | 5 +- tests/test_prepare_data.py | 113 ++++++++++++++++++++++++++++------- 2 files changed, 94 insertions(+), 24 deletions(-) diff --git a/swmmanywhere/prepare_data.py b/swmmanywhere/prepare_data.py index ab2cef1d..79439fc1 100644 --- a/swmmanywhere/prepare_data.py +++ b/swmmanywhere/prepare_data.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- -"""Created 2023-12-20. +"""Prepare data module for SWMManywhere. -@author: Barnaby Dobson +A module to download data needed for SWMManywhere. """ import shutil diff --git a/tests/test_prepare_data.py b/tests/test_prepare_data.py index 3e4ab1e3..de5e9273 100644 --- a/tests/test_prepare_data.py +++ b/tests/test_prepare_data.py @@ -3,16 +3,21 @@ @author: Barney """ - -# import pytest +import io import tempfile from pathlib import Path +from unittest import mock import geopandas as gpd +import networkx as nx +import osmnx as ox import rasterio +import yaml +from geopy.geocoders import Nominatim from swmmanywhere import prepare_data as downloaders +RUN_DOWNLOADS = False # Test get_country def test_get_uk(): @@ -20,14 +25,30 @@ def test_get_uk(): # Coordinates for London, UK x = -0.1276 y = 51.5074 - - result = downloaders.get_country(x, y) - - assert result[2] == 'GB' - assert result[3] == 'GBR' + if RUN_DOWNLOADS: + result = downloaders.get_country(x, y) + assert result[2] == 'GB' + assert result[3] == 'GBR' + else: + # Create a mock response for geolocator.reverse + mock_location = mock.Mock() + mock_location.raw = {'address': {'country_code': 'gb'}} + + # Mock Nominatim + with mock.patch.object(Nominatim, 'reverse', return_value=mock_location): + # Mock yaml.safe_load + with mock.patch.object(yaml, 'safe_load', return_value={'GB': 'GBR'}): + # Call get_country + result = downloaders.get_country(x, y) + + assert result[2] == 'GB' + assert result[3] == 'GBR' def test_get_us(): """Check a US point.""" + if not RUN_DOWNLOADS: + # Skip this test as the no-download test is same as test_get_uk + return None x = -113.43318 y = 33.81869 @@ -43,11 +64,27 @@ def test_building_downloader(): y = 43.73205 with tempfile.TemporaryDirectory() as temp_dir: temp_fid = Path(temp_dir) / 'temp.parquet' - # Download - response = downloaders.download_buildings(temp_fid, x,y) + if not RUN_DOWNLOADS: + mock_response = mock.Mock() + mock_response.status_code = 200 + mock_response.content = b'{"features": []}' + with mock.patch('requests.get', + return_value=mock_response) as mock_get: + # Call your function that uses requests.get + response = downloaders.download_buildings(temp_fid, x, y) + + # Assert that requests.get was called with the right arguments + mock_get.assert_called_once_with('https://data.source.coop/vida/google-microsoft-open-buildings/geoparquet/by_country/country_iso=MCO/MCO.parquet') + else: + # Download + response = downloaders.download_buildings(temp_fid, x,y) + # Check response assert response == 200 + if not RUN_DOWNLOADS: + return None + # Check file exists assert temp_fid.exists(), "Buildings data file not found after download." @@ -60,6 +97,16 @@ def test_building_downloader(): def test_street_downloader(): """Check streets are downloaded and a specific point in the graph.""" bbox = (-0.17929,51.49638, -0.17383,51.49846) + + if not RUN_DOWNLOADS: + mock_graph = nx.MultiDiGraph() + # Mock ox.graph_from_bbox + with mock.patch.object(ox, 'graph_from_bbox', return_value=mock_graph): + # Call download_street + G = downloaders.download_street(bbox) + assert G == mock_graph + return None + G = downloaders.download_street(bbox) # Not sure if they they are likely to change the osmid @@ -68,6 +115,16 @@ def test_street_downloader(): def test_river_downloader(): """Check rivers are downloaded and a specific point in the graph.""" bbox = (0.0402, 51.55759, 0.09825591114207548, 51.6205) + + if not RUN_DOWNLOADS: + mock_graph = nx.MultiDiGraph() + # Mock ox.graph_from_bbox + with mock.patch.object(ox, 'graph_from_bbox', return_value=mock_graph): + # Call download_street + G = downloaders.download_river(bbox) + assert G == mock_graph + return None + G = downloaders.download_river(bbox) # Not sure if they they are likely to change the osmid @@ -83,22 +140,36 @@ def test_elevation_downloader(): with tempfile.TemporaryDirectory() as temp_dir: temp_fid = Path(temp_dir) / 'temp.tif' - # Download - response = downloaders.download_elevation(temp_fid, bbox, test_api_key) + if not RUN_DOWNLOADS: + mock_response = mock.Mock() + mock_response.status_code = 200 + mock_response.raw = io.BytesIO(b'25') + with mock.patch('requests.get', + return_value=mock_response) as mock_get: + # Call your function that uses requests.get + response = downloaders.download_elevation(temp_fid, + bbox, + test_api_key) + # Assert that requests.get was called with the right arguments + assert 'https://portal.opentopography.org/API/globaldem?demtype=NASADEM&south=51.49638&north=51.49846&west=-0.17929&east=-0.17383&outputFormat=GTiff&API_Key' in mock_get.call_args[0][0] # noqa: E501 + else: + # Download + response = downloaders.download_elevation(temp_fid, bbox, test_api_key) # Check response assert response == 200 # Check response assert temp_fid.exists(), "Elevation data file not found after download." - - # Load data - with rasterio.open(temp_fid) as src: - data = src.read(1) # Reading the first band as an example - - # Make sure it has some values - assert data.size > 0, "Elevation data should have some values." - # Test some property of data (not sure if they may change this - # data) - assert data.max().max() > 25, "Elevation data should be higher." \ No newline at end of file + if RUN_DOWNLOADS: + # Load data + with rasterio.open(temp_fid) as src: + data = src.read(1) # Reading the first band as an example + + # Make sure it has some values + assert data.size > 0, "Elevation data should have some values." + + # Test some property of data (not sure if they may change this + # data) + assert data.max().max() > 25, "Elevation data should be higher." \ No newline at end of file From 283987d81f7d2e2e2338940dcb3eaade6760e932 Mon Sep 17 00:00:00 2001 From: barneydobson Date: Fri, 22 Mar 2024 10:19:39 +0000 Subject: [PATCH 2/6] Revert "Mock downloads with option to turn on" This reverts commit b3b0e3f62549225f89349e420a09f5bd7b8ab780. --- swmmanywhere/prepare_data.py | 5 +- tests/test_prepare_data.py | 113 +++++++---------------------------- 2 files changed, 24 insertions(+), 94 deletions(-) diff --git a/swmmanywhere/prepare_data.py b/swmmanywhere/prepare_data.py index 79439fc1..ab2cef1d 100644 --- a/swmmanywhere/prepare_data.py +++ b/swmmanywhere/prepare_data.py @@ -1,6 +1,7 @@ -"""Prepare data module for SWMManywhere. +# -*- coding: utf-8 -*- +"""Created 2023-12-20. -A module to download data needed for SWMManywhere. +@author: Barnaby Dobson """ import shutil diff --git a/tests/test_prepare_data.py b/tests/test_prepare_data.py index de5e9273..3e4ab1e3 100644 --- a/tests/test_prepare_data.py +++ b/tests/test_prepare_data.py @@ -3,21 +3,16 @@ @author: Barney """ -import io + +# import pytest import tempfile from pathlib import Path -from unittest import mock import geopandas as gpd -import networkx as nx -import osmnx as ox import rasterio -import yaml -from geopy.geocoders import Nominatim from swmmanywhere import prepare_data as downloaders -RUN_DOWNLOADS = False # Test get_country def test_get_uk(): @@ -25,30 +20,14 @@ def test_get_uk(): # Coordinates for London, UK x = -0.1276 y = 51.5074 - if RUN_DOWNLOADS: - result = downloaders.get_country(x, y) - assert result[2] == 'GB' - assert result[3] == 'GBR' - else: - # Create a mock response for geolocator.reverse - mock_location = mock.Mock() - mock_location.raw = {'address': {'country_code': 'gb'}} - - # Mock Nominatim - with mock.patch.object(Nominatim, 'reverse', return_value=mock_location): - # Mock yaml.safe_load - with mock.patch.object(yaml, 'safe_load', return_value={'GB': 'GBR'}): - # Call get_country - result = downloaders.get_country(x, y) - - assert result[2] == 'GB' - assert result[3] == 'GBR' + + result = downloaders.get_country(x, y) + + assert result[2] == 'GB' + assert result[3] == 'GBR' def test_get_us(): """Check a US point.""" - if not RUN_DOWNLOADS: - # Skip this test as the no-download test is same as test_get_uk - return None x = -113.43318 y = 33.81869 @@ -64,27 +43,11 @@ def test_building_downloader(): y = 43.73205 with tempfile.TemporaryDirectory() as temp_dir: temp_fid = Path(temp_dir) / 'temp.parquet' - if not RUN_DOWNLOADS: - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.content = b'{"features": []}' - with mock.patch('requests.get', - return_value=mock_response) as mock_get: - # Call your function that uses requests.get - response = downloaders.download_buildings(temp_fid, x, y) - - # Assert that requests.get was called with the right arguments - mock_get.assert_called_once_with('https://data.source.coop/vida/google-microsoft-open-buildings/geoparquet/by_country/country_iso=MCO/MCO.parquet') - else: - # Download - response = downloaders.download_buildings(temp_fid, x,y) - + # Download + response = downloaders.download_buildings(temp_fid, x,y) # Check response assert response == 200 - if not RUN_DOWNLOADS: - return None - # Check file exists assert temp_fid.exists(), "Buildings data file not found after download." @@ -97,16 +60,6 @@ def test_building_downloader(): def test_street_downloader(): """Check streets are downloaded and a specific point in the graph.""" bbox = (-0.17929,51.49638, -0.17383,51.49846) - - if not RUN_DOWNLOADS: - mock_graph = nx.MultiDiGraph() - # Mock ox.graph_from_bbox - with mock.patch.object(ox, 'graph_from_bbox', return_value=mock_graph): - # Call download_street - G = downloaders.download_street(bbox) - assert G == mock_graph - return None - G = downloaders.download_street(bbox) # Not sure if they they are likely to change the osmid @@ -115,16 +68,6 @@ def test_street_downloader(): def test_river_downloader(): """Check rivers are downloaded and a specific point in the graph.""" bbox = (0.0402, 51.55759, 0.09825591114207548, 51.6205) - - if not RUN_DOWNLOADS: - mock_graph = nx.MultiDiGraph() - # Mock ox.graph_from_bbox - with mock.patch.object(ox, 'graph_from_bbox', return_value=mock_graph): - # Call download_street - G = downloaders.download_river(bbox) - assert G == mock_graph - return None - G = downloaders.download_river(bbox) # Not sure if they they are likely to change the osmid @@ -140,36 +83,22 @@ def test_elevation_downloader(): with tempfile.TemporaryDirectory() as temp_dir: temp_fid = Path(temp_dir) / 'temp.tif' - if not RUN_DOWNLOADS: - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.raw = io.BytesIO(b'25') - with mock.patch('requests.get', - return_value=mock_response) as mock_get: - # Call your function that uses requests.get - response = downloaders.download_elevation(temp_fid, - bbox, - test_api_key) - # Assert that requests.get was called with the right arguments - assert 'https://portal.opentopography.org/API/globaldem?demtype=NASADEM&south=51.49638&north=51.49846&west=-0.17929&east=-0.17383&outputFormat=GTiff&API_Key' in mock_get.call_args[0][0] # noqa: E501 - else: - # Download - response = downloaders.download_elevation(temp_fid, bbox, test_api_key) + # Download + response = downloaders.download_elevation(temp_fid, bbox, test_api_key) # Check response assert response == 200 # Check response assert temp_fid.exists(), "Elevation data file not found after download." + + # Load data + with rasterio.open(temp_fid) as src: + data = src.read(1) # Reading the first band as an example + + # Make sure it has some values + assert data.size > 0, "Elevation data should have some values." - if RUN_DOWNLOADS: - # Load data - with rasterio.open(temp_fid) as src: - data = src.read(1) # Reading the first band as an example - - # Make sure it has some values - assert data.size > 0, "Elevation data should have some values." - - # Test some property of data (not sure if they may change this - # data) - assert data.max().max() > 25, "Elevation data should be higher." \ No newline at end of file + # Test some property of data (not sure if they may change this + # data) + assert data.max().max() > 25, "Elevation data should be higher." \ No newline at end of file From 5238e91e96398aab44708311cd191cfd998643c8 Mon Sep 17 00:00:00 2001 From: barneydobson Date: Fri, 22 Mar 2024 10:56:15 +0000 Subject: [PATCH 3/6] Update downloaders to separate tests --- pyproject.toml | 2 +- swmmanywhere/post_processing.py | 39 ++++++----- tests/test_prepare_data.py | 119 +++++++++++++++++++++++++++++--- 3 files changed, 133 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index be65c610..a70436d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,7 @@ module = "tests.*" disallow_untyped_defs = false [tool.pytest.ini_options] -# addopts = "-v --mypy -p no:warnings --cov=swmmanywhere --cov-report=html --doctest-modules --ignore=swmmanywhere/__main__.py" +addopts = "-v -p no:warnings --cov=swmmanywhere --cov-report=html --doctest-modules --ignore=swmmanywhere/__main__.py -m 'not downloads'" [tool.ruff] select = ["D", "E", "F", "I"] # pydocstyle, pycodestyle, Pyflakes, isort diff --git a/swmmanywhere/post_processing.py b/swmmanywhere/post_processing.py index bf75b89a..70e486dc 100644 --- a/swmmanywhere/post_processing.py +++ b/swmmanywhere/post_processing.py @@ -9,7 +9,7 @@ import re import shutil from pathlib import Path -from typing import Literal +from typing import Any, Literal import geopandas as gpd import numpy as np @@ -259,7 +259,7 @@ def data_dict_to_inp(data_dict: dict[str, np.ndarray], # Set the flow routing change_flow_routing(routing, new_input_file) -def explode_polygon(row): +def explode_polygon(row: pd.Series): """Explode a polygon into a DataFrame of coordinates. Args: @@ -272,12 +272,12 @@ def explode_polygon(row): ... 'geometry' : Polygon([(0,0), (1,0), ... (1,1), (0,1)])}) >>> explode_polygon(df) - x y subcatchment - 0 0 0 1 - 1 1 0 1 - 2 1 1 1 - 3 0 1 1 - 4 0 0 1 + x y subcatchment + 0 0.0 0.0 1 + 1 1.0 0.0 1 + 2 1.0 1.0 1 + 3 0.0 1.0 1 + 4 0.0 0.0 1 """ # Get the vertices of the polygon vertices = list(row['geometry'].exterior.coords) @@ -288,12 +288,12 @@ def explode_polygon(row): df['subcatchment'] = row['subcatchment'] return df -def format_to_swmm_dict(nodes, - outfalls, - conduits, - subs, - event, - symbol): +def format_to_swmm_dict(nodes: pd.DataFrame, + outfalls: pd.DataFrame, + conduits: pd.DataFrame, + subs: gpd.GeoDataFrame, + event: dict[str, Any], + symbol: dict[str, Any]) -> dict[str, np.ndarray]: """Format data to a dictionary of data arrays with columns matching SWMM. These data are the parameters of all assets that are written to the SWMM @@ -318,8 +318,9 @@ def format_to_swmm_dict(nodes, 'x', 'y', 'name'. Example: + >>> import os >>> import geopandas as gpd - >>> from shapely.geometry import Point + >>> from shapely.geometry import Point, Polygon >>> nodes = gpd.GeoDataFrame({'id' : ['node1', 'node2'], ... 'x' : [0, 1], ... 'y' : [0, 1], @@ -347,8 +348,10 @@ def format_to_swmm_dict(nodes, ... 'rc' : [1], ... 'width' : [1], ... 'slope' : [0.001], - ... 'geometry' : [sgeom.Polygon([(0,0), (1,0), - ... (1,1), (0,1)])]}) + ... 'geometry' : [Polygon([(0.0,0.0), + ... (1.0,0.0), + ... (1.0,1.0), + ... (0.0,1.0)])]}) >>> rain_fid = os.path.join(os.path.dirname(os.path.abspath(__file__)), ... '..', ... 'swmmanywhere', @@ -361,7 +364,7 @@ def format_to_swmm_dict(nodes, >>> symbol = {'x' : 0, ... 'y' : 0, ... 'name' : 'name'} - >>> data_dict = stt.format_to_swmm_dict(nodes, + >>> data_dict = format_to_swmm_dict(nodes, ... outfalls, ... conduits, ... subs, diff --git a/tests/test_prepare_data.py b/tests/test_prepare_data.py index 3e4ab1e3..4aa791d6 100644 --- a/tests/test_prepare_data.py +++ b/tests/test_prepare_data.py @@ -4,18 +4,25 @@ @author: Barney """ -# import pytest +import io import tempfile from pathlib import Path +from unittest import mock import geopandas as gpd +import networkx as nx +import osmnx as ox +import pytest import rasterio +import yaml +from geopy.geocoders import Nominatim from swmmanywhere import prepare_data as downloaders # Test get_country -def test_get_uk(): +@pytest.mark.downloads +def test_get_uk_download(): """Check a UK point.""" # Coordinates for London, UK x = -0.1276 @@ -26,7 +33,8 @@ def test_get_uk(): assert result[2] == 'GB' assert result[3] == 'GBR' -def test_get_us(): +@pytest.mark.downloads +def test_get_us_download(): """Check a US point.""" x = -113.43318 y = 33.81869 @@ -36,7 +44,8 @@ def test_get_us(): assert result[2] == 'US' assert result[3] == 'USA' -def test_building_downloader(): +@pytest.mark.downloads +def test_building_downloader_download(): """Check buildings are downloaded.""" # Coordinates for small country (VAT) x = 7.41839 @@ -57,7 +66,8 @@ def test_building_downloader(): # Make sure has some rows assert gdf.shape[0] > 0 -def test_street_downloader(): +@pytest.mark.downloads +def test_street_downloader_download(): """Check streets are downloaded and a specific point in the graph.""" bbox = (-0.17929,51.49638, -0.17383,51.49846) G = downloaders.download_street(bbox) @@ -65,7 +75,8 @@ def test_street_downloader(): # Not sure if they they are likely to change the osmid assert 26389449 in G.nodes -def test_river_downloader(): +@pytest.mark.downloads +def test_river_downloader_download(): """Check rivers are downloaded and a specific point in the graph.""" bbox = (0.0402, 51.55759, 0.09825591114207548, 51.6205) G = downloaders.download_river(bbox) @@ -73,7 +84,8 @@ def test_river_downloader(): # Not sure if they they are likely to change the osmid assert 21473922 in G.nodes -def test_elevation_downloader(): +@pytest.mark.downloads +def test_elevation_downloader_download(): """Check elevation downloads, writes, contains data, and a known elevation.""" # Please do not reuse api_key test_api_key = 'b206e65629ac0e53d599e43438560d28' @@ -101,4 +113,95 @@ def test_elevation_downloader(): # Test some property of data (not sure if they may change this # data) - assert data.max().max() > 25, "Elevation data should be higher." \ No newline at end of file + assert data.max().max() > 25, "Elevation data should be higher." + +def test_get_uk(): + """Check a UK point.""" + # Coordinates for London, UK + x = -0.1276 + y = 51.5074 + + # Create a mock response for geolocator.reverse + mock_location = mock.Mock() + mock_location.raw = {'address': {'country_code': 'gb'}} + + # Mock Nominatim + with mock.patch.object(Nominatim, 'reverse', return_value=mock_location): + # Mock yaml.safe_load + with mock.patch.object(yaml, 'safe_load', return_value={'GB': 'GBR'}): + # Call get_country + result = downloaders.get_country(x, y) + + assert result[2] == 'GB' + assert result[3] == 'GBR' + +def test_building_downloader(): + """Check buildings are downloaded.""" + # Coordinates for small country (VAT) + x = 7.41839 + y = 43.73205 + with tempfile.TemporaryDirectory() as temp_dir: + temp_fid = Path(temp_dir) / 'temp.parquet' + mock_response = mock.Mock() + mock_response.status_code = 200 + mock_response.content = b'{"features": []}' + with mock.patch('requests.get', + return_value=mock_response) as mock_get: + # Call your function that uses requests.get + response = downloaders.download_buildings(temp_fid, x, y) + + # Assert that requests.get was called with the right arguments + mock_get.assert_called_once_with('https://data.source.coop/vida/google-microsoft-open-buildings/geoparquet/by_country/country_iso=MCO/MCO.parquet') + + # Check response + assert response == 200 + +def test_street_downloader(): + """Check streets are downloaded and a specific point in the graph.""" + bbox = (-0.17929,51.49638, -0.17383,51.49846) + + mock_graph = nx.MultiDiGraph() + # Mock ox.graph_from_bbox + with mock.patch.object(ox, 'graph_from_bbox', return_value=mock_graph): + # Call download_street + G = downloaders.download_street(bbox) + assert G == mock_graph + +def test_river_downloader(): + """Check rivers are downloaded and a specific point in the graph.""" + bbox = (0.0402, 51.55759, 0.09825591114207548, 51.6205) + + mock_graph = nx.MultiDiGraph() + # Mock ox.graph_from_bbox + with mock.patch.object(ox, 'graph_from_bbox', return_value=mock_graph): + # Call download_street + G = downloaders.download_river(bbox) + assert G == mock_graph + +def test_elevation_downloader(): + """Check elevation downloads, writes, contains data, and a known elevation.""" + # Please do not reuse api_key + test_api_key = 'b206e65629ac0e53d599e43438560d28' + + bbox = (-0.17929,51.49638, -0.17383,51.49846) + + with tempfile.TemporaryDirectory() as temp_dir: + temp_fid = Path(temp_dir) / 'temp.tif' + + mock_response = mock.Mock() + mock_response.status_code = 200 + mock_response.raw = io.BytesIO(b'25') + with mock.patch('requests.get', + return_value=mock_response) as mock_get: + # Call your function that uses requests.get + response = downloaders.download_elevation(temp_fid, + bbox, + test_api_key) + # Assert that requests.get was called with the right arguments + assert 'https://portal.opentopography.org/API/globaldem?demtype=NASADEM&south=51.49638&north=51.49846&west=-0.17929&east=-0.17383&outputFormat=GTiff&API_Key' in mock_get.call_args[0][0] # noqa: E501 + + # Check response + assert response == 200 + + # Check response + assert temp_fid.exists(), "Elevation data file not found after download." \ No newline at end of file From f441aaef051ec53d4c0162d8d123e07f96f64d24 Mon Sep 17 00:00:00 2001 From: barneydobson Date: Fri, 22 Mar 2024 11:07:18 +0000 Subject: [PATCH 4/6] Update geospatial_utilities.py fix example --- swmmanywhere/geospatial_utilities.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/swmmanywhere/geospatial_utilities.py b/swmmanywhere/geospatial_utilities.py index f5df9859..56a332b1 100644 --- a/swmmanywhere/geospatial_utilities.py +++ b/swmmanywhere/geospatial_utilities.py @@ -192,8 +192,9 @@ def get_transformer(source_crs: str, Example: >>> transformer = get_transformer('EPSG:4326', 'EPSG:32630') - >>> transformer.transform(-0.1276, 51.5074) - (699330.1106898375, 5710164.30300683) + >>> x, y = transformer.transform(-0.1276, 51.5074) + >>> print(f"{x:.6f}, {y:.6f}") + 699330.110690, 5710164.303007 """ return pyproj.Transformer.from_crs(source_crs, target_crs, From 2ff710a3ba13d51e7c390761fbc1a17bb9d076ec Mon Sep 17 00:00:00 2001 From: barneydobson Date: Fri, 22 Mar 2024 11:13:58 +0000 Subject: [PATCH 5/6] Use conftest rather addopts to run not downloads --- pyproject.toml | 2 +- tests/conftest.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/conftest.py diff --git a/pyproject.toml b/pyproject.toml index a70436d3..051b95fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,7 @@ module = "tests.*" disallow_untyped_defs = false [tool.pytest.ini_options] -addopts = "-v -p no:warnings --cov=swmmanywhere --cov-report=html --doctest-modules --ignore=swmmanywhere/__main__.py -m 'not downloads'" +addopts = "-v -p no:warnings --cov=swmmanywhere --cov-report=html --doctest-modules --ignore=swmmanywhere/__main__.py" [tool.ruff] select = ["D", "E", "F", "I"] # pydocstyle, pycodestyle, Pyflakes, isort diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..c523d703 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,4 @@ +def pytest_collection_modifyitems(config, items): + """Skip tests marked with downloads.""" + if not config.getoption('markexpr', 'False'): + config.option.markexpr = "not downloads" \ No newline at end of file From 5613991ee6035f4397c1f24c8551bcde8ee8f204 Mon Sep 17 00:00:00 2001 From: Dobson Date: Mon, 25 Mar 2024 09:18:59 +0000 Subject: [PATCH 6/6] Update test_prepare_data.py --- tests/test_prepare_data.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_prepare_data.py b/tests/test_prepare_data.py index 4aa791d6..084a0134 100644 --- a/tests/test_prepare_data.py +++ b/tests/test_prepare_data.py @@ -1,7 +1,10 @@ # -*- coding: utf-8 -*- -"""Created on Tue Oct 18 10:35:51 2022. +"""Test the prepare_data module. -@author: Barney +By default downloads themselves are mocked, but these can be enabled with the +following test command: + +pytest -m downloads """ import io