Skip to content

Commit

Permalink
[cdd/tests/test_compound/test_exmod.py] Replace custom `normalise_dou…
Browse files Browse the repository at this point in the history
…ble_paths` with `os.path.normcase` ; [cdd/compound/exmod.py] No longer `__repr__` the dry-run output… just `path.normcase` it
  • Loading branch information
SamuelMarks committed Jan 24, 2024
1 parent 2dc5c5b commit 9a782d1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 57 deletions.
2 changes: 1 addition & 1 deletion cdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
8 changes: 6 additions & 2 deletions cdd/compound/exmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions cdd/compound/exmod_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,18 @@ 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)

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:
Expand Down Expand Up @@ -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,
)
Expand Down
96 changes: 46 additions & 50 deletions cdd/tests/test_compound/test_exmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -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]),
),
),
)
)
Expand All @@ -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
Expand Down

0 comments on commit 9a782d1

Please sign in to comment.