Skip to content

Commit

Permalink
Task 42, creating tests for SampleData GoodFile and BadFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Nargis Sultani committed Sep 27, 2023
1 parent bff77c6 commit 271c7fb
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/tests/test_sample_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pandas as pd

Check failure on line 1 in src/tests/test_sample_data.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

src/tests/test_sample_data.py:1:18: F401 `pandas` imported but unused
import pytest

from validator import main

Check failure on line 4 in src/tests/test_sample_data.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

src/tests/test_sample_data.py:4:23: F401 `validator.main` imported but unused
from validator.create_schemas import validate_phases
from validator.sample_data import read_bad_data, read_good_data


class TestValidatingSampleData:
valid_response = {"response": "No validations errors or warnings"}

def test_invalid_good_data_file(self):
failed_fpath = "./SBL_Validations_SampleData_GoodFile_03312023_1.csv"
with pytest.raises(Exception) as exc:
read_good_data(failed_fpath)
assert exc.type == FileNotFoundError

def test_invalid_bad_data_file(self):
failed_fpath = "./SBL_Validations_SampleData_BadFile_03312023_1.csv"
with pytest.raises(Exception) as exc:
read_bad_data(failed_fpath)
assert exc.type == FileNotFoundError

def test_run_validation_on_good_data_invalid_lei(self):
lei = "000TESTFIUIDDONOTUS1"
good_data_df = read_good_data()
validation_result = validate_phases(good_data_df, lei)

assert len(validation_result) == 1
assert validation_result[0] != self.valid_response

def test_run_validation_on_good_data_valid_lei(self):
lei = "000TESTFIUIDDONOTUSE"
good_data_df = read_good_data()
validation_result = validate_phases(good_data_df, lei)

assert len(validation_result) == 1
assert validation_result[0] == self.valid_response

def test_run_validation_on_bad_data_invalid_lei(self):
lei = "000TESTFIUIDDONOTUS1"
bad_data_df = read_bad_data()
validation_result = validate_phases(bad_data_df, lei)

print(validation_result)
assert len(validation_result) >= 1
assert validation_result[0] != self.valid_response

def test_run_validation_on_bad_data_valid_lei(self):
lei = "000TESTFIUIDDONOTUSE"
bad_data_df = read_bad_data()
# print(bad_data_df)
validation_result = validate_phases(bad_data_df, lei)

assert len(validation_result) >= 1
assert validation_result[0] != self.valid_response
40 changes: 40 additions & 0 deletions src/validator/sample_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import sys

import pandas as pd

from validator.create_schemas import validate_phases

Check failure on line 6 in src/validator/sample_data.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

src/validator/sample_data.py:6:38: F401 `validator.create_schemas.validate_phases` imported but unused

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # noqa: E402
sys.path.append(ROOT_DIR) # noqa: E402

GOOD_FILE_PATH = "./SBL_Validations_SampleData_GoodFile_03312023.csv"
BAD_FILE_PATH = "./SBL_Validations_SampleData_BadFile_03312023.csv"


def read_good_data(csv_path: str = GOOD_FILE_PATH):
"""reads SampleData GoodFile csv file and returns a dataframe.
Args:
csv_path (str, optional): _description_. Defaults to GOOD_FILE_PATH.
Returns:
dataframe : return csv rows as dataframe
"""

good_data_df = pd.read_csv(csv_path, dtype=str, na_filter=False)
return good_data_df


def read_bad_data(csv_path: str = BAD_FILE_PATH):
"""reads SampleData BadFile csv file and returns a dataframe.
Args:
csv_path (str, optional): _description_. Defaults to BAD_FILE_PATH.
Returns:
dataframe : return csv rows as dataframe
"""

bad_data_df = pd.read_csv(csv_path, dtype=str, na_filter=False)
return bad_data_df

0 comments on commit 271c7fb

Please sign in to comment.