Skip to content

Commit

Permalink
Merge pull request #15 from WD-Scott/updates_initial
Browse files Browse the repository at this point in the history
started creating test scripts and added makefile job to run them
  • Loading branch information
WD-Scott authored Aug 9, 2024
2 parents 2def838 + 99e1f13 commit 84dcec6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ build_exe: remove_pathlib
. env/bin/activate; pyinstaller -w -F -i "icon.icns" "Downloads_Cleaner.py"
@# Check if running on macOS and perform actions accordingly
@uname | grep -q 'Darwin' && mv dist/Downloads_Cleaner.app . && rm -rf build dist Downloads_Cleaner.spec || echo "Skipping macOS specific commands"

# Job to run tests
.PHONY: test
test:
pytest test_cleaner.py -vvx
54 changes: 54 additions & 0 deletions test_cleaner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'''
test_cleaner.py
===============
Author:
-------
Wyatt D. Scott ([email protected])
Last Updated:
-------------
09 August 2024
'''
import os
import logging
from os.path import exists, join, splitext
from shutil import move
import pytest
from cleaner import make_unique, config

dst = '/Downloads/'

test_cases = [
("tester(2).png", 'tester.png'),
("tester(2).py", 'tester.py'),
("tester(2).pdf", 'tester.pdf'),
("tester(2).mp4", 'tester.mp4'),
("tester(2).mp3", 'tester.mp3')
]

test_ids = [name for name, _ in test_cases]

def test_config():
'''
Tests the config setup in cleaner.py.
GIVEN the config dict
WHEN source dir is initialized
THEN ensure it ends with '/Downloads'
'''
cfg = config.get('source_dir')
dl = '/Downloads'
assert cfg[-10:] == dl, f"Source dir should end with {dl} but got {cfg}"


@pytest.mark.parametrize("new_name, original", test_cases, ids=test_ids)
def test_make_unique(new_name, original, counter=2):
'''
Tests the `make_unique` function from cleaner.py.
GIVEN a file name and destination
WHEN checking if a unique file name is generated
THEN ensure the name is unique and formatted correctly
'''
assert make_unique(dst, original, 2) == new_name

0 comments on commit 84dcec6

Please sign in to comment.