Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Nov 18, 2023
1 parent b7ce4ca commit e09067d
Show file tree
Hide file tree
Showing 7 changed files with 147,913 additions and 4 deletions.
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ install_requires =
typer >= 0.9.0
rich >= 13.6.0

[options.extras_require]
dev =
pytest >= 7.4.3

[options.package_data]
extras = *.fmf
* = README.md
Expand Down
7 changes: 7 additions & 0 deletions src/PyScoutFM/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Data:
"""
Load the config data and subsequent files
"""

def __init__(self, data):
self.data = data
8 changes: 4 additions & 4 deletions src/PyScoutFM/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def find_latest_file(self, path: str, extension: str) -> Optional[str]:
"""
Find the latest file in a given directory with a specific extension.
"""
files = glob.glob(os.path.join(os.path.expanduser(path), extension))
if files:
return max(files, key=os.path.getctime)
return None
files = glob.glob(os.path.join(os.path.expanduser(path)) + "/" + extension)
files.sort(key=os.path.getmtime)

return files[-1] if files else None
32 changes: 32 additions & 0 deletions tests/importer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import json
import os
from unittest.mock import mock_open, patch

import pytest

from PyScoutFM.importer import Importer


@pytest.fixture
def sample_config():
return {"ratings_path": "~/ratings.json"}


@pytest.fixture
def sample_ratings():
return {"rating1": 4.5, "rating2": 3.7}


def test_load_config_from_file(sample_config):
with patch(
"builtins.open", mock_open(read_data=json.dumps(sample_config))
) as mock_file:
importer = Importer("dummy_config_path.json")
mock_file.assert_called_once_with("dummy_config_path.json", "r")
assert importer.config == sample_config


def test_get_last_file():
importer = Importer("tests/stubs/config.json")
test_path = os.getcwd() + "/tests/stubs/inputs"
assert importer.find_latest_file(test_path, "*.html") == test_path + "/Squad.html"
20 changes: 20 additions & 0 deletions tests/stubs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"import_path": "~/Documents/input",
"export_path": "~/Documents/output",
"ratings_path": "ratings.json",
"ratings_set": "ykykyk_balanced",
"filter_values_below": 45,
"paginate": 30,
"output_columns": [
"Name",
"Age",
"Club",
"Transfer Value",
"Wage",
"1st Nat",
"Position",
"Personality",
"Left Foot",
"Right Foot"
]
}
Loading

0 comments on commit e09067d

Please sign in to comment.