Skip to content

Commit 4a6e42c

Browse files
committed
Merge branch 'freshen-tests' into actions
2 parents 68218d4 + 57fa8c5 commit 4a6e42c

File tree

2 files changed

+930
-19
lines changed

2 files changed

+930
-19
lines changed

protogen/test.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,25 @@ def run_plugin(
5656
# Open stdin and stdout for the plugin.
5757
# We need SpoledTemporaryFile(mode="w+t")._file because its a TextIOWrapper
5858
# which sys.stdin and sys.stdout also are.
59-
fake_stdin = tempfile.SpooledTemporaryFile(mode="w+t")._file
60-
fake_stdin.buffer.write(req.SerializeToString())
61-
fake_stdin.flush()
62-
fake_stdin.seek(0)
63-
fake_stdout = tempfile.SpooledTemporaryFile(mode="w+t")._file
64-
65-
_stdin, sys.stdin = sys.stdin, fake_stdin
66-
_stdout, sys.stdout = sys.stdout, fake_stdout
67-
68-
# Call the plugin under test.
69-
import_module(plugin)
70-
71-
fake_stdout.seek(0)
72-
resp = google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.FromString(
73-
fake_stdout.buffer.read()
74-
)
75-
76-
fake_stdin.close() # will remove tmp files
77-
fake_stdout.close()
59+
with tempfile.SpooledTemporaryFile(mode="w+t") as tmp_stdin:
60+
with tempfile.SpooledTemporaryFile(mode="w+t") as tmp_stdout:
61+
fake_stdin = tmp_stdin._file
62+
fake_stdin.buffer.write(req.SerializeToString())
63+
fake_stdin.flush()
64+
fake_stdin.seek(0)
65+
66+
fake_stdout = tmp_stdout._file
67+
68+
_stdin, sys.stdin = sys.stdin, fake_stdin
69+
_stdout, sys.stdout = sys.stdout, fake_stdout
70+
71+
# Call the plugin under test.
72+
import_module(plugin)
73+
74+
fake_stdout.seek(0)
75+
resp = google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse.FromString(
76+
fake_stdout.buffer.read()
77+
)
7878

7979
# Reset stdin and stdout.
8080
sys.stdin = _stdin

0 commit comments

Comments
 (0)