Module Diabetes-Detection-Web-Application.testing.tests.unit_tests.test_data_loading

Expand source code

"""
Testing the file responsible for loading the file.
"""
#import global libraries
import pandas as pd
import pytest
#import local libraries
from src.preprocessing.dataloading import DataIngestion


def test_load_data():
    path = "https://raw.githubusercontent.com/ritik8801/Diabetes-Detection-Web-Application/main/Testing/tests/unit_tests/test_data/sample.csv"
    di = DataIngestion()
    df = di.load_data(path)
    assert isinstance(df, pd.DataFrame)

@pytest.mark.parametrize("path,expected", [("path1", "The data file does not exist"),
("incorrect path", "The data file does not exist"), ("xyz.abc", "The data file does not exist")])
def test_load_data_error(path, expected):
    with pytest.raises(FileNotFoundError) as F:
        df = DataIngestion().load_data(path)
        assert F.message == expected

Functions

def test_load_data()

Test the load_data Function

Expand source code
def test_load_data():
    path = "https://raw.githubusercontent.com/ritik8801/Diabetes-Detection-Web-Application/main/Testing/tests/unit_tests/test_data/sample.csv"
    di = DataIngestion()
    df = di.load_data(path)
    assert isinstance(df, pd.DataFrame)
def test_load_data_error(path, expected)

Test the test_load_data_error Function

Expand source code

@pytest.mark.parametrize("path,expected", [("path1", "The data file does not exist"),
("incorrect path", "The data file does not exist"), ("xyz.abc", "The data file does not exist")])
def test_load_data_error(path, expected):
    with pytest.raises(FileNotFoundError) as F:
        df = DataIngestion().load_data(path)
        assert F.message == expected