From 9a782d17b7c1a641abc19e554b6eea574ff16e8a Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:11:40 -0500 Subject: [PATCH] =?UTF-8?q?[cdd/tests/test=5Fcompound/test=5Fexmod.py]=20R?= =?UTF-8?q?eplace=20custom=20`normalise=5Fdouble=5Fpaths`=20with=20`os.pat?= =?UTF-8?q?h.normcase`=20;=20[cdd/compound/exmod.py]=20No=20longer=20`=5F?= =?UTF-8?q?=5Frepr=5F=5F`=20the=20dry-run=20output=E2=80=A6=20just=20`path?= =?UTF-8?q?.normcase`=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cdd/__init__.py | 2 +- cdd/compound/exmod.py | 8 ++- cdd/compound/exmod_utils.py | 11 +-- cdd/tests/test_compound/test_exmod.py | 96 +++++++++++++-------------- 4 files changed, 60 insertions(+), 57 deletions(-) diff --git a/cdd/__init__.py b/cdd/__init__.py index 7d0c3d57..d821bbb0 100644 --- a/cdd/__init__.py +++ b/cdd/__init__.py @@ -9,7 +9,7 @@ from logging import getLogger as get_logger __author__ = "Samuel Marks" # type: str -__version__ = "0.0.99rc20" # type: str +__version__ = "0.0.99rc21" # type: str __description__ = ( "Open API to/fro routes, models, and tests. " "Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy." diff --git a/cdd/compound/exmod.py b/cdd/compound/exmod.py index 9c05fa60..13bf39fb 100644 --- a/cdd/compound/exmod.py +++ b/cdd/compound/exmod.py @@ -108,7 +108,9 @@ def exmod( ) elif dry_run: print( - "mkdir\t{output_directory!r}".format(output_directory=output_directory), + "mkdir\t'{output_directory}'".format( + output_directory=path.normcase(output_directory) + ), file=cdd.compound.exmod_utils.EXMOD_OUT_STREAM, ) elif not path.isdir(output_directory): @@ -405,7 +407,9 @@ def exmod_single_folder( ) if dry_run: print( - "write\t{init_filepath!r}".format(init_filepath=init_filepath), + "write\t'{init_filepath}'".format( + init_filepath=path.normcase(init_filepath) + ), file=cdd.compound.exmod_utils.EXMOD_OUT_STREAM, ) else: diff --git a/cdd/compound/exmod_utils.py b/cdd/compound/exmod_utils.py index bcb550a3..8a6999d9 100644 --- a/cdd/compound/exmod_utils.py +++ b/cdd/compound/exmod_utils.py @@ -266,7 +266,8 @@ def emit_file_on_hierarchy( if not path.isdir(mod_path): if dry_run: print( - "mkdir\t{mod_path!r}".format(mod_path=mod_path), file=EXMOD_OUT_STREAM + "mkdir\t'{mod_path}'".format(mod_path=path.normcase(mod_path)), + file=EXMOD_OUT_STREAM, ) else: makedirs(mod_path) @@ -274,7 +275,9 @@ def emit_file_on_hierarchy( init_filepath: str = path.join(path.dirname(mod_path), INIT_FILENAME) if dry_run: print( - "touch\t{init_filepath!r}".format(init_filepath=init_filepath), + "touch\t'{init_filepath}'".format( + init_filepath=path.normcase(init_filepath) + ), file=EXMOD_OUT_STREAM, ) else: @@ -327,8 +330,8 @@ def emit_file_on_hierarchy( if not path.isdir(emit_filename_dir): ( print( - "mkdir\t{emit_filename_dir!r}".format( - emit_filename_dir=emit_filename_dir + "mkdir\t'{emit_filename_dir}'".format( + emit_filename_dir=path.normcase(emit_filename_dir) ), file=EXMOD_OUT_STREAM, ) diff --git a/cdd/tests/test_compound/test_exmod.py b/cdd/tests/test_compound/test_exmod.py index c8f4e229..2060ae19 100644 --- a/cdd/tests/test_compound/test_exmod.py +++ b/cdd/tests/test_compound/test_exmod.py @@ -70,29 +70,6 @@ def setUpClass(cls) -> None: (cls.grandchild_name, cls.grandchild_dir), ) - @staticmethod - def normalise_double_paths(*dictionaries): - """ - On Windows the paths can come up weird, like C:\\\\foo instead of C:\\foo - - This fixes that issue, and also safe to work on non-Windows - - :param dictionaries: Dictionaries - :type dictionaries: ```tuple[dictionaries]``` - - :return: `map` of normalised `dictionaries` - :rtype: ```map``` - """ - return map( - lambda d: { - k: tuple( - map(repr, map(rpartial(str.replace, path.sep * 2, path.sep), v)) - ) - for k, v in d.items() - }, - dictionaries, - ) - @skipIf( "GITHUB_ACTIONS" in environ and version_info[:2] >= (3, 12), "GitHub Actions fails this test (unable to replicate locally)", @@ -305,34 +282,39 @@ def test_exmod_dry_run(self) -> None: k_v[0], tuple( sorted( - set( + frozenset( map( - partial( - relative_filename, - remove_hints=( - ( - lambda directory: ( - "{directory}{sep}".format( - directory=unquote( - repr(directory) - ), - sep=path.sep, + path.normcase, + map( + partial( + relative_filename, + remove_hints=( + ( + lambda directory: ( + "{directory}{sep}".format( + directory=unquote( + directory + ), + sep=path.sep, + ) + if platform + == "win32" + else directory ) - if platform == "win32" - else directory - ) - )( - path.join( - new_module_dir, - path.basename( - new_module_dir + )( + path.join( + new_module_dir, + path.basename( + new_module_dir + ), ), ), ), ), - ), - map( - unquote, map(itemgetter(1), k_v[1]) + map( + unquote, + map(itemgetter(1), k_v[1]), + ), ), ) ) @@ -358,27 +340,41 @@ def test_exmod_dry_run(self) -> None: self.assertEqual(count, len(result[key]), key) gold: ExmodOutput = ExmodOutput( - touch=(path.join(path.dirname(self.gold_dir), INIT_FILENAME),), + touch=( + path.normcase( + path.join(path.dirname(self.gold_dir), INIT_FILENAME) + ), + ), **{ k: tuple( map( rpartial(str.rstrip, path.sep), - map(partial(path.join, new_module_dir), v), + map( + path.normcase, + map(partial(path.join, new_module_dir), v), + ), ) ) for k, v in { - "mkdir": ("", *map(itemgetter(1), self.module_hierarchy)), + "mkdir": ( + "", + *map( + path.normcase, + map(itemgetter(1), self.module_hierarchy), + ), + ), "write": (INIT_FILENAME,), }.items() }, ) - if platform != "darwin": - self.assertDictEqual(*self.normalise_double_paths(result, gold)) + self.assertDictEqual(result, gold) self._check_emission(existent_module_dir, new_module_dir, dry_run=True) finally: self._pip(["uninstall", "-y", self.package_root_name]) + maxDiff = None + def create_and_install_pkg(self, root): """ Create and install the pacakge