From 254aaca622b6b9139ccfa59639d847c4495f510d Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Thu, 11 Apr 2013 14:38:04 -0400 Subject: [PATCH] * Added tester for active Parameters value. --- params/params_flat_test.py | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/params/params_flat_test.py b/params/params_flat_test.py index 97d6c27..0c5e45c 100644 --- a/params/params_flat_test.py +++ b/params/params_flat_test.py @@ -28,6 +28,7 @@ def test1(): def test2(**_opts_): + """Testing _localvars_ option.""" p = global_defaults._create_(_localvars_=1) nbasis = 327 @@ -41,6 +42,7 @@ def test2(**_opts_): def test2b(**_opts_): + """Testing _localvars_ option.""" nbasis = 327 p = global_defaults._create_(_localvars_=1) @@ -142,6 +144,42 @@ def test5(**_opts_): print "nsppol = ", p.nsppol +def test6(): + """Tests active method.""" + from wpylib.text_tools import str_snippet as snippet + from wpylib.params.params_flat import ActiveReadValue as Act + defaults = { + 'nbasis': 320, + 'npart': 37, + 'deltau': 0.025, + } + print "test6()" + p = params(defaults, nbasis=332) + p.input_template = Act(lambda P: snippet("""\ + input = { + nbasis = %(nbasis)d + npart = %(npart)d + deltau = %(deltau)s + }; + code = { + %(code_template)s + }; + """) % P) + p.code_template = Act(lambda P: snippet("""\ + for (i = 1; %(nbasis)d; ++i) { + print i, %(deltau)g + } + """) % P) + print "\nInput template 1:" + print p.input_template + + p.nbasis = 327 + print "\nInput template 2 after updating nbasis:" + print p.input_template + + print "\nHere is the generator script:\n*%(input_template)s*" % p._create_(deltau=2.775) + + def dump_objects(): """See what's in each dicts. """ @@ -149,6 +187,8 @@ def dump_objects(): if __name__ == "__main__": + test6() + exit() test1() test2() test2b()