Skip to content

Commit

Permalink
Revert to os.walk in scaffold_commands (Path.walk only supported in P…
Browse files Browse the repository at this point in the history
…ython 3.12+)
  • Loading branch information
swainn authored Nov 29, 2024
1 parent c6be0d8 commit c009a39
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
66 changes: 33 additions & 33 deletions tests/unit_tests/test_tethys_cli/test_scaffold_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_render_path(self):
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Path.write_text")
Expand All @@ -133,7 +133,7 @@ def test_scaffold_command(
__,
___,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_scaffold_command(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs_tmpl")),
]
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_scaffold_command_with_not_valid_template(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Path.write_text")
Expand All @@ -278,7 +278,7 @@ def test_scaffold_command_with_no_extension(
__,
___,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -307,7 +307,7 @@ def test_scaffold_command_with_no_extension(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs_tmpl")),
]
Expand Down Expand Up @@ -369,7 +369,7 @@ def test_scaffold_command_with_no_extension(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Path.write_text")
Expand All @@ -380,7 +380,7 @@ def test_scaffold_command_with_uppercase_project_name(
__,
___,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -410,7 +410,7 @@ def test_scaffold_command_with_uppercase_project_name(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs_tmpl")),
]
Expand Down Expand Up @@ -519,7 +519,7 @@ def test_scaffold_command_with_wrong_project_name(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Path.write_text")
Expand All @@ -530,7 +530,7 @@ def test_scaffold_command_with_project_warning(
__,
___,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -559,7 +559,7 @@ def test_scaffold_command_with_project_warning(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs_tmpl")),
]
Expand Down Expand Up @@ -628,7 +628,7 @@ def test_scaffold_command_with_project_warning(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Path.write_text")
Expand All @@ -639,7 +639,7 @@ def test_scaffold_command_with_no_defaults(
__,
___,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -670,7 +670,7 @@ def test_scaffold_command_with_no_defaults(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs_tmpl")),
]
Expand Down Expand Up @@ -746,7 +746,7 @@ def test_scaffold_command_with_no_defaults(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Template")
Expand All @@ -757,7 +757,7 @@ def test_scaffold_command_with_no_defaults_input_exception(
_,
__,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -788,7 +788,7 @@ def test_scaffold_command_with_no_defaults_input_exception(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs")),
]
Expand Down Expand Up @@ -841,7 +841,7 @@ def test_scaffold_command_with_no_defaults_input_exception(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Path.write_text")
Expand All @@ -852,7 +852,7 @@ def test_scaffold_command_with_no_defaults_invalid_response(
__,
___,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -884,7 +884,7 @@ def test_scaffold_command_with_no_defaults_invalid_response(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs_tmpl")),
]
Expand Down Expand Up @@ -968,7 +968,7 @@ def test_scaffold_command_with_no_defaults_invalid_response(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Path.write_text")
Expand All @@ -979,7 +979,7 @@ def test_scaffold_command_with_no_overwrite(
__,
___,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -1010,7 +1010,7 @@ def test_scaffold_command_with_no_overwrite(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs_tmpl")),
]
Expand Down Expand Up @@ -1081,7 +1081,7 @@ def test_scaffold_command_with_no_overwrite(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Template")
Expand All @@ -1090,7 +1090,7 @@ def test_scaffold_command_with_no_overwrite_keyboard_interrupt(
_,
__,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -1121,7 +1121,7 @@ def test_scaffold_command_with_no_overwrite_keyboard_interrupt(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs")),
]
Expand Down Expand Up @@ -1175,7 +1175,7 @@ def test_scaffold_command_with_no_overwrite_keyboard_interrupt(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Template")
Expand All @@ -1184,7 +1184,7 @@ def test_scaffold_command_with_no_overwrite_cancel(
_,
__,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -1215,7 +1215,7 @@ def test_scaffold_command_with_no_overwrite_cancel(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs")),
]
Expand Down Expand Up @@ -1269,7 +1269,7 @@ def test_scaffold_command_with_no_overwrite_cancel(
@mock.patch("tethys_cli.scaffold_commands.Path.is_dir")
@mock.patch("tethys_cli.scaffold_commands.shutil.rmtree")
@mock.patch("tethys_cli.scaffold_commands.render_path")
@mock.patch("tethys_cli.scaffold_commands.Path.walk")
@mock.patch("tethys_cli.scaffold_commands.walk")
@mock.patch("tethys_cli.scaffold_commands.Path.mkdir")
@mock.patch("tethys_cli.scaffold_commands.Path.read_text")
@mock.patch("tethys_cli.scaffold_commands.Template")
Expand All @@ -1278,7 +1278,7 @@ def test_scaffold_command_with_no_overwrite_os_error(
_,
__,
mock_mkdir,
mock_path_walk,
mock_os_walk,
mock_render_path,
mock_rmt,
mock_is_dir,
Expand Down Expand Up @@ -1309,7 +1309,7 @@ def test_scaffold_command_with_no_overwrite_os_error(

mock_render_path.return_value = ""

mock_path_walk.return_value = [
mock_os_walk.return_value = [
(Path("/").absolute() / "foo", ("bar",), ("baz",)),
(Path("/").absolute() / "foo" / "bar", (), ("spam", "eggs")),
]
Expand Down
3 changes: 2 additions & 1 deletion tethys_cli/scaffold_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import random
import shutil
from os import walk
from pathlib import Path

from jinja2 import Template
Expand Down Expand Up @@ -417,7 +418,7 @@ def scaffold_command(args):
exit(1)

# Walk the template directory, creating the templates and directories in the new project as we go
for curr_template_root, _, template_files in template_root.walk():
for curr_template_root, _, template_files in walk(template_root):
curr_project_root = str(curr_template_root).replace(
str(template_root), str(project_root)
)
Expand Down

0 comments on commit c009a39

Please sign in to comment.