Skip to content

Commit

Permalink
add tty raw out test
Browse files Browse the repository at this point in the history
  • Loading branch information
zTrix committed Sep 20, 2020
1 parent 8820af4 commit 959800b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 40 deletions.
40 changes: 0 additions & 40 deletions test/myprintf.py

This file was deleted.

1 change: 1 addition & 0 deletions test2/myprintf.py
23 changes: 23 additions & 0 deletions test2/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import threading
import socket
import unittest
import string
from StringIO import StringIO as BytesIO
import unittest
from zio import *
Expand Down Expand Up @@ -209,6 +210,28 @@ def test_uname(self):

self.assertEqual(io.exit_status(), 0)

def test_tty_raw_out(self):
s = []
ans = []
for i in range(10):
r = random.randint(0,1)
s.append('%d%s' % (i, r and '\\r\\n' or '\\n'))
ans.append('%d%s' % (i, r and '\r\n' or '\n'))
ans = ''.join(ans)
cmd = "printf '" + ''.join(s) + "'"
io = zio(cmd, stdout=TTY_RAW)
rd = io.read()
io.close()
self.assertEqual(rd, ans.encode())

unprintable = [chr(c) for c in range(256) if chr(c) not in string.printable]
random.shuffle(unprintable)
unprintable = ''.join(unprintable)

io = zio(' '.join([sys.executable, '-u', os.path.join(os.path.dirname(sys.argv[0]), 'myprintf.py'), "'\\r\\n" + repr(unprintable)[1:-1] + "\\n'"]), stdout=TTY_RAW, print_read=COLORED(REPR))
rd = io.read()
self.assertEqual(rd, b"\r\n" + unprintable + b"\n")

if sys.version_info[1] < 7:
# python2.6 shim

Expand Down
7 changes: 7 additions & 0 deletions test3/myprintf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python

import os, sys
from zio import EVAL as evals
from zio import write_stdout

write_stdout(evals(sys.argv[1].encode()))
23 changes: 23 additions & 0 deletions test3/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import socket
import unittest
import time
import string
from io import BytesIO
from zio import *

Expand Down Expand Up @@ -210,5 +211,27 @@ def test_uname(self):

self.assertEqual(io.exit_status(), 0)

def test_tty_raw_out(self):
s = []
ans = []
for i in range(10):
r = random.randint(0,1)
s.append('%d%s' % (i, r and '\\r\\n' or '\\n'))
ans.append('%d%s' % (i, r and '\r\n' or '\n'))
ans = ''.join(ans)
cmd = "printf '" + ''.join(s) + "'"
io = zio(cmd, stdout=TTY_RAW)
rd = io.read()
io.close()
self.assertEqual(rd, ans.encode())

unprintable = [c for c in range(256) if chr(c) not in string.printable]
random.shuffle(unprintable)
unprintable = bytes(unprintable)

io = zio(' '.join([sys.executable, '-u', os.path.join(os.path.dirname(sys.argv[0]), 'myprintf.py'), "'\\r\\n" + str(unprintable)[2:-1] + "\\n'"]), stdout=TTY_RAW, print_read=COLORED(REPR))
rd = io.read()
self.assertEqual(rd, b"\r\n" + unprintable + b"\n")

if __name__ == '__main__':
unittest.main(verbosity=2, failfast=True)
1 change: 1 addition & 0 deletions zio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ def main():
'l8', 'b8', 'l16', 'b16', 'l32', 'b32', 'l64', 'b64', 'convert_packing',
'colored',
'match_pattern',
'write_stdout', 'write_stderr',
'xor', 'bytes2hex', 'hex2bytes', 'tohex', 'unhex',
'zio',
'HEX', 'TOHEX', 'UNHEX', 'EVAL', 'REPR', 'RAW', 'NONE',
Expand Down

0 comments on commit 959800b

Please sign in to comment.