Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Jun 8, 2024
1 parent 0be288b commit e21331d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tornado/test/process_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def fetch(url, fail_ok=False):

@skipIfNonUnix
class SubprocessTest(AsyncTestCase):
maxDiff = None # XXX

def term_and_wait(self, subproc):
subproc.proc.terminate()
subproc.proc.wait()
Expand All @@ -150,11 +152,14 @@ def test_subprocess(self):
raise unittest.SkipTest(
"Subprocess tests not compatible with " "LayeredTwistedIOLoop"
)
env = dict(os.environ)
env["PYTHON_BASIC_REPL"] = "1"
subproc = Subprocess(
[sys.executable, "-u", "-i"],
stdin=Subprocess.STREAM,
stdout=Subprocess.STREAM,
stderr=subprocess.STDOUT,
env=env,
)
self.addCleanup(lambda: self.term_and_wait(subproc))
self.addCleanup(subproc.stdout.close)
Expand All @@ -167,21 +172,28 @@ def test_subprocess(self):
yield subproc.stdout.read_until(b">>> ")
subproc.stdin.write(b"raise SystemExit\n")
data = yield subproc.stdout.read_until_close()
if data:
print(str(data, "utf-8"))
self.assertEqual(data, b"")

@gen_test
def test_close_stdin(self):
# Close the parent's stdin handle and see that the child recognizes it.
env = dict(os.environ)
env["PYTHON_BASIC_REPL"] = "1"
subproc = Subprocess(
[sys.executable, "-u", "-i"],
stdin=Subprocess.STREAM,
stdout=Subprocess.STREAM,
stderr=subprocess.STDOUT,
env=env,
)
self.addCleanup(lambda: self.term_and_wait(subproc))
yield subproc.stdout.read_until(b">>> ")
subproc.stdin.close()
data = yield subproc.stdout.read_until_close()
if data != b"\n":
print(str(data, "utf-8"))
self.assertEqual(data, b"\n")

@gen_test
Expand Down

0 comments on commit e21331d

Please sign in to comment.