From 912b3982ced5af232a508ad6387f1e3aa0789d41 Mon Sep 17 00:00:00 2001 From: Rashi Selarka Date: Thu, 11 Apr 2024 18:12:50 -0700 Subject: [PATCH] debugged pynyairbnb tests --- tests/test_pynyairbnb.py | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/tests/test_pynyairbnb.py b/tests/test_pynyairbnb.py index 338b84c..fb642d0 100644 --- a/tests/test_pynyairbnb.py +++ b/tests/test_pynyairbnb.py @@ -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): @@ -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) \ No newline at end of file + {}, 'test_report.csv') \ No newline at end of file