transit_calculator/tests/test_data.py

108 lines
2.6 KiB
Python

from fixtures.fixtures import *
good_data = [
[
{
"created_at": "2024-01-01 12:03:03",
"pick_at": "2024-01-10 09:00:00",
"from_lat": 55.751,
"from_lon": 37.618,
"to_lat": 52.139,
"to_lon": 104.21,
"weight": 20000,
"volume": 82
},
{
"created_at": "2024-01-01 12:03:03",
"pick_at": "2024-01-10 09:00:00",
"from_lat": 55.751,
"from_lon": 37.618,
"to_lat": 52.139,
"to_lon": 104.21,
"weight": 20000,
"volume": 82,
"car_type_id": 1
}
]
]
@pytest.mark.usefixtures("dataset")
@pytest.mark.parametrize("data", good_data)
def test_dataset_good(dataset, data):
dataset.create(data)
for X in dataset:
assert X.shape == (13,)
bad_data = [
{
"created_at": "1989-01-01 12:03:03",
"pick_at": "2024-01-10 09:00:00",
"from_lat": 55.751,
"from_lon": 37.618,
"to_lat": 52.139,
"to_lon": 104.21,
"weight": 20000,
"volume": 82
},
{
"created_at": "2024-01-01 12:03:03",
"pick_at": "2024-01-10 09:00:00",
"from_lat": 55.751,
"from_lon": 37.618,
"to_lat": 52.139,
"to_lon": 104.21,
"weight": 20000,
"volume": 82,
"car_type_id": 3
},
{
"created_at": "2024-01-01 12:03:03",
"pick_at": "2024-01-10 09:00:00",
"from_lat": 55.751,
"from_lon": 37.618,
"to_lat": 52.139,
"to_lon": 104.21,
"weight": 20000,
},
{
"created_at": "2024-01-01 12:03:03",
"pick_at": "2024-01-10",
"from_lat": 55.751,
"from_lon": 37.618,
"to_lat": 52.139,
"to_lon": 104.21,
"weight": 20000,
"volume": 82
},
{
"created_at": "2024-01-01 12:03:03",
"pick_at": "2024-01-10 09:00:00",
"from_lat": 55.751,
"from_lon": 37.618,
"to_lat": 52.139,
"to_lon": -3.1,
"weight": 20000,
"volume": 82
},
{
"created_at": "2024-01-01 12:03:03",
"pick_at": "2024-01-10 09:00:00",
"from_lat": 55.751,
"from_lon": 7.618,
"to_lat": 52.139,
"to_lon": 104.21,
"weight": 20000,
"volume": 82
},
]
@pytest.mark.usefixtures("dataset")
@pytest.mark.parametrize("data_elem", bad_data)
def test_dataset_bad(dataset, data_elem):
with pytest.raises(ValueError):
dataset.create([data_elem])