From 99e1f13fe8f09da2eab320102135de67a879e031 Mon Sep 17 00:00:00 2001 From: WD-Scott Date: Fri, 9 Aug 2024 16:47:52 -0400 Subject: [PATCH] started creating test scripts and added makefile job to run them --- makefile | 5 +++++ test_cleaner.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test_cleaner.py diff --git a/makefile b/makefile index b6acb4f..3082897 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/test_cleaner.py b/test_cleaner.py new file mode 100644 index 0000000..2aa35f4 --- /dev/null +++ b/test_cleaner.py @@ -0,0 +1,54 @@ +''' +test_cleaner.py +=============== + +Author: +------- +Wyatt D. Scott (wyatt.d.scott28@gmail.com) + +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