Skip to content

Commit 0d54f4d

Browse files
committed
fix tests
1 parent 9f8b90c commit 0d54f4d

File tree

3 files changed

+27
-41
lines changed

3 files changed

+27
-41
lines changed

src/idom/_console/update_html_usages.py

+17-27
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@
1515
import click
1616

1717
from idom import html
18-
from idom._console.utils import echo_error, echo_warning
1918

2019

2120
CAMEL_CASE_SUB_PATTERN = re.compile(r"(?<!^)(?=[A-Z])")
2221

2322

2423
@click.command()
25-
@click.argument(
26-
"directories",
27-
nargs=-1,
28-
type=click.Path(exists=True, dir_okay=True, file_okay=False),
29-
)
24+
@click.argument("paths", nargs=-1, type=click.Path(exists=True))
3025
def update_html_usages(paths: list[str]) -> None:
3126
"""Rewrite files under the given paths using the new html element API.
3227
@@ -61,26 +56,19 @@ def update_html_usages(paths: list[str]) -> None:
6156

6257
at_least_one_file = False
6358
for p in map(Path, paths):
64-
if not p.exists():
65-
echo_warning(f"no directory {p}")
66-
continue
6759
for f in [p] if p.is_file() else p.rglob("*.py"):
6860
at_least_one_file = True
6961
result = generate_rewrite(file=f, source=f.read_text())
7062
if result is not None:
7163
f.write_text(result)
7264

73-
if not at_least_one_file:
74-
echo_error("Found no Python files in the given directories.")
75-
sys.exit(1)
76-
7765

7866
def generate_rewrite(file: Path, source: str) -> str | None:
7967
tree = ast.parse(source)
8068

8169
changed: list[Sequence[ast.AST]] = []
8270
for parents, node in walk_with_parent(tree):
83-
if not (isinstance(node, ast.Call) and node.args):
71+
if not isinstance(node, ast.Call):
8472
continue
8573

8674
func = node.func
@@ -91,28 +79,30 @@ def generate_rewrite(file: Path, source: str) -> str | None:
9179
else:
9280
continue
9381

94-
if not (hasattr(html, name) or name == "vdom"):
95-
continue
96-
9782
if name == "vdom":
83+
if len(node.args) < 2:
84+
continue
9885
maybe_attr_dict_node = node.args[1]
9986
# remove attr dict from new args
10087
new_args = node.args[:1] + node.args[2:]
101-
else:
88+
elif hasattr(html, name):
89+
if len(node.args) == 0:
90+
continue
10291
maybe_attr_dict_node = node.args[0]
10392
# remove attr dict from new args
10493
new_args = node.args[1:]
94+
else:
95+
continue
10596

106-
if node.args:
107-
new_keyword_info = extract_keywords(maybe_attr_dict_node)
108-
if new_keyword_info is not None:
109-
if new_keyword_info.replace:
110-
node.keywords = new_keyword_info.keywords
111-
else:
112-
node.keywords.extend(new_keyword_info.keywords)
97+
new_keyword_info = extract_keywords(maybe_attr_dict_node)
98+
if new_keyword_info is not None:
99+
if new_keyword_info.replace:
100+
node.keywords = new_keyword_info.keywords
101+
else:
102+
node.keywords.extend(new_keyword_info.keywords)
113103

114-
node.args = new_args
115-
changed.append((node, *parents))
104+
node.args = new_args
105+
changed.append((node, *parents))
116106

117107
if not changed:
118108
return None

src/idom/_console/utils.py

-9
This file was deleted.

tests/test__console/test_update_html_usages.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ def test_update_html_usages_no_files():
3131
runner = CliRunner()
3232

3333
result = runner.invoke(
34-
update_html_usages,
35-
args=["directory-does-no-exist"],
36-
catch_exceptions=False,
34+
update_html_usages, args=["directory-does-no-exist"], catch_exceptions=False
3735
)
3836

39-
assert result.exit_code == 1
40-
assert "Found no Python files" in result.stdout
37+
assert result.exit_code != 0
4138

4239

4340
@pytest.mark.parametrize(
@@ -90,6 +87,14 @@ def test_update_html_usages_no_files():
9087
'html.div(ignore, {"className": "test"})',
9188
None,
9289
),
90+
(
91+
"html.div()",
92+
None,
93+
),
94+
(
95+
'html.vdom("div")',
96+
None,
97+
),
9398
(
9499
'html.div({"tagName": "test"})',
95100
None,

0 commit comments

Comments
 (0)