Skip to content

Commit 8ae07b4

Browse files
committed
Fixes tests after moving run to Ubuntu
1 parent 6e8988d commit 8ae07b4

17 files changed

+203
-84
lines changed

poetry.lock

+47-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mlxtend = "^0.23.1"
2020

2121
[tool.poetry.group.dev.dependencies]
2222
nbstripout = "^0.7.1"
23+
pytest = "^8.3.3"
2324

2425
[build-system]
2526
requires = ["poetry-core"]

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool:pytest]
2+
pythonpath = src

src/notebooks/freecodecamp/helper_functions.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
If a function gets defined once and could be used over and over, it'll go in here.
55
"""
6+
import torchvision
7+
from typing import List
68
import torch
79
import matplotlib.pyplot as plt
810
import numpy as np
@@ -18,7 +20,7 @@
1820

1921
# Walk through an image classification directory and find out how many files (images)
2022
# are in each subdirectory.
21-
import os
23+
2224

2325
def walk_through_dir(dir_path):
2426
"""
@@ -35,6 +37,7 @@ def walk_through_dir(dir_path):
3537
for dirpath, dirnames, filenames in os.walk(dir_path):
3638
print(f"There are {len(dirnames)} directories and {len(filenames)} images in '{dirpath}'.")
3739

40+
3841
def plot_decision_boundary(model: torch.nn.Module, X: torch.Tensor, y: torch.Tensor):
3942
"""Plots decision boundaries of model predicting on X in comparison to y.
4043
@@ -166,8 +169,6 @@ def plot_loss_curves(results):
166169

167170
# Pred and plot image function from notebook 04
168171
# See creation: https://www.learnpytorch.io/04_pytorch_custom_datasets/#113-putting-custom-image-prediction-together-building-a-function
169-
from typing import List
170-
import torchvision
171172

172173

173174
def pred_and_plot_image(
@@ -185,7 +186,7 @@ def pred_and_plot_image(
185186
class_names (List[str], optional): different class names for target image. Defaults to None.
186187
transform (_type_, optional): transform of target image. Defaults to None.
187188
device (torch.device, optional): target device to compute on. Defaults to "cuda" if torch.cuda.is_available() else "cpu".
188-
189+
189190
Returns:
190191
Matplotlib plot of target image and model prediction as title.
191192
@@ -236,7 +237,8 @@ def pred_and_plot_image(
236237
plt.title(title)
237238
plt.axis(False)
238239

239-
def set_seeds(seed: int=42):
240+
241+
def set_seeds(seed: int = 42):
240242
"""Sets random sets for torch operations.
241243
242244
Args:
@@ -247,7 +249,8 @@ def set_seeds(seed: int=42):
247249
# Set the seed for CUDA torch operations (ones that happen on the GPU)
248250
torch.cuda.manual_seed(seed)
249251

250-
def download_data(source: str,
252+
253+
def download_data(source: str,
251254
destination: str,
252255
remove_source: bool = True) -> Path:
253256
"""Downloads a zipped dataset from source and unzips to destination.
@@ -256,10 +259,10 @@ def download_data(source: str,
256259
source (str): A link to a zipped file containing data.
257260
destination (str): A target directory to unzip data to.
258261
remove_source (bool): Whether to remove the source after downloading and extracting.
259-
262+
260263
Returns:
261264
pathlib.Path to downloaded data.
262-
265+
263266
Example usage:
264267
download_data(source="https://github.com/mrdbourke/pytorch-deep-learning/raw/main/data/pizza_steak_sushi.zip",
265268
destination="pizza_steak_sushi")
@@ -268,13 +271,13 @@ def download_data(source: str,
268271
data_path = Path("data/")
269272
image_path = data_path / destination
270273

271-
# If the image folder doesn't exist, download it and prepare it...
274+
# If the image folder doesn't exist, download it and prepare it...
272275
if image_path.is_dir():
273276
print(f"[INFO] {image_path} directory exists, skipping download.")
274277
else:
275278
print(f"[INFO] Did not find {image_path} directory, creating one...")
276279
image_path.mkdir(parents=True, exist_ok=True)
277-
280+
278281
# Download pizza, steak, sushi data
279282
target_file = Path(source).name
280283
with open(data_path / target_file, "wb") as f:
@@ -284,11 +287,11 @@ def download_data(source: str,
284287

285288
# Unzip pizza, steak, sushi data
286289
with zipfile.ZipFile(data_path / target_file, "r") as zip_ref:
287-
print(f"[INFO] Unzipping {target_file} data...")
290+
print(f"[INFO] Unzipping {target_file} data...")
288291
zip_ref.extractall(image_path)
289292

290293
# Remove .zip file
291294
if remove_source:
292295
os.remove(data_path / target_file)
293-
296+
294297
return image_path

src/notebooks/stock_up_down/multiple_classes.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
"source": [
204204
"\n",
205205
"\n",
206-
"from src.classificators.proportions_calc import calculate_proportions\n",
206+
"from classificators.proportions_calc import calculate_proportions\n",
207207
"\n",
208208
"\n",
209209
"proportions= calculate_proportions(close_list, windows_rolling_avg)\n"

src/pytest.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pytest.ini
22
[pytest]
3+
pythonpath = .
34
minversion = 6.0
45
addopts = -ra -q
56
testpaths =

src/settings.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# File config.json added to Keepass entry for Tiingo
2-
import os
32
import json
43

54
from utils.file_utils import get_project_root

src/tests/__init__.py

Whitespace-only changes.

src/tests/conftest.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
import os
3+
4+
# Add the project root to the Python path
5+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../')))

src/tests/data_sources/test_tiingo_repo.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import List
21
import pytest
32
from unittest import mock
3+
4+
from typing import List
45
import pandas as pd
56
from datetime import datetime, timedelta
67

7-
# import src.tests.context
8-
from src.data_sources import tiingo_repo as tr
8+
from data_sources import tiingo_repo as tr
99

1010
DAYS_DOWNLOAD = 30
1111

src/tests/test_ewa_classifier.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import unittest
21
import pytest
32

4-
from math import nan, isclose
3+
from math import isclose
54

6-
# import context
7-
from src.classifiers import ewa_classifier as ec
5+
from classifiers import ewa_classifier as ec
86

97

108
def test_ewa_classifier_when_window_less_than_2_raises_exception():

src/tests/test_tiingo_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from datetime import datetime
55

66
import requests
7-
from src.apis.tiingo_api import TiingoAPI
7+
from apis.tiingo_api import TiingoAPI
88

99

1010
class TestTiingoAPI(unittest.TestCase):

0 commit comments

Comments
 (0)