Skip to content

Commit 243a52c

Browse files
authored
Move tests running pipeline into a separate class for PythonExternalTransformTest (#36492)
1 parent b9a8972 commit 243a52c

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"modification": 1}
1+
{"modification": 2}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

sdks/java/extensions/python/src/test/java/org/apache/beam/sdk/extensions/python/PythonExternalTransformTest.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,56 +33,55 @@
3333
import org.apache.beam.sdk.schemas.SchemaTranslation;
3434
import org.apache.beam.sdk.schemas.logicaltypes.MicrosInstant;
3535
import org.apache.beam.sdk.testing.PAssert;
36-
import org.apache.beam.sdk.testing.TestPipeline;
3736
import org.apache.beam.sdk.testing.UsesPythonExpansionService;
3837
import org.apache.beam.sdk.testing.ValidatesRunner;
3938
import org.apache.beam.sdk.transforms.Create;
4039
import org.apache.beam.sdk.transforms.Keys;
4140
import org.apache.beam.sdk.util.PythonCallableSource;
41+
import org.apache.beam.sdk.util.construction.BaseExternalTest;
4242
import org.apache.beam.sdk.values.KV;
4343
import org.apache.beam.sdk.values.PCollection;
4444
import org.apache.beam.sdk.values.Row;
4545
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList;
4646
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
47-
import org.junit.Rule;
4847
import org.junit.Test;
4948
import org.junit.experimental.categories.Category;
5049
import org.junit.runner.RunWith;
5150
import org.junit.runners.JUnit4;
5251

5352
@RunWith(JUnit4.class)
5453
public class PythonExternalTransformTest implements Serializable {
55-
@Rule public transient TestPipeline testPipeline = TestPipeline.create();
56-
57-
@Test
58-
@Category({ValidatesRunner.class, UsesPythonExpansionService.class})
59-
public void trivialPythonTransform() {
60-
PCollection<String> output =
61-
testPipeline
62-
.apply(Create.of(KV.of("A", "x"), KV.of("A", "y"), KV.of("B", "z")))
63-
.apply(
64-
PythonExternalTransform
65-
.<PCollection<KV<String, String>>, PCollection<KV<String, Iterable<String>>>>
66-
from("apache_beam.GroupByKey"))
67-
.apply(Keys.create());
68-
PAssert.that(output).containsInAnyOrder("A", "B");
69-
testPipeline.run();
70-
}
71-
72-
@Test
73-
@Category({ValidatesRunner.class, UsesPythonExpansionService.class})
74-
public void pythonTransformWithDependencies() {
75-
PCollection<String> output =
76-
testPipeline
77-
.apply(Create.of("elephant", "mouse", "sheep"))
78-
.apply(
79-
PythonExternalTransform.<PCollection<String>, PCollection<String>>from(
80-
"apache_beam.Map")
81-
.withArgs(PythonCallableSource.of("import inflection\ninflection.pluralize"))
82-
.withExtraPackages(ImmutableList.of("inflection"))
83-
.withOutputCoder(StringUtf8Coder.of()));
84-
PAssert.that(output).containsInAnyOrder("elephants", "mice", "sheep");
85-
testPipeline.run();
54+
@RunWith(JUnit4.class)
55+
public static class RunPipelineTest extends BaseExternalTest {
56+
57+
@Test
58+
@Category({ValidatesRunner.class, UsesPythonExpansionService.class})
59+
public void trivialPythonTransform() {
60+
PCollection<String> output =
61+
testPipeline
62+
.apply(Create.of(KV.of("A", "x"), KV.of("A", "y"), KV.of("B", "z")))
63+
.apply(
64+
PythonExternalTransform
65+
.<PCollection<KV<String, String>>, PCollection<KV<String, Iterable<String>>>>
66+
from("apache_beam.GroupByKey"))
67+
.apply(Keys.create());
68+
PAssert.that(output).containsInAnyOrder("A", "B");
69+
}
70+
71+
@Test
72+
@Category({ValidatesRunner.class, UsesPythonExpansionService.class})
73+
public void pythonTransformWithDependencies() {
74+
PCollection<String> output =
75+
testPipeline
76+
.apply(Create.of("elephant", "mouse", "sheep"))
77+
.apply(
78+
PythonExternalTransform.<PCollection<String>, PCollection<String>>from(
79+
"apache_beam.Map")
80+
.withArgs(PythonCallableSource.of("import inflection\ninflection.pluralize"))
81+
.withExtraPackages(ImmutableList.of("inflection"))
82+
.withOutputCoder(StringUtf8Coder.of()));
83+
PAssert.that(output).containsInAnyOrder("elephants", "mice", "sheep");
84+
}
8685
}
8786

8887
@Test

0 commit comments

Comments
 (0)