Skip to content

Commit 5143719

Browse files
committed
including the tests now
1 parent b85c837 commit 5143719

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ API_keys/
22
Map_Data/
33
__pycache__/
44
ODOT*
5-
test*
65
working_on*
7-
process_single_date.py
6+
process_single_date.py
7+
8+
# Python build artifacts
9+
*.egg-info/
10+
build/
11+
dist/

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Tests package

tests/test_api.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import pytest
2+
import os
3+
from datetime import datetime, timedelta
4+
import pandas as pd
5+
from ritis_inrix_api import RITIS_Downloader, INRIX_Downloader
6+
7+
SAMPLE_SEGMENTS = [1236893704,1236860943]
8+
9+
def test_ritis_download():
10+
"""
11+
Test RITIS single download.
12+
"""
13+
# Clean up old test files
14+
if os.path.exists("tests/ritis_unit_test.parquet"):
15+
os.remove("tests/ritis_unit_test.parquet")
16+
17+
ritis_key = os.environ.get("RITIS_API_KEY")
18+
if not ritis_key:
19+
pytest.skip("RITIS_API_KEY not set")
20+
21+
downloader = RITIS_Downloader(
22+
api_key=ritis_key,
23+
segments=SAMPLE_SEGMENTS,
24+
download_path="tests",
25+
start_time='06:00:00',
26+
end_time='06:02:00',
27+
bin_size=1,
28+
verbose=2,
29+
verify=False
30+
)
31+
32+
# Use yesterday's date for testing
33+
start_date = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')
34+
end_date = (datetime.now()).strftime('%Y-%m-%d')
35+
36+
downloader.single_download(start_date, end_date, "ritis_unit_test")
37+
38+
# Check that the file was created
39+
assert os.path.exists("tests/ritis_unit_test.parquet")
40+
41+
# Check that the file is not empty
42+
df = pd.read_parquet("tests/ritis_unit_test.parquet")
43+
assert not df.empty
44+
45+
def test_inrix_download():
46+
"""
47+
Test INRIX speed data download.
48+
"""
49+
inrix_id = os.environ.get("INRIX_APP_ID")
50+
inrix_token = os.environ.get("INRIX_HASH_TOKEN")
51+
52+
if not inrix_id or not inrix_token:
53+
pytest.skip("INRIX_APP_ID or INRIX_HASH_TOKEN not set")
54+
55+
downloader = INRIX_Downloader(
56+
app_id=inrix_id,
57+
hash_token=inrix_token,
58+
segments=SAMPLE_SEGMENTS,
59+
verbose=2
60+
)
61+
62+
speed_data = downloader.get_speed_data()
63+
64+
assert isinstance(speed_data, pd.DataFrame)
65+
assert not speed_data.empty

0 commit comments

Comments
 (0)