Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit 464e907

Browse files
authored
Fixes some bugs in test code (#95)
* Fixes some bugs in test code * test with export dep * Enable poetry-plugin-export in CI Update poetry version
1 parent 1cfd223 commit 464e907

File tree

6 files changed

+16
-5
lines changed

6 files changed

+16
-5
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343

4444
- name: Install Poetry
4545
uses: snok/install-poetry@v1
46+
with:
47+
version: 1.8.1
48+
plugins: poetry-plugin-export
4649

4750
- name: build-java
4851
run: ./gradlew ${{ env.GRADLE_SWITCHES }} build

rewrite/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ openrewrite-remote = "*"
2020

2121
[build-system]
2222
requires = ["poetry-core>=1.0.0"]
23-
build-backend = "poetry.core.masonry.api"
23+
build-backend = "poetry.core.masonry.api"

rewrite/rewrite/java/extensions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import Optional, TypeVar, TYPE_CHECKING
22

33
from .support_types import J, JRightPadded, JLeftPadded, JContainer, Space
4+
from ..visitor import Cursor
5+
from ..tree import Tree
46

57
if TYPE_CHECKING:
68
from .visitor import JavaVisitor
@@ -16,7 +18,7 @@ def visit_container(v: 'JavaVisitor', container: Optional[JContainer[J2]], loc:
1618

1719
v.cursor = Cursor(v.cursor, container)
1820
before = v.visit_space(container.before, loc.before_location, p)
19-
js = [v.visit_right_padded(el.element, loc.element_location, p) for el in container.padding.elements]
21+
js = [v.visit_right_padded(el, loc.element_location, p) for el in container.padding.elements]
2022
v.cursor = v.cursor.parent
2123

2224
return container if js == container.padding.elements and before is container.before else JContainer(before, js, container.markers)

rewrite/rewrite/python/support_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def accept(self, v: TreeVisitor[Any, P], p: P) -> Optional[Any]:
2323
def accept_python(self, v: 'PythonVisitor[P]', p: P) -> Optional['J']:
2424
...
2525

26+
def is_acceptable(self, v: TreeVisitor[Any, P], p: P) -> bool:
27+
from .visitor import PythonVisitor
28+
return isinstance(v, PythonVisitor)
29+
2630

2731
class PySpace:
2832
class Location(Enum):

rewrite/rewrite/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def rewrite_run(*sources: list[SourceSpec]):
7272

7373
if spec.after is not None:
7474
after = spec.after(source_file.print_all())
75-
assert after == spec.before
75+
assert source_file.print_all() == after
76+
else:
77+
assert source_file.print_all() == spec.before
7678
break
7779
except Exception:
7880
raise
@@ -85,6 +87,6 @@ def python(before: str, after: str = None) -> list[SourceSpec]:
8587
random_id(),
8688
PythonParserBuilder(),
8789
textwrap.dedent(before),
88-
None if after is None else lambda: after,
90+
None if after is None else lambda _: textwrap.dedent(after),
8991
None
9092
)]

rewrite/rewrite/visitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def first_enclosing(self, type: Type[P]) -> P:
4141
class TreeVisitor(Protocol[T, P]):
4242
_visit_count: int = 0
4343
_cursor: Cursor = Cursor(None, "root")
44-
_after_visit: Optional[List[TreeVisitor[Any, P]]]
44+
_after_visit: Optional[List[TreeVisitor[Any, P]]] = None
4545

4646
def is_acceptable(self, source_file: SourceFile, p: P) -> bool:
4747
return True

0 commit comments

Comments
 (0)