Skip to content

Commit

Permalink
Adding initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-George-T committed Oct 18, 2023
1 parent c51697e commit cdf8fc2
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[![Pytest](https://github.com/Thomas-George-T/Ecommerce-Data-MLOps/actions/workflows/pytest.yml/badge.svg)](https://github.com/Thomas-George-T/Ecommerce-Data-MLOps/actions/workflows/pytest.yml)


# MLOps-Ecomm
Work in Progress
Binary file added data/Online Retail.xlsx
Binary file not shown.
Binary file added data/data.zip
Binary file not shown.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ numpy
pandas
pytest
ipykernel
mlflow
mlflow
requests
zipfile
Binary file added src/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added src/__pycache__/datapipeline.cpython-310.pyc
Binary file not shown.
34 changes: 34 additions & 0 deletions src/datapipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import requests
import zipfile

def ingest_data():

file_url = "https://archive.ics.uci.edu/static/public/352/online+retail.zip"

# Send an HTTP GET request to the URL
response = requests.get(file_url)

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Save file to data
with open("data/data.zip", "wb") as file:
file.write(response.content)
print("File downloaded successfully.")
else:
print(f"Failed to download the file. Status code: {response.status_code}")


def unzip_file():
zip_filename ='data/data.zip'
extract_to = 'data/'
try:
with zipfile.ZipFile(zip_filename, 'r') as zip_ref:
zip_ref.extractall(extract_to)
print(f"File {zip_filename} successfully unzipped to {extract_to}")
except Exception as e:
print(f"Failed to unzip {zip_filename}: {e}")


if __name__ == "__main__":
ingest_data()
unzip_file()
Binary file added test/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file not shown.
32 changes: 32 additions & 0 deletions test/test_datapipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import requests
import pytest
from src import datapipeline

def test_ingest_data(mocker):
# arrange:
# mocked dependencies
mock_print = mocker.MagicMock(name='print')
mocker.patch('src.datapipeline.print', new=mock_print)

# act: invoking the tested code
datapipeline.ingest_data()

# assert:
assert 1 == mock_print.call_count


def test_unzip_file(mocker):
# arrange:
# mocked dependencies
mock_ZipFile = mocker.MagicMock(name='ZipFile')
mocker.patch('src.datapipeline.zipfile.ZipFile', new=mock_ZipFile)
mock_print = mocker.MagicMock(name='print')
mocker.patch('src.datapipeline.print', new=mock_print)
mock_Exception = mocker.MagicMock(name='Exception')
mocker.patch('src.datapipeline.Exception', new=mock_Exception)

# act: invoking the tested code
datapipeline.unzip_file()

# assert:
mock_Exception.assert_not_called()

0 comments on commit cdf8fc2

Please sign in to comment.