Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,50 @@
*/
package org.openrewrite.python;

import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import org.openrewrite.ParseExceptionResult;
import org.openrewrite.SourceFile;
import org.openrewrite.python.tree.Py;
import org.openrewrite.test.RewriteTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.python.Assertions.python;

@DisabledIfEnvironmentVariable(named = "CI", matches = "true", disabledReason = "No remote client/server available")
class PythonParserTest implements RewriteTest {

@Test
void parseString() {
rewriteRun(
python(
"""
import sys
print(sys.path)
""",
spec -> spec.afterRecipe(cu -> {
assertThat(cu).isInstanceOf(Py.CompilationUnit.class);
})
import sys
print(sys.path)
""",
spec -> spec.afterRecipe(cu -> SoftAssertions.assertSoftly(softly -> {
softly.assertThat(cu).isInstanceOf(Py.CompilationUnit.class);
softly.assertThat(cu.getMarkers().getMarkers()).isEmpty();
})
)
)
);
}

@Test
void parseStringWithParser() {
SourceFile sf = PythonParser.builder().build()
.parse(
//language=python
"""
import sys
print(sys.path)
""")
.findFirst()
.get();
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(sf).isInstanceOf(Py.CompilationUnit.class);
softly.assertThat(sf.getMarkers().getMarkers()).isEmpty();
});
}
}