From 94327aa83037fcf1695e07ac6401356ee373e7e8 Mon Sep 17 00:00:00 2001 From: Manuel-Knepper Date: Fri, 6 Nov 2026 10:06:33 +0100 Subject: [PATCH] added tests for settings and parameter validation --- tests/test_utils.py | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 624bb38..708de47 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,14 +1,58 @@ import geopandas as gpd import pytest +import networkx as nx from networkx.utils.misc import graphs_equal from shapely.geometry import Point import fixbikenet as fbn -from fixbikenet.utils import * +from fixbikenet import constants, settings +from fixbikenet.utils import ( + _validate_parameters, + _validate_settings, + find_edges_to_drop, + weigh_edges, + find_contact_nodes, + find_potential_gaps, + find_actual_gaps, + rank_gaps_by_b, + assign_pbi_to_edges +) fbn.constants._ROUTING_PENALTY = {0: 5, 1: 1} fbn.constants._BETWEENNESS_RANDOM_NODES = 300 +def test_validate_parameters(): + with pytest.raises(TypeError): + _validate_parameters(city_query=7, min_gap_length=500, max_gap_length=1000, export_data=False, import_files={}) + with pytest.raises(TypeError): + _validate_parameters(city_query='Copenhagen Municipality', min_gap_length='test', max_gap_length=1000, export_data=False, import_files={}) + with pytest.raises(TypeError): + _validate_parameters(city_query='Copenhagen Municipality', min_gap_length=500, max_gap_length='test', + export_data=False, import_files={}) + with pytest.raises(TypeError): + _validate_parameters(city_query='Copenhagen Municipality', min_gap_length=500, max_gap_length=1000, + export_data='test', import_files={}) + with pytest.raises(TypeError): + _validate_parameters(city_query='Copenhagen Municipality', min_gap_length=500, max_gap_length=1000, + export_data=False, import_files=7) + with pytest.raises(FileNotFoundError): + _validate_parameters(city_query='Copenhagen Municipality', min_gap_length=500, max_gap_length=1000, + export_data=False, import_files={'city_boundary': 'test'}) + +def test_validate_settings(): + constants._CRS_CALCULATIONS = 7 + with pytest.raises(TypeError): + _validate_settings() + constants._CRS_CALCULATIONS = 'auto' + settings.export_file_format = 'test' + with pytest.raises(ValueError): + _validate_settings() + settings.export_file_format = 'gpkg' + settings.radius = 'test' + with pytest.raises(TypeError): + _validate_settings() + settings.radius = 2500 + @pytest.fixture def create_test_graph(): G = nx.MultiDiGraph()