Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Unit Tests
on:
workflow_dispatch:
push:
branches-ignore:
- '**'
pull_request:
branches: [ main, develop ]

jobs:
UnitTest:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Updating and installing GDAL
run: |
sudo apt update
sudo apt install gdal-bin libgdal-dev python3-gdal

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install GDAL==3.4.1
pip install -r requirements.txt

- name: Determine output folder
id: set_output_folder
run: |
if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then
branch_name=$GITHUB_BASE_REF
else
branch_name=$GITHUB_REF_NAME
fi
if [[ $branch_name == "main" ]]; then
echo "output_folder=prod" >> $GITHUB_ENV
elif [[ $branch_name == "stage" ]]; then
echo "output_folder=stage" >> $GITHUB_ENV
elif [[ $branch_name == "develop" ]]; then
echo "output_folder=dev" >> $GITHUB_ENV
else
echo "Unknown branch: $branch_name"
exit 1
fi

- name: Run tests with coverage
run: |
timestamp=$(date '+%Y-%m-%d_%H-%M-%S')
mkdir -p test_results
log_file="test_results/${timestamp}_report.log"
echo -e "\nTest Cases Report Report\n" >> $log_file
# Run the tests and append output to the log file
python -m coverage run --source=src/osm_osw_reformatter -m unittest discover -v tests/unit_tests >> $log_file 2>&1
echo -e "\nCoverage Report\n" >> $log_file
coverage report >> $log_file

- name: Check coverage
run: |
coverage report --fail-under=85

- name: Upload report to Azure
uses: LanceMcCarthy/Action-AzureBlobUpload@v2
with:
source_folder: 'test_results'
destination_folder: '${{ env.output_folder }}'
connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
container_name: 'osm-osw-reformatter-package'
clean_destination_folder: false
delete_if_exists: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ cython_debug/
.idea/
reports/
output
test_results
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

### 0.2.6
- Added unit test cases
- Added unit test cases pipeline
- Added support to upload test cases results on Azure blob

### 0.2.5
- Fixes XML Parsing issue

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ folder.
coverage report // Can be run after 1st command
```


- After the commands are run, you can check the coverage report in `htmlcov/index.html`. Open the file in any browser,
and it shows complete coverage details
- The terminal will show the output of coverage like this
Expand Down
2 changes: 1 addition & 1 deletion src/osm_osw_reformatter/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.5'
__version__ = '0.2.6'
12 changes: 11 additions & 1 deletion tests/unit_tests/helpers/test_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from src.osm_osw_reformatter.serializer.osm.osm_graph import OSMGraph
from src.osm_osw_reformatter.serializer.counters import WayCounter, PointCounter, NodeCounter
from src.osm_osw_reformatter.helpers.osm import count_entities, get_osm_graph, osw_way_filter, osw_node_filter, \
osw_point_filter, simplify_og, construct_geometries
osw_point_filter, simplify_og, construct_geometries, osw_zone_filter, osw_polygon_filter

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEST_FILE = os.path.join(ROOT_DIR, 'test_files/wa.microsoft.osm.pbf')
Expand Down Expand Up @@ -88,6 +88,16 @@ async def run_test():

asyncio.run(run_test())

def test_osw_zone_filter(self):
tags = {'zone': 'residential'}
result = osw_zone_filter(tags)
self.assertTrue(isinstance(result, bool))

def test_osw_polygon_filter(self):
tags = {'polygon': 'yes'}
result = osw_polygon_filter(tags)
self.assertTrue(isinstance(result, bool))


if __name__ == '__main__':
unittest.main()
17 changes: 17 additions & 0 deletions tests/unit_tests/helpers/test_osw.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,20 @@ def test_cleanup_of_temp_files(self):
# Check if the temporary GeoJSON files have been removed
for filename in self.geojson_files.keys():
self.assertFalse(os.path.exists(filename))

def test_osw_zone_filter(self):
tags = {'zone': 'residential'}
result = OSWHelper.osw_zone_filter(tags)
self.assertTrue(isinstance(result, bool))
self.assertFalse(result)

def test_osw_polygon_filter(self):
tags = {'building': 'yes', 'type': 'multipolygon'}
result = OSWHelper.osw_polygon_filter(tags)
self.assertTrue(isinstance(result, bool))
self.assertTrue(result)



if __name__ == '__main__':
unittest.main()
17 changes: 17 additions & 0 deletions tests/unit_tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import asyncio
import unittest
from unittest.mock import patch
from src.osm_osw_reformatter import Formatter
from src.osm_osw_reformatter.helpers.response import Response

Expand Down Expand Up @@ -88,6 +89,22 @@ def test_cleanup_non_existent_files(self):
self.assertFalse(os.path.exists(f'{OUTPUT_DIR}/non_existent1.osm'))
self.assertFalse(os.path.exists(f'{OUTPUT_DIR}/non_existent2.osm'))

@patch("src.osm_osw_reformatter.OSW2OSM.convert")
def test_osw2osm_successful(self, mock_convert):
# Mock the response from OSW2OSM.convert
mock_response = Response(status=True, generated_files=['output.osm'])
mock_convert.return_value = mock_response

formatter = Formatter(file_path=self.osw_file_path, workdir=OUTPUT_DIR)
result = formatter.osw2osm()

# Assertions
mock_convert.assert_called_once()
self.assertTrue(result.status)
self.assertEqual(formatter.generated_files, [mock_response.generated_files])




if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tests/unit_tests/test_osm2osw/test_osm2osw.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_generated_3_files(self):
async def run_test():
osm2osw = OSM2OSW(osm_file=osm_file_path, workdir=OUTPUT_DIR, prefix='test')
result = await osm2osw.convert()
self.assertEqual(len(result.generated_files), 6)
self.assertEqual(len(result.generated_files), 4)
for file in result.generated_files:
os.remove(file)

Expand Down
Loading
Loading