From: timv Date: Wed, 12 Jun 2013 17:31:03 +0000 (-0400) Subject: fixed test/repl test cases. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=a7ecf90dc6c81b9c8358adc902f3824f76dc81e8;p=dyna2 fixed test/repl test cases. - repl no longer overwrites `~/.dyna/tmp.dyna` and `~/.dyna/tmp.dyna.plan.py` Now uses a file in `~/dyna/tmp/` with file name based on sha1 hash of necessary code (which includes parser_state pragmas, of course) --- diff --git a/src/Dyna/Backend/Python/interpreter.py b/src/Dyna/Backend/Python/interpreter.py index 0cab7ae..fabd396 100644 --- a/src/Dyna/Backend/Python/interpreter.py +++ b/src/Dyna/Backend/Python/interpreter.py @@ -197,6 +197,8 @@ import os, sys from collections import defaultdict from argparse import ArgumentParser +from hashlib import sha1 + import debug from chart import Chart, Term, _repr from defn import aggregator @@ -525,8 +527,15 @@ class Interpreter(object): raises ``DynaCompilerError`` """ + x = sha1() + x.update(self.parser_state) + x.update(code) + + dyna = dotdynadir / 'tmp' / ('%s.dyna' % x.hexdigest()) + + # make necessary directories + dyna.dirname().mkdir_p() - dyna = dotdynadir / 'tmp.dyna' out = '%s.plan.py' % dyna with file(dyna, 'wb') as f: diff --git a/src/Dyna/Backend/Python/repl.py b/src/Dyna/Backend/Python/repl.py index 046adc7..1de1e45 100644 --- a/src/Dyna/Backend/Python/repl.py +++ b/src/Dyna/Backend/Python/repl.py @@ -18,7 +18,6 @@ class REPL(cmd.Cmd, object): with file(hist, 'wb') as f: f.write('') readline.read_history_file(hist) - self.do_trace('off') self.lineno = 0 @property @@ -65,16 +64,8 @@ class REPL(cmd.Cmd, object): def do_ip(self, _): ip() - def do_trace(self, args): - if args == 'on': - self.interp.trace = sys.stdout - elif args == 'off': - self.interp.trace = file(os.devnull, 'w') - else: - print 'Did not understand argument %r please use (on or off).' % args - def do_debug(self, line): - with file(dotdynadir / 'tmp.dyna', 'wb') as f: + with file(dotdynadir / 'repl-debug-line.dyna', 'wb') as f: f.write(line) debug.main(f.name) diff --git a/test/repl/aggregator-conflict.expect b/test/repl/aggregator-conflict.expect index 3238426..34bdc95 100644 --- a/test/repl/aggregator-conflict.expect +++ b/test/repl/aggregator-conflict.expect @@ -1,6 +1,10 @@ :- :- ============= a := 1 -:- AggregatorConflict: Aggregator conflict 'a/0' was '+=' trying to set to '|='. +:- DynaCompilerError: +FATAL: Encountered error in input program: + Conflicting aggregators; rule /home/timv/.dyna/tmp/966093dc38b755a6f17b02774b5c656931163a3a.dyna:5:1-/home/timv/.dyna/tmp/966093dc38b755a6f17b02774b5c656931163a3a.dyna:5:3 + uses '|=' for a/0 but I had been lead to expect '+='. + > new rule(s) were not added to program. :- exit diff --git a/test/repl/retract-rule.expect b/test/repl/retract-rule.expect index 1552807..c4c5012 100644 --- a/test/repl/retract-rule.expect +++ b/test/repl/retract-rule.expect @@ -7,8 +7,8 @@ b := 1 :- ============= a := 2 -:- 0: - 1: a += 1. +:- 0: a += 1. + 1: b += 1. 2: a += 1. :- Charts