Skip to content

Commit

Permalink
debugged pynyairbnb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rashiselarka committed Apr 12, 2024
1 parent 73c5d80 commit 912b398
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions tests/test_pynyairbnb.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ def test_build_clf_model():

def test_clf_model_inputs():
"""_summary_
Ensures that running the build_clf function function with the incorrect inputs leads to an error
Ensures that running the build_clf function function with the incorrect inputs leads to a type error
"""
with pytest.raises(ValueError):
with pytest.raises(TypeError):
clf_model = build_clf_model("faulty_value", "faulty_input", "faulty_input", X_train, y_train, X_test, y_test, "test", "test_name")

def test_empty_datasets():
"""_summary_
Ensures that if model is run with empty data sets run an error
Ensures that if model is run with empty data sets, it raises a value error
"""
with TemporaryDirectory() as temp_dir:
with pytest.raises(ValueError):
Expand All @@ -120,47 +120,34 @@ def test_empty_datasets():

def test_invalid_data_types():
"""_summary_
Tests that model runs error if invalid datatypes are entered
Tests that model runs into value error if invalid datatypes are entered
"""
with TemporaryDirectory() as temp_dir:
with pytest.raises(TypeError):
with pytest.raises(ValueError):
build_clf_model(KNeighborsClassifier(), StandardScaler(), temp_dir,
[0, 1], [0, 1], [1, 0], [1, 0],
{}, 'test_report.csv')

def test_data_with_missing_values():
"""_summary_
Ensures function can work despite missing values
Ensures function raises value error for missing values
"""
X_train = pd.DataFrame({'feature1': [np.nan, 1], 'feature2': [1, 0]})
y_train = pd.Series([0, 1])
X_test = pd.DataFrame({'feature1': [1, 0], 'feature2': [0, 1]})
y_test = pd.Series([1, 0])
with TemporaryDirectory() as temp_dir:
# Assuming the function should handle NaNs, replace assert with appropriate logic
build_clf_model(KNeighborsClassifier(), StandardScaler(), temp_dir,
X_train, y_train, X_test, y_test,
{}, 'test_report.csv')
with pytest.raises(ValueError):
build_clf_model(KNeighborsClassifier(), StandardScaler(), temp_dir,
X_train, y_train, X_test, y_test,
{}, 'test_report.csv')

def test_invalid_path():
"""_summary_
Ensures file not found error is raised if an invalid file path is input
Ensures value error is raised if an invalid file path is input
"""
with pytest.raises(FileNotFoundError):
with pytest.raises(ValueError):
build_clf_model(KNeighborsClassifier(), StandardScaler(), '/invalid/path',
pd.DataFrame({'feature1': [0, 1], 'feature2': [1, 0]}), pd.Series([0, 1]),
pd.DataFrame({'feature1': [1, 0], 'feature2': [0, 1]}), pd.Series([1, 0]),
{}, 'test_report.csv')



def test_empty_replacement_dict():
"""_summary_
Tests that empty dictionary does not create an error
"""
with TemporaryDirectory() as temp_dir:
model = build_clf_model(KNeighborsClassifier(), StandardScaler(), temp_dir,
pd.DataFrame({'feature1': [0, 1], 'feature2': [1, 0]}), pd.Series([0, 1]),
pd.DataFrame({'feature1': [1, 0], 'feature2': [0, 1]}), pd.Series([1, 0]),
{}, 'test_report.csv')
assert isinstance(model, KNeighborsClassifier)
{}, 'test_report.csv')

0 comments on commit 912b398

Please # to comment.