Files
asciinema/tests/pty_test.py
Davis Schirmer bd3e6f5f67 [test] Convert unittests runner nose => pytest
Per the official docs, nose is in maintenance mode. Attempts to import
`Callable` from `collections` fails in Python 3.10. Convert
nose-specific assert statements to bare asserts supported by pytest.

* https://nose.readthedocs.io/en/latest/#note-to-users
* https://github.com/pytest-dev/nose2pytest
2021-11-05 01:13:56 -04:00

50 lines
1.0 KiB
Python

import os
import pty
import asciinema.pty
from .test_helper import Test
class FakeStdout:
def __init__(self):
self.data = []
def write_stdout(self, ts, data):
self.data.append(data)
def write_stdin(self, ts, data):
pass
class TestRecord(Test):
def setUp(self):
self.real_os_write = os.write
os.write = self.os_write
def tearDown(self):
os.write = self.real_os_write
def os_write(self, fd, data):
if fd != pty.STDOUT_FILENO:
self.real_os_write(fd, data)
def test_record_command_writes_to_stdout(self):
output = FakeStdout()
command = [
"python3",
"-c",
(
"import sys"
"; import time"
"; sys.stdout.write('foo')"
"; sys.stdout.flush()"
"; time.sleep(0.01)"
"; sys.stdout.write('bar')"
),
]
asciinema.pty.record(command, output)
assert output.data == [b"foo", b"bar"]