Skip to content

Commit

Permalink
refactoring of tests continued
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkcode committed Mar 6, 2024
1 parent a8887c5 commit 0a28506
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tests/data/scripts/create_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pandas as pd, numpy as np
from typing import List
from src.data.scripts.utils import get_and_clean_csv
from tests.data.scripts.utils import get_file_path
from tests.data.scripts.utils import get_test_file_path

src_dir = 'src'
test_dir = 'tests'
Expand All @@ -12,7 +12,7 @@
property_test_cases = ['United Center', 'Crown Hall', 'Art Institute', 'Marie Curie']

def csv_rows() -> csv.reader:
csvfile = open(get_file_path(test_dir, test_input_file))
csvfile = open(get_test_file_path(test_dir, test_input_file))
return csv.reader(csvfile)

def get_test_sample(src_data: csv.reader, property_test_cases: List[str]) -> csv.writer:
Expand Down
16 changes: 9 additions & 7 deletions tests/data/scripts/unit/test_clean_all_years.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from src.data.scripts.utils import get_and_clean_csv
from src.data.scripts import clean_and_pare_down_data_all_years as clean, process_data as proc
from tests.data.scripts.utils import get_file_path
from tests.data.scripts.utils import get_test_file_path, get_src_file_path

src_dir = 'src'
test_dir = 'tests'
Expand All @@ -15,17 +15,19 @@

@pytest.fixture
def src_building_data() -> pd.DataFrame:
test_data_path = get_file_path(test_dir, test_input_file)
test_data_path = get_test_file_path(test_input_file)
assert os.path.exists(test_data_path)
return get_and_clean_csv(test_data_path)

@pytest.fixture
def csv_file() -> csv.reader:
csvfile = open(get_file_path(test_dir, test_input_file))
csvfile = open(get_test_file_path(test_input_file))
return csv.reader(csvfile)

def test_csv_file_is_readable(csv_file):
csv_file
def test_csv_file_has_some_data(csv_file):
first_line = csv_file.__next__()
assert first_line
assert len(first_line) > 0

@pytest.mark.parametrize("test_input", [
clean.string_cols,
Expand Down Expand Up @@ -77,13 +79,13 @@ def test_int_values_remain_the_same_as_origin(test_has_last_year_of_data):
assert np.all(df[clean.int_cols].dtypes == 'Int64')

def test_csv_is_produced(test_has_last_year_of_data):
out_file = get_file_path(test_dir, test_output_file)
out_file = get_test_file_path(test_output_file)
clean.output_to_csv(test_has_last_year_of_data, out_file)
assert os.path.exists(out_file)

@pytest.fixture
def process():
return clean.process(get_file_path(src_dir, src_input_file))
return clean.process(get_src_file_path(src_input_file))

def test_data_has_ranking_columns(process):
for col in proc.building_cols_to_rank:
Expand Down
9 changes: 7 additions & 2 deletions tests/data/scripts/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import os, pathlib

def get_file_path(dir: str, f: str):
def get_test_file_path(f: str):
curr_path = pathlib.Path(".")
path = curr_path.parent.absolute() / dir / "data" / "source"
path = curr_path.parent.absolute() / 'tests' / 'data' / 'source'
return os.path.join(path, f)

def get_src_file_path(f: str):
curr_path = pathlib.Path(".")
path = curr_path.parent.absolute() / 'src' / 'data' / 'source'
return os.path.join(path, f)

0 comments on commit 0a28506

Please sign in to comment.