Skip to content

Commit

Permalink
start testing
Browse files Browse the repository at this point in the history
  • Loading branch information
elbeejay committed Mar 24, 2024
1 parent 65ca02f commit fb63f41
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8"]
python-version: ["3.8", "3.9", "3.10"]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: tests

on:
push:
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install .[dev]
- name: Test with pytest via coverage
run: |
coverage run -m pytest
coverage report -m
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies = [
]

[project.optional-dependencies]
dev = ["pre-commit", "pytest", "pytest-cov", "tomli", "GOStnets[docs,osm,opt]"]
dev = ["pre-commit", "pytest", "pytest-cov", "tomli", "coverage[toml]", "GOStnets[docs,osm,opt]"]
docs = [
"docutils==0.17.1",
"jupyter-book>=1,<2",
Expand Down
34 changes: 34 additions & 0 deletions tests/test_calculate_od_raw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from GOSTnets import calculate_od_raw
from unittest.mock import MagicMock


def test_calculateOD_csv(tmp_path):
"""Test the calculateOD_csv function."""
# Define inputs
G = None
# make test csv files
originCSV = tmp_path / "otest_points.csv"
originCSV.write_text("Lat,Lon\n0,0\n1,1\n2,2\n3,3\n4,4\n5,5\n6,6\n7,7\n8,8\n9,9\n")
destinationCSV = tmp_path / "dtest_points.csv"
destinationCSV.write_text(
"Lat,Lon\n0,0\n1,1\n2,2\n3,3\n4,4\n5,5\n6,6\n7,7\n8,8\n9,9\n"
)
fail_value = 999999
weight = "length"
calculate_snap = True
# mock the calculateOD_gdf function
calculate_od_raw.calculateOD_gdf = MagicMock(return_value=1)

# Run the function
result = calculate_od_raw.calculateOD_csv(
G,
originCSV,
destinationCSV=destinationCSV,
fail_value=fail_value,
weight=weight,
calculate_snap=calculate_snap,
)

# Check the result
assert result == 1
assert calculate_od_raw.calculateOD_gdf.call_count == 1

0 comments on commit fb63f41

Please sign in to comment.