"""Utilities for running individual tests""" import itertools import os import re import time from cram._encoding import b, bchr, bytestype, envencode, unicodetype from cram._diff import esc, glob, regex, unified_diff from cram._process import PIPE, STDOUT, execute __all__ = ['test', 'testfile'] _needescape = re.compile(b(r'[\x00-\x09\x0b-\x1f\x7f-\xff]')).search _escapesub = re.compile(b(r'[\x00-\x09\x0b-\x1f\\\x7f-\xff]')).sub _escapemap = dict((bchr(i), b(r'\x%02x' % i)) for i in range(256)) _escapemap.update({b('\\'): b('\\\\'), b('\r'): b(r'\r'), b('\t'): b(r'\t')}) def _escape(s): """Like the string-escape codec, but doesn't escape quotes""" return (_escapesub(lambda m: _escapemap[m.group(0)], s[:-1]) + b(' (esc)\n')) def test(lines, shell='/bin/sh', indent=2, testname=None, env=None, cleanenv=True, debug=False, noerrfile=False): r"""Run test lines and return input, output, and diff. This returns a 3-tuple containing the following: (list of lines in test, same list with actual output, diff)
"""Utilities for running individual tests""" import itertools import os import re import time from cram._encoding import b, bchr, bytestype, envencode, unicodetype from cram._diff import esc, glob, regex, unified_diff from cram._process import PIPE, STDOUT, execute __all__ = ['test', 'testfile'] _needescape = re.compile(b(r'[\x00-\x09\x0b-\x1f\x7f-\xff]')).search _escapesub = re.compile(b(r'[\x00-\x09\x0b-\x1f\\\x7f-\xff]')).sub _escapemap = dict((bchr(i), b(r'\x%02x' % i)) for i in range(256)) _escapemap.update({b('\\'): b('\\\\'), b('\r'): b(r'\r'), b('\t'): b(r'\t')}) def _escape(s): """Like the string-escape codec, but doesn't escape quotes""" return (_escapesub(lambda m: _escapemap[m.group(0)], s[:-1]) + b(' (esc)\n')) def test(lines, shell='/bin/sh', indent=2, testname=None, env=None, cleanenv=True,