Skip to content

Commit

Permalink
test added
Browse files Browse the repository at this point in the history
  • Loading branch information
tedoaba committed Oct 22, 2024
1 parent 1aa25fa commit f568b8d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,46 @@ jobs:
runs-on: windows-latest

steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3

# Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'

# Cache pip dependencies to speed up the build
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# Install dependencies
- name: Install dependencies
run: |
pip install -r requirements.txt
# Run linting with flake8 to ensure code quality
- name: Lint code
run: |
pip install flake8
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Run unit tests using pytest
- name: Run tests
run: |
pip install pytest pandas
pytest tests --maxfail=1 --disable-warnings
# Optionally, upload test results
- name: Upload test results (optional)
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: test-results.xml
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ mlflow
flask
click
flask_sqlalchemy
Flask-Migrate
Flask-Migrate
pytest
33 changes: 33 additions & 0 deletions tests/test_data_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import sys
import unittest
from unittest.mock import patch
import pandas as pd

sys.path.append(os.path.abspath('../src'))

from src.data_loader import load_data

class TestDataLoader(unittest.TestCase):

@patch('pandas.read_csv')
def test_load_data(self, mock_read_csv):
# Create a mock DataFrame to be returned by pandas.read_csv
mock_df = pd.DataFrame({
'column1': [1, 2, 3],
'column2': ['A', 'B', 'C']
})

# Set the mock to return this DataFrame
mock_read_csv.return_value = mock_df

# Call the load_data function
file_path = 'dummy/path/to/file.csv'
result = load_data(file_path)

# Assertions
mock_read_csv.assert_called_once_with(file_path) # Check that read_csv was called with the correct file path
pd.testing.assert_frame_equal(result, mock_df) # Check that the result is as expected

if __name__ == '__main__':
unittest.main()

0 comments on commit f568b8d

Please sign in to comment.