From 56342d087793d8e6811dc5dadfd506acb44fbbb8 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 4 Jul 2012 19:21:59 +0400 Subject: [PATCH] ... Signed-off-by: Alex A. Naanou --- pli/logictypes.py | 14 +++++++++++--- pli/objutils.py | 2 +- pli/testlog.py | 38 +++++++++++++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/pli/logictypes.py b/pli/logictypes.py index 4506542..34e2308 100755 --- a/pli/logictypes.py +++ b/pli/logictypes.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.1.21''' -__sub_version__ = '''20110112220102''' +__sub_version__ = '''20120704184439''' __copyright__ = '''(c) Alex A. Naanou 2003''' __doc__ = '''\ @@ -212,8 +212,11 @@ class ErxCONTAINER(Pattern, mapping.Mapping): - content/containment - bounds ''' + ##!!! we need to pass data arround! def __init__(self, data=()): - objutils.termsuper(ErxCONTAINER, self).__init__(data) + ##!!! we need to pass data arround! +## objutils.termsuper(ErxCONTAINER, self).__init__(data) + objutils.termsuper(ErxCONTAINER, self).__init__() self._data = data # mapping-like interface... # NOTE: this is mainly needed to bypass pythons dict optimizations @@ -253,6 +256,7 @@ class ErxCONTAINER(Pattern, mapping.Mapping): def __eq__(self, other): ''' ''' + # NOTE: this will go through content items via .__iter__ for e in other: if e not in self: return False @@ -260,7 +264,8 @@ class ErxCONTAINER(Pattern, mapping.Mapping): def __ne__(self, other): ''' ''' - pass + # XXX is there a better way to do this? + return not (self == other) C = ErxCONTAINER @@ -285,6 +290,9 @@ class ORDERED(ErxCONTAINER): ##!!! should this be a view or a container? +# XXX this should be like OR -- match single elements as well as +# sub-sequences... i.e. '==' and 'in' should be equivalent but +# strictly prioretized... class CONTENT(ErxCONTAINER): ''' like a container but matches a part of a container. diff --git a/pli/objutils.py b/pli/objutils.py index 21d7ed7..73ce5db 100755 --- a/pli/objutils.py +++ b/pli/objutils.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.22''' -__sub_version__ = '''20100616203128''' +__sub_version__ = '''20120704184132''' __copyright__ = '''(c) Alex A. Naanou 2003-2008''' diff --git a/pli/testlog.py b/pli/testlog.py index 3a2ab15..bdff49e 100755 --- a/pli/testlog.py +++ b/pli/testlog.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20110812003340''' +__sub_version__ = '''20110913175458''' __copyright__ = '''(c) Alex A. Naanou 2003''' @@ -36,8 +36,6 @@ PPRINT_PREFIX = '>>>' # # # TODO add error log support... -# TODO add quiet mode... -# TODO reporting... # TODO exception handling both in testing and in failures.... # TODO add more clever output handling... # for things like: @@ -56,6 +54,8 @@ PPRINT_PREFIX = '>>>' #-----------------------------------------------------------------log--- # XXX rewrite... def log(*cmd, **kw): + ''' + ''' depth = kw.pop('depth', 1) rep = kw.pop('repr', REPR_FUNCTION) mute = kw.pop('mute', False) @@ -66,6 +66,7 @@ def log(*cmd, **kw): lcl = sys._getframe(depth).f_locals glbl = sys._getframe(depth).f_globals res = None + err = None code = '%(indent)s %(mute_prefix)s%(command)s%(result)s' data = { @@ -81,6 +82,7 @@ def log(*cmd, **kw): data['mute_prefix'] = mute_prefix data['command'] = cmd[0].strip() try: + ##!!! add exception handling... res = eval(compile(cmd[0].strip(), filename, 'eval'), glbl, lcl) if not mute: if len(cmd[0].strip()) + INDENT >= 8: @@ -92,12 +94,19 @@ def log(*cmd, **kw): # we've got a statement... except SyntaxError: # XXX need a more robust way to do this... + ##!!! add exception handling... eval(compile(cmd[0].strip(), filename, 'exec'), glbl, lcl) code += ' \n' + # we've got an exception... + except Exception, e: + err = e + # XXX figure out a better syntax to represent exceptions... + data['result'] = '\n\t-X-> %s\n' % rep(err) elif len(cmd) > 1: if mute: data['mute_prefix'] = mute_prefix data['command'] = ''.join([c.strip() for c in cmd]) + cmd[-1].strip() + ##!!! add exception handling... res = eval(compile(cmd[-1].strip(), filename, 'eval'), glbl, lcl) if not mute: if len(cmd[-1].strip()) + INDENT >= 8: @@ -109,15 +118,27 @@ def log(*cmd, **kw): else: code += '\n' - return code % data, res + return code % data, res, err #----------------------------------------------------------------test--- def test(*cmd, **kw): expected, cmd = cmd[-1], cmd[:-1] + expected_err = kw.pop('expected_err', None) depth = kw.pop('depth', 1) rep = kw.pop('repr', REPR_FUNCTION) - code, res = log(depth=depth+1, *cmd) + code, res, err = log(depth=depth+1, *cmd) + + ##!!! for some reason, if we have an exception, we do not reach this spot... + + if err is not None: + if expected_err is None: + raise err + if expected_err == err: + ##!!! stub... + res = err + ##!!! stub... + res = err text = code if res != expected: text += '\t## Error: result did not match the expected: %s' % rep(expected) @@ -143,6 +164,7 @@ def pretty_print(*cmd, **kw): glbl = sys._getframe(depth).f_globals text = '%s %s' % (PPRINT_PREFIX, code) + ##!!! add exception handling... res = pformat(eval(compile(cmd[0].strip(), filename, 'eval'), glbl, lcl), width=80-8-3) text += '%s %s' % ('\n##\t->', '\n##\t '.join(res.split('\n'))) return text @@ -273,6 +295,7 @@ def loglines2(*lines, **kw): yield res elif len(line) == 2: line_count += 1 + ##!!! add exception handling... res, text = test(line[0], eval(line[1]), depth=depth+1, **kw) if not res: lines_failed += 1 @@ -351,6 +374,11 @@ if __name__ == '__main__': # now we can test the value... a -> 1 + # we can also test for fails... + 1/0 + + 1/0 +## -X-> ZeroDivisionError # pretty printing... -- 2.11.4.GIT