Make test tools interactive

By bypassing readlines() buffering.
This commit is contained in:
Behdad Esfahbod 2012-01-20 18:39:27 -05:00
parent 91540a7d97
commit ad34e39a4a
1 changed files with 27 additions and 6 deletions

View File

@ -25,6 +25,10 @@ class Colors:
else: else:
return Colors.Null return Colors.Null
@staticmethod
def Default (argv = []):
return Colors.ANSI
class FancyDiffer: class FancyDiffer:
@ -80,6 +84,7 @@ class FancyDiffer:
for l in f1: for l in f1:
sys.stdout.writelines (["-", colors.green, l1, colors.end]) sys.stdout.writelines (["-", colors.green, l1, colors.end])
class DiffFilters: class DiffFilters:
@staticmethod @staticmethod
@ -89,6 +94,15 @@ class DiffFilters:
sys.stdout.writelines (l) sys.stdout.writelines (l)
class ShapeFilters:
@staticmethod
def filter_failures (f):
for l in f:
if l[0] in '-+':
sys.stdout.writelines (l)
class UtilMains: class UtilMains:
@staticmethod @staticmethod
@ -99,7 +113,7 @@ class UtilMains:
sys.exit (1) sys.exit (1)
for s in sys.argv[1:]: for s in sys.argv[1:]:
callback (open_file_or_stdin (s)) callback (FileHelpers.open_file_or_stdin (s))
@staticmethod @staticmethod
def filter_multiple_strings_or_stdin (callback, string_mnemonic, \ def filter_multiple_strings_or_stdin (callback, string_mnemonic, \
@ -113,7 +127,10 @@ class UtilMains:
if '--stdin' in sys.argv: if '--stdin' in sys.argv:
sys.argv.remove ('--stdin') sys.argv.remove ('--stdin')
for line in sys.stdin.readlines (): while (1):
line = sys.stdin.readline ()
if not len (line):
break
print callback (line) print callback (line)
else: else:
args = sys.argv[1:] args = sys.argv[1:]
@ -171,10 +188,14 @@ class Unicode:
s = [unichr (int (x, 16)) for x in re.split ('[, \n]', s) if len (x)] s = [unichr (int (x, 16)) for x in re.split ('[, \n]', s) if len (x)]
return ' + '.join (Unicode.pretty_name (x) for x in s) return ' + '.join (Unicode.pretty_name (x) for x in s)
def open_file_or_stdin (f):
if f == '-': class FileHelprs:
return sys.stdin
return file (f) @staticmethod
def open_file_or_stdin (f):
if f == '-':
return sys.stdin
return file (f)
if __name__ == '__main__': if __name__ == '__main__':
pass pass