Skip to content

Commit

Permalink
refactor: update module paths and tmp_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward-Jackson-ONS committed Feb 20, 2024
1 parent 4b844e0 commit b4e49e4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
26 changes: 9 additions & 17 deletions tests/aggregation/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import os
import pytest
import time
from bus_metrics.setup.ingest_static_data import StaticDataIngest
from bus_metrics.setup.ingest_realtime_data import RealtimeDataIngest
from bus_metrics.aggregation.build_schedules import Schedule_Builder
from src.bus_metrics.setup.ingest_static_data import StaticDataIngest
from src.bus_metrics.setup.ingest_realtime_data import RealtimeDataIngest
from src.bus_metrics.aggregation.build_schedules import Schedule_Builder
from datetime import datetime

stool = StaticDataIngest()
Expand Down Expand Up @@ -54,14 +54,9 @@ def test_gtfs_path(tmp_path_factory):
Path to the temporary folder which contains GTFS.
"""
gtfs_path = os.path.join(tmp_path_factory.getbasetemp(), "gtfs")

if not os.path.exists(gtfs_path):
# If it doesn't exist, create the folder
os.makedirs(gtfs_path)

# set download path
stool.zip_fp_root = os.path.join(gtfs_path)
gtfs_path = tmp_path_factory.mktemp("gtfs")
os.chdir(gtfs_path)
stool.zip_fp_root = gtfs_path

try:
stool.ingest_bus_timetable(region="north_east")
Expand All @@ -81,16 +76,13 @@ def test_real_path(tmp_path_factory):
Path to the temporary folder which contains GTFS.
"""
real_path = os.path.join(tmp_path_factory.getbasetemp(), "real")

if not os.path.exists(real_path):
# If it doesn't exist, create the folder
os.makedirs(real_path)
real_path = tmp_path_factory.mktemp("real")
os.chdir(real_path)

scriptStartTime = datetime.now()
scriptStartTimeUnix = time.mktime(scriptStartTime.timetuple())

while time.mktime(datetime.now().timetuple()) < scriptStartTimeUnix + 30:
while time.mktime(datetime.now().timetuple()) < scriptStartTimeUnix + 10:
try:
rtool.api_call()
fileTimeStamp = datetime.now().strftime("%Y%m%d-%H:%M:%S")
Expand Down
2 changes: 1 addition & 1 deletion tests/aggregation/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import pytest
from datetime import datetime
from bus_metrics.aggregation.preprocessing import unzip_GTFS
from src.bus_metrics.aggregation.preprocessing import unzip_GTFS

pytest_plugins = ["tests.aggregation.test_fixtures"]

Expand Down
2 changes: 1 addition & 1 deletion tests/setup/test_RealtimeDataIngest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from dotenv import load_dotenv
from bus_metrics.setup.ingest_realtime_data import RealtimeDataIngest
from src.bus_metrics.setup.ingest_realtime_data import RealtimeDataIngest
from google.transit import gtfs_realtime_pb2
from google.protobuf import text_format

Expand Down
5 changes: 3 additions & 2 deletions tests/setup/test_StaticDataIngest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for ingest_static_data module."""

import pytest
from bus_metrics.setup.ingest_static_data import StaticDataIngest
from src.bus_metrics.setup.ingest_static_data import StaticDataIngest
from datetime import datetime
import os

Expand All @@ -12,7 +12,8 @@ def test_ingest_bus_timetable_file_exists():
"""Simple test to check that data not overwritten."""
with pytest.raises(FileExistsError) as excinfo:
date = datetime.now().strftime("%Y%m%d")
open(f"tests/data/north_east_{date}.zip", "w")
with open(f"tests/data/north_east_{date}.zip", "w") as f:
f.write("")
tool.zip_fp_root = "tests/data"
tool.ingest_bus_timetable(region="north_east")
assert (
Expand Down

0 comments on commit b4e49e4

Please sign in to comment.