1+ import json
12import unittest
23from pathlib import Path
34from src .osw_incline import OSWIncline
45from src .osw_incline .logger import Logger
56from unittest .mock import patch , MagicMock
67from src .osw_incline .osm_graph import OSMGraph
8+ from src .utils import download_dems , unzip_dataset , remove_unzip_dataset
9+
10+ ASSETS_DIR = f'{ Path .cwd ()} /tests/assets'
11+ DEM_DIR = f'{ Path .cwd ()} /downloads/dems'
712
813
914class TestOSWIncline (unittest .TestCase ):
@@ -53,7 +58,8 @@ def test_calculate_success(self, mock_logger_info, mock_time, mock_dem_processor
5358 @patch ('src.osw_incline.dem_processor.DEMProcessor.process' , return_value = None )
5459 @patch ('time.time' , side_effect = [1 , 5 ]) # Simulate time taken for the calculation
5560 @patch .object (Logger , 'info' ) # Mock the Logger to capture log calls
56- def test_calculate_success_with_skip_existing_tags (self , mock_logger_info , mock_time , mock_dem_processor , mock_osm_graph ):
61+ def test_calculate_success_with_skip_existing_tags (self , mock_logger_info , mock_time , mock_dem_processor ,
62+ mock_osm_graph ):
5763 result = self .osw_incline .calculate (skip_existing_tags = True )
5864
5965 # Check if the process was successful
@@ -76,7 +82,7 @@ def test_calculate_success_with_skip_existing_tags(self, mock_logger_info, mock_
7682 @patch ('time.time' , side_effect = [1 , 5 ]) # Simulate time taken for the calculation
7783 @patch .object (Logger , 'info' ) # Mock the Logger to capture log calls
7884 def test_calculate_success_with_batch_processing (self , mock_logger_info , mock_time , mock_dem_processor ,
79- mock_osm_graph ):
85+ mock_osm_graph ):
8086 result = self .osw_incline .calculate (batch_processing = True )
8187
8288 # Check if the process was successful
@@ -98,8 +104,9 @@ def test_calculate_success_with_batch_processing(self, mock_logger_info, mock_ti
98104 @patch ('src.osw_incline.dem_processor.DEMProcessor.process' , return_value = None )
99105 @patch ('time.time' , side_effect = [1 , 5 ]) # Simulate time taken for the calculation
100106 @patch .object (Logger , 'info' ) # Mock the Logger to capture log calls
101- def test_calculate_success_with_batching_and_skip_existing_tags (self , mock_logger_info , mock_time , mock_dem_processor ,
102- mock_osm_graph ):
107+ def test_calculate_success_with_batching_and_skip_existing_tags (self , mock_logger_info , mock_time ,
108+ mock_dem_processor ,
109+ mock_osm_graph ):
103110 result = self .osw_incline .calculate (skip_existing_tags = True , batch_processing = True )
104111
105112 # Check if the process was successful
@@ -169,5 +176,49 @@ def test_debug_logging_on_initialization(self, mock_logger_debug):
169176 mock_logger_debug .assert_called_once_with ('Debug mode is enabled' )
170177
171178
179+ class TestOSWInclineIntegration (unittest .TestCase ):
180+ def setUp (self ):
181+ self .dem_files = [f'{ DEM_DIR } /n48w123.tif' ]
182+ # Download DEM file if not present
183+ download_dems ()
184+ # unzip medium.zip to the specified extraction path
185+ unzip_dataset ()
186+ self .extract_to = Path (f'{ ASSETS_DIR } /medium' )
187+ self .nodes_file = f'{ self .extract_to } /wa.seattle.graph.nodes.geojson'
188+ self .edges_file = f'{ self .extract_to } /wa.seattle.graph.edges.geojson'
189+
190+ def tearDown (self ):
191+ remove_unzip_dataset ()
192+
193+ def test_entire_process (self ):
194+ incline = OSWIncline (
195+ dem_files = self .dem_files ,
196+ nodes_file = str (self .nodes_file ),
197+ edges_file = str (self .edges_file ),
198+ debug = True
199+ )
200+ result = incline .calculate ()
201+ self .assertTrue (result )
202+
203+ def test_incline_tag_added (self ):
204+ incline = OSWIncline (
205+ dem_files = self .dem_files ,
206+ nodes_file = self .nodes_file ,
207+ edges_file = self .edges_file ,
208+ debug = True
209+ )
210+ result = incline .calculate ()
211+ self .assertTrue (result )
212+
213+ with open (self .edges_file , 'r' ) as f :
214+ edges_data = json .load (f )
215+
216+ for feature in edges_data ['features' ]:
217+ if 'incline' in feature ['properties' ]:
218+ incline_value = feature ['properties' ]['incline' ]
219+ self .assertIsInstance (incline_value , (int , float ), 'Incline should be an integer or float.' )
220+ self .assertTrue (- 1 <= incline_value <= 1 , 'Incline should be between -1 and 1.' )
221+
222+
172223if __name__ == '__main__' :
173224 unittest .main ()
0 commit comments