-
Notifications
You must be signed in to change notification settings - Fork 0
/
byteio_test.py
37 lines (29 loc) · 1.07 KB
/
byteio_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from run import run
from byteio import *
from cpp.um_emulator import UniversalMachine
from pathlib import Path
import io
import sys
import pytest
def test_io_smoke():
um = UniversalMachine(Path('umix.umz').read_bytes())
run(um, umin=BaseReader(), umout=BaseWriter())
assert um.state == UniversalMachine.State.WAITING
output = io.StringIO('')
run(um, umin=TextReader(io.StringIO('guest\nexit\n')),
umout=ForkWriter(TextWriter(output), TextWriter(sys.stdout)))
assert um.state == UniversalMachine.State.HALT
assert 'logged in as guest' in output.getvalue()
def test_io_sequential():
input = SequentialReader(TextReader(io.StringIO('hello ')),
TextReader(io.StringIO('world')),
TextReader(io.StringIO('!\n')))
outstring = io.StringIO()
output = TextWriter(outstring)
while True:
c = input.readbyte()
if c is None: break
output.writebyte(c)
assert outstring.getvalue() == 'hello world!\n'
if __name__ == '__main__':
test_io_smoke()