Skip to content

Commit

Permalink
use tempdir for unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
hjtran committed Sep 17, 2023
1 parent e42f4fb commit 36038fc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sdks/python/apache_beam/runners/render_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import logging
import subprocess
import unittest
import tempfile
import pytest

import apache_beam as beam
Expand Down Expand Up @@ -98,9 +99,16 @@ def test_run_portable_pipeline(self):
p | beam.Impulse() | beam.Map(lambda _: 2)
| 'CustomName' >> beam.Map(lambda x: x * x))
pipeline_proto = p.to_runner_api()
render.RenderRunner().run_portable_pipeline(
pipeline_proto, render.RenderOptions(render_output=["my_output.svg"]))
assert os.path.exists("my_output.svg")

# In tmpdir:
# - Create a file called "my_output.svg"
# - Run the pipeline
# - Assert that "my_output.svg" exists
with tempfile.TemporaryDirectory() as tmpdir:
svg_path = os.path.join(tmpdir, "my_output.svg")
render.RenderRunner().run_portable_pipeline(
pipeline_proto, render.RenderOptions(render_output=[svg_path]))
assert os.path.exists(svg_path)

def test_dot_well_formed(self):
p = beam.Pipeline()
Expand Down

0 comments on commit 36038fc

Please sign in to comment.