-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for parsing the input from JSON
- Loading branch information
1 parent
fe685c4
commit d8eae3b
Showing
11 changed files
with
332 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: python test | ||
on: [push] | ||
jobs: | ||
python-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: git clone | ||
uses: actions/checkout@v3 | ||
|
||
- name: set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: unit tests | ||
run: python -m unittest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"path": "." | ||
} | ||
], | ||
"settings": {} | ||
"folders": [ | ||
{ | ||
"path": "." | ||
} | ||
], | ||
"settings": { | ||
"python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "test*.py"], | ||
"python.testing.pytestEnabled": false, | ||
"python.testing.unittestEnabled": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
"""Schema (class) definitions for the entities in Nextroute.""" | ||
|
||
from .input import Defaults as Defaults | ||
from .input import DurationGroup as DurationGroup | ||
from .input import Input as Input | ||
from .location import Location as Location | ||
from .stop import AlternateStop as AlternateStop | ||
from .stop import Stop as Stop | ||
from .stop import StopDefaults as StopDefaults | ||
from .vehicle import InitialStop as InitialStop | ||
from .vehicle import Vehicle as Vehicle | ||
from .vehicle import VehicleDefaults as VehicleDefaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,263 @@ | ||
{ | ||
"defaults": { | ||
"vehicles": { | ||
"capacity": { | ||
"bunnies": 20, | ||
"rabbits": 10 | ||
}, | ||
"start_location": { | ||
"lat": 35.791729813680874, | ||
"lon": -78.7401685145487 | ||
}, | ||
"end_location": { | ||
"lat": 35.791729813680874, | ||
"lon": -78.7401685145487 | ||
}, | ||
"speed": 10 | ||
}, | ||
"stops": { | ||
"duration": 300, | ||
"quantity": { | ||
"bunnies": -1, | ||
"rabbits": -1 | ||
}, | ||
"unplanned_penalty": 200000, | ||
"target_arrival_time": "2023-01-01T10:00:00Z", | ||
"early_arrival_time_penalty": 1.5, | ||
"late_arrival_time_penalty": 1.5 | ||
} | ||
}, | ||
"stops": [ | ||
{ | ||
"id": "s1", | ||
"location": { | ||
"lon": -78.90919, | ||
"lat": 35.72389 | ||
}, | ||
"compatibility_attributes": ["premium"] | ||
}, | ||
{ | ||
"id": "s2", | ||
"location": { | ||
"lon": -78.813862, | ||
"lat": 35.75712 | ||
}, | ||
"compatibility_attributes": ["premium"] | ||
}, | ||
{ | ||
"id": "s3", | ||
"location": { | ||
"lon": -78.92996, | ||
"lat": 35.932795 | ||
}, | ||
"compatibility_attributes": ["premium"] | ||
}, | ||
{ | ||
"id": "s4", | ||
"location": { | ||
"lon": -78.505745, | ||
"lat": 35.77772 | ||
}, | ||
"compatibility_attributes": ["premium"] | ||
}, | ||
{ | ||
"id": "s5", | ||
"location": { | ||
"lon": -78.75084, | ||
"lat": 35.732995 | ||
}, | ||
"compatibility_attributes": ["premium"] | ||
}, | ||
{ | ||
"id": "s6", | ||
"location": { | ||
"lon": -78.788025, | ||
"lat": 35.813025 | ||
}, | ||
"compatibility_attributes": ["premium"] | ||
}, | ||
{ | ||
"id": "s7", | ||
"location": { | ||
"lon": -78.749391, | ||
"lat": 35.74261 | ||
}, | ||
"compatibility_attributes": ["premium"] | ||
}, | ||
{ | ||
"id": "s8", | ||
"location": { | ||
"lon": -78.94658, | ||
"lat": 36.039135 | ||
}, | ||
"compatibility_attributes": ["basic"] | ||
}, | ||
{ | ||
"id": "s9", | ||
"location": { | ||
"lon": -78.64972, | ||
"lat": 35.64796 | ||
}, | ||
"compatibility_attributes": ["basic"] | ||
}, | ||
{ | ||
"id": "s10", | ||
"location": { | ||
"lon": -78.747955, | ||
"lat": 35.672955 | ||
}, | ||
"compatibility_attributes": ["basic"] | ||
}, | ||
{ | ||
"id": "s11", | ||
"location": { | ||
"lon": -78.83403, | ||
"lat": 35.77013 | ||
}, | ||
"compatibility_attributes": ["basic"] | ||
}, | ||
{ | ||
"id": "s12", | ||
"location": { | ||
"lon": -78.864465, | ||
"lat": 35.782855 | ||
}, | ||
"compatibility_attributes": ["basic"] | ||
}, | ||
{ | ||
"id": "s13", | ||
"location": { | ||
"lon": -78.952142, | ||
"lat": 35.88029 | ||
}, | ||
"compatibility_attributes": ["basic"] | ||
}, | ||
{ | ||
"id": "s14", | ||
"location": { | ||
"lon": -78.52748, | ||
"lat": 35.961465 | ||
}, | ||
"compatibility_attributes": ["basic"] | ||
}, | ||
{ | ||
"id": "s15", | ||
"location": { | ||
"lon": -78.89832, | ||
"lat": 35.83202 | ||
} | ||
}, | ||
{ | ||
"id": "s16", | ||
"location": { | ||
"lon": -78.63216, | ||
"lat": 35.83458 | ||
} | ||
}, | ||
{ | ||
"id": "s17", | ||
"location": { | ||
"lon": -78.76063, | ||
"lat": 35.67337 | ||
} | ||
}, | ||
{ | ||
"id": "s18", | ||
"location": { | ||
"lon": -78.911485, | ||
"lat": 36.009015 | ||
} | ||
}, | ||
{ | ||
"id": "s19", | ||
"location": { | ||
"lon": -78.522705, | ||
"lat": 35.93663 | ||
} | ||
}, | ||
{ | ||
"id": "s20", | ||
"location": { | ||
"lon": -78.995162, | ||
"lat": 35.97414 | ||
} | ||
}, | ||
{ | ||
"id": "s21", | ||
"location": { | ||
"lon": -78.50509, | ||
"lat": 35.7606 | ||
} | ||
}, | ||
{ | ||
"id": "s22", | ||
"location": { | ||
"lon": -78.828547, | ||
"lat": 35.962635 | ||
}, | ||
"precedes": ["s16", "s23"] | ||
}, | ||
{ | ||
"id": "s23", | ||
"location": { | ||
"lon": -78.60914, | ||
"lat": 35.84616 | ||
}, | ||
"start_time_window": [ | ||
"2023-01-01T09:00:00-06:00", | ||
"2023-01-01T09:30:00-06:00" | ||
] | ||
}, | ||
{ | ||
"id": "s24", | ||
"location": { | ||
"lon": -78.65521, | ||
"lat": 35.740605 | ||
}, | ||
"start_time_window": [ | ||
"2023-01-01T09:00:00-06:00", | ||
"2023-01-01T09:30:00-06:00" | ||
], | ||
"succeeds": "s25" | ||
}, | ||
{ | ||
"id": "s25", | ||
"location": { | ||
"lon": -78.92051, | ||
"lat": 35.887575 | ||
}, | ||
"start_time_window": [ | ||
"2023-01-01T09:00:00-06:00", | ||
"2023-01-01T09:30:00-06:00" | ||
], | ||
"precedes": "s26" | ||
}, | ||
{ | ||
"id": "s26", | ||
"location": { | ||
"lon": -78.84058, | ||
"lat": 35.823865 | ||
}, | ||
"start_time_window": [ | ||
"2023-01-01T09:00:00-06:00", | ||
"2023-01-01T09:30:00-06:00" | ||
] | ||
} | ||
], | ||
"vehicles": [ | ||
{ | ||
"id": "vehicle-0", | ||
"start_time": "2023-01-01T06:00:00-06:00", | ||
"end_time": "2023-01-01T10:00:00-06:00", | ||
"activation_penalty": 4000, | ||
"compatibility_attributes": ["premium"] | ||
}, | ||
{ | ||
"id": "vehicle-1", | ||
"start_time": "2023-01-01T10:00:00-06:00", | ||
"end_time": "2023-01-01T16:00:00-06:00", | ||
"max_duration": 21000, | ||
"compatibility_attributes": ["basic"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import json | ||
import os | ||
import unittest | ||
|
||
from nextmv.nextroute.schema import Input | ||
|
||
|
||
class TestInput(unittest.TestCase): | ||
def test_from_json(self): | ||
filepath = os.path.join(os.path.dirname(__file__), "input.json") | ||
input = Input.from_json(filepath) | ||
parsed = input.to_dict() | ||
with open(filepath) as f: | ||
expected = json.load(f) | ||
|
||
self.maxDiff = None | ||
self.assertEqual( | ||
parsed, | ||
expected, | ||
"Parsing the JSON into the class and back should yield the same result.", | ||
) |
This file was deleted.
Oops, something went wrong.