From 490be29faa7739fa9482cfdb6c83ff64ae8c3916 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Mon, 7 Feb 2022 18:48:26 +0100 Subject: [PATCH] Made it like an app --- setup.cfg | 1 + src/criteriaSorter/__main__.py | 8 +++ .../{ => modules}/criteriaSorter.py | 6 +-- tests/modules/test_fileops.py | 49 +++++++++++++++++++ tests/test_fileops.py | 14 ------ 5 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 src/criteriaSorter/__main__.py rename src/criteriaSorter/{ => modules}/criteriaSorter.py (98%) create mode 100644 tests/modules/test_fileops.py delete mode 100644 tests/test_fileops.py diff --git a/setup.cfg b/setup.cfg index 1be7750..a9980ce 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,6 +17,7 @@ classifiers = packages = criteriaSorter criteriaSorter.modules +; criteriaSorter.criteriaSorter install_requires = pyyaml>=6.0 python_requires = >=3.6 diff --git a/src/criteriaSorter/__main__.py b/src/criteriaSorter/__main__.py new file mode 100644 index 0000000..7e32d44 --- /dev/null +++ b/src/criteriaSorter/__main__.py @@ -0,0 +1,8 @@ +from criteriaSorter.modules import criteriaSorter +import sys + + +# pragma: nocover # The main call can't be covered because it will only execute through the CLI +if __name__ == "__main__": + criteriaSorter.main(sys.argv) + sys.exit(0) \ No newline at end of file diff --git a/src/criteriaSorter/criteriaSorter.py b/src/criteriaSorter/modules/criteriaSorter.py similarity index 98% rename from src/criteriaSorter/criteriaSorter.py rename to src/criteriaSorter/modules/criteriaSorter.py index 7804e67..43262c1 100644 --- a/src/criteriaSorter/criteriaSorter.py +++ b/src/criteriaSorter/modules/criteriaSorter.py @@ -7,7 +7,7 @@ import os import time import rich from rich.logging import RichHandler -from fileops import DirectoryHandler, FileHandler, ArtistHandler +from criteriaSorter.modules.fileops import DirectoryHandler, FileHandler, ArtistHandler def action_sort(argsp): @@ -191,6 +191,7 @@ def parse_args(argvp): args = parser.parse_args() return args + def main(argvp): """ Main function @@ -205,6 +206,3 @@ def main(argvp): # Execute the action _LIST_ACTIONS[args.action](args) - -if __name__ == '__main__': - main(sys.argv) diff --git a/tests/modules/test_fileops.py b/tests/modules/test_fileops.py new file mode 100644 index 0000000..9d4291a --- /dev/null +++ b/tests/modules/test_fileops.py @@ -0,0 +1,49 @@ +# Test file for fileops.py +from criteriaSorter.modules import fileops + + +def _mock_get_file_list(dir_path): + # Mock function for testing + return ["file1", "file2", "file3"] + + +def _mock_get_file_list_with_size(dir_path): + # Mock function for testing + return [("file1", 1), ("file2", 2), ("file3", 3)] + + +def test_DirectoryHandler(): + # Regular invocation + handler = fileops.DirectoryHandler(".") + + # Test regular calls, doen't test the return value + handler.get_dir_path() + handler.get_dir_name() + handler.get_dir_size() + handler.get_dir_size_in_mb() + handler.get_dir_size_in_gb() + [f for f in handler.get_files()] + [f for f in handler.get_directories()] + handler.get_file_list_with_size() + + # Using a mock function to test return value + handler = fileops.DirectoryHandler("/Test/Path") + handler.get_file_list=_mock_get_file_list + handler.get_file_list_with_size=_mock_get_file_list_with_size + + # Test return values + assert handler.get_dir_path() == "/Test/Path" + assert handler.get_dir_name() == "Path" + assert handler.get_dir_size() == 6 + assert handler.get_dir_size_in_mb() == 0.06 + assert handler.get_dir_size_in_gb() == 0.00006 + assert handler.get_files() == ["file1", "file2", "file3"] + + + +# def test_FileHandler(): +# handler = fileops.FileHandler(".") +# +# +# def test_ArticleHandler(): +# handler = fileops.ArtistHandler(".") diff --git a/tests/test_fileops.py b/tests/test_fileops.py deleted file mode 100644 index e8a666b..0000000 --- a/tests/test_fileops.py +++ /dev/null @@ -1,14 +0,0 @@ -# Test file for fileops.py -from criteriaSorter.modules import fileops - - -def test_DirectoryHandler(): - handler = fileops.DirectoryHandler(".") - - -def test_FileHandler(): - handler = fileops.FileHandler(".") - - -def test_ArticleHandler(): - handler = fileops.ArtistHandler(".")