From bd630f753156286b80b8671a6aa7454a28856ab5 Mon Sep 17 00:00:00 2001 From: ronilpatil Date: Fri, 15 Mar 2024 00:57:49 +0530 Subject: [PATCH] creating tox env for testing using pytest framework --- requirements-tox.txt | 18 +++++++++++++++++ tests/test_main.py | 44 ++++++++++++++++++++++++++++++++++++++++++ tests/trash/.gitignore | 0 tox.ini | 10 +++++++--- 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 requirements-tox.txt create mode 100644 tests/test_main.py create mode 100644 tests/trash/.gitignore diff --git a/requirements-tox.txt b/requirements-tox.txt new file mode 100644 index 0000000..2c77e61 --- /dev/null +++ b/requirements-tox.txt @@ -0,0 +1,18 @@ +# dependencies for tox environment +-e . + +fastapi==0.110.0 +hyperopt==0.2.7 +imbalanced_learn==0.12.0 +joblib==1.3.2 +matplotlib==3.8.3 +mlflow==2.11.1 +numpy==1.26.4 +pandas==2.2.1 +pydantic==2.6.4 +pytest==8.1.1 +PyYAML==6.0.1 +scikit_learn==1.4.1.post1 +setuptools==69.1.1 +streamlit==1.31.1 +uvicorn==0.28.0 diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..d62eca4 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,44 @@ +# data is properly loading from source or not +# check build_features working or not ---- done +# check model training is working fine or not and model return kr rha he ki nahi +# model tunning performance improve kr rha he ki nahi +# check whether visualization is working fine or not, or plot return kr rha he ki nahi +# check api working fine or not, response kya de rha he api glt or sahi input pr +# check streamlit working fine or not, + +import pathlib +import pytest +import yaml +from src.features.build_features import feat_eng +from src.data.make_dataset import load_data + +curr_dir = pathlib.Path(__file__) +home_dir = curr_dir.parent.parent + +params = yaml.safe_load(open(f"{home_dir.as_posix()}/params.yaml")) + +processed_data = params['make_dataset']['processed_data'] +data_source = f'{home_dir.as_posix()}{processed_data}/train.csv' + + +# 'request' is a fixture that provides information about the currently executing test. +# It allows us to access various attributes and methods to get information about the test +# environment, access fixtures, and more. +# here we are accessing current parameters value using request.param +@pytest.fixture(params = [data_source]) +def load(request) : + return feat_eng(load_data(request.param)) + +def test_build_features(load) : + assert load.shape[1] == 20 + + + +''' +tox.ini file initially khud se create karo or configure karo +but ek cheez ka dhyan de ki agr test_files kisi dir me hoto kese tox.ini me mention krna he +or khas baat requirements.txt dhyan se dena, local package bhi mention krna +bss fix requirements.txt reload kr k testing kran hoto +cmd: tox -r +else cmd: tox +''' diff --git a/tests/trash/.gitignore b/tests/trash/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini index c32fbd8..ff4a7c1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,3 +1,7 @@ -[flake8] -max-line-length = 79 -max-complexity = 10 +[tox] # global settings +envlist = py39 # define the list of environment to test against +skipsdist = True # skip creating package + +[testenv] +deps = -rrequirements-tox.txt # dependency +commands = pytest tests/ # testcases