def setUp(self): cells.reset() self.x = cells.InputCell(None, 4, name="x") self.a = cells.UntilAskedLazyCell( None, name="a", rule=lambda s, p: self.x.getvalue() + 1) self.a.getvalue(init=True) # establish dependencies, a = 5 self.x.set(42) # cause propogation
def setUp(self): cells.reset() self.x = cells.InputCell(None, 4, name="x") self.a = cells.UntilAskedLazyCell(None, name="a", rule=lambda s,p: self.x.getvalue() + 1) self.a.getvalue(init=True) # establish dependencies, a = 5 self.x.set(42) # cause propogation
def setUp(self): cells.reset() self.x = cells.Cell(None, name="x", value=1) self.b = cells.Cell(None, name="b", rule=lambda s, p: (p or 40) + 2) self.a = cells.Cell( None, name="a", rule=lambda s, p: self.b.getvalue() * self.x.getvalue())
def test_ObserverMultipleObjects(self): "Observers should act correctly with multiple instances of a MO" # this test is a little different than the others, so cells.reset() self.observerlog = [] a = self.M() # this should fire the model obs b = self.M() # as should this self.failUnless(2 == self.observerlog.count("model"))
def test_ObserverMultipleObjects(self): "Observers should act correctly with multiple instances of a MO" # this test is a little different than the others, so cells.reset() self.observerlog = [] a = self.M() # this should fire the model obs b = self.M() # as should this self.failUnless(2 == self.observerlog.count("model"))
def test_1b_RunRaisesAfterEval(self): """Rule 1: 1. Evaluates once at init, sets its value, and then acts like an InputCell. """ cells.reset() x = cells.RuleThenInputCell(None, rule=lambda s,p: 0, name="x") x.getvalue() self.failUnlessRaises(cells.InputCellRunError, x.run)
def test_1b_RunRaisesAfterEval(self): """Rule 1: 1. Evaluates once at init, sets its value, and then acts like an InputCell. """ cells.reset() x = cells.RuleThenInputCell(None, rule=lambda s, p: 0, name="x") x.getvalue() self.failUnlessRaises(cells.InputCellRunError, x.run)
def setUp(self): cells.reset() self.x = cells.InputCell(None, 4, name="x") self.a = cells.OnceAskedLazyCell(None, name="a", rule=lambda s,p: self.x.getvalue()+(p or 1)) self.a.getvalue() # establish dependencies self.x.set(42) # cause propogation
def setUp(self): cells.reset() self.x = cells.Cell(None, name="x", value=21) self.captured_notify_flag = None def a_rule(s, p): self.captured_notify_flag = self.x.notifying return self.x.getvalue() * 2 self.a = cells.Cell(None, name="a", rule=a_rule)
def setUp(self): cells.reset() self.x = cells.InputCell(None, 4, name="x") self.a = cells.OnceAskedLazyCell(None, name="a", rule=lambda s, p: self.x.getvalue() + (p or 1)) self.a.getvalue() # establish dependencies self.x.set(42) # cause propogation
def setUp(self): cells.reset() self.x = cells.Cell(None, name="x", value=21) self.captured_notify_flag = None def a_rule(s, p): self.captured_notify_flag = self.x.notifying return self.x.getvalue() * 2 self.a = cells.Cell(None, name="a", rule=a_rule)
def setUp(self): cells.reset() class K(cells.Family): x = cells.makecell(value=1) model_value = cells.makecell(rule=lambda s,p: s.x * 3) class F(cells.Family): kid_slots = cells.makecell(value=K) self.F = F self.K = K
def setUp(self): cells.reset() class K(cells.Family): x = cells.makecell(value=1) model_value = cells.makecell(rule=lambda s, p: s.x * 3) class F(cells.Family): kid_slots = cells.makecell(value=K) self.F = F self.K = K
def test_1_NoEvalOnPropogation(self): "Always Lazy 1: Always lazys never evaluate on change propogation" cells.reset() x = cells.InputCell(None, 4, name="x") a = cells.AlwaysLazyCell(None, name="a", rule=lambda s,p: x.getvalue() + (p or 1)) a.getvalue() # establish dependencies x.set(42) # cause propogation self.failUnless(a.value == 5) # sneaky exam doesn't cause lazy eval self.failUnless(a.getvalue() == 47) # standard eval causes lazy eval x.set(5) # cause another propogation self.failUnless(a.value == 47) # yadda yadda... self.failUnless(a.getvalue() == 52)
def test_1_NoEvalOnPropogation(self): "Always Lazy 1: Always lazys never evaluate on change propogation" cells.reset() x = cells.InputCell(None, 4, name="x") a = cells.AlwaysLazyCell(None, name="a", rule=lambda s, p: x.getvalue() + (p or 1)) a.getvalue() # establish dependencies x.set(42) # cause propogation self.failUnless(a.value == 5) # sneaky exam doesn't cause lazy eval self.failUnless(a.getvalue() == 47) # standard eval causes lazy eval x.set(5) # cause another propogation self.failUnless(a.value == 47) # yadda yadda... self.failUnless(a.getvalue() == 52)
def test_2_NoEvalOnInit(self): "Always Lazy 2: Does not evaluate during model init" cells.reset() ran_flag = False def a_rule(self, prev): ran_flag = True return self.x + 2 class M(cells.Model): x = cells.makecell(value=3) a = cells.makecell(rule=a_rule, celltype=cells.AlwaysLazyCell) m = M() self.failIf(ran_flag) self.failUnless(m.a == 5)
def test_2_NoEvalOnInit(self): "Always Lazy 2: Does not evaluate during model init" cells.reset() ran_flag = False def a_rule(self, prev): ran_flag = True return self.x + 2 class M(cells.Model): x = cells.makecell(value=3) a = cells.makecell(rule=a_rule, celltype=cells.AlwaysLazyCell) m = M() self.failIf(ran_flag) self.failUnless(m.a == 5)
def setUp(self): cells.reset() self.a_ran = False class MyModel(cells.Model): x = cells.makecell(value=5) @cells.fun2cell() def a(modelself, prev): self.a_ran = True return modelself.x + modelself.offset def __init__(self, *args, **kwargs): self.offset = 1 cells.Model.__init__(self, *args, **kwargs) self.M = MyModel
def setUp(self): cells.reset() self.a_ran = False class MyModel(cells.Model): x = cells.makecell(value=5) @cells.fun2cell() def a(modelself, prev): self.a_ran = True return modelself.x + modelself.offset def __init__(self, *args, **kwargs): self.offset = 1 cells.Model.__init__(self, *args, **kwargs) self.M = MyModel
def setUp(self): # h i j # | | | # v v v # a --> b --> c # | | # \-- > x <---/ cells.reset() self.runlog = [] self.x = cells.Cell(None, name="x", value=5) def anon_rule(name, getfrom): def rule(s, p): self.runlog.append(name) return getfrom.getvalue() + (p or 0) return rule self.c = cells.Cell(None, name="c", rule=anon_rule('c', self.x)) self.b = cells.Cell(None, name="b", rule=anon_rule('b', self.c)) def a_rule(s, p): self.runlog.append("a") return self.b.getvalue() + self.x.getvalue() + (p or 0) self.a = cells.Cell(None, name="a", rule=a_rule) self.h = cells.Cell(None, name="h", rule=anon_rule('h', self.a)) self.i = cells.Cell(None, name="i", rule=anon_rule('i', self.b)) self.j = cells.Cell(None, name="j", rule=anon_rule('j', self.c)) # build dependencies self.h.getvalue() self.i.getvalue() self.j.getvalue() self.runlog = [] # run an x.set(3) in the desired order: self.x.propogation_list = lambda s, e: [self.a, self.c] self.c.propogation_list = lambda s, e: [self.b, self.j] self.b.propogation_list = lambda s, e: [self.a, self.i] self.x.set(3)
def setUp(self): # h i j # | | | # v v v # a --> b --> c # | | # \-- > x <---/ cells.reset() self.runlog = [] self.x = cells.Cell(None, name="x", value=5) def anon_rule(name, getfrom): def rule(s,p): self.runlog.append(name) return getfrom.getvalue() + (p or 0) return rule self.c = cells.Cell(None, name="c", rule=anon_rule('c', self.x)) self.b = cells.Cell(None, name="b", rule=anon_rule('b', self.c)) def a_rule(s,p): self.runlog.append("a") return self.b.getvalue() + self.x.getvalue() + (p or 0) self.a = cells.Cell(None, name="a", rule=a_rule) self.h = cells.Cell(None, name="h", rule=anon_rule('h', self.a)) self.i = cells.Cell(None, name="i", rule=anon_rule('i', self.b)) self.j = cells.Cell(None, name="j", rule=anon_rule('j', self.c)) # build dependencies self.h.getvalue() self.i.getvalue() self.j.getvalue() self.runlog = [] # run an x.set(3) in the desired order: self.x.propogation_list = lambda s,e: [ self.a, self.c ] self.c.propogation_list = lambda s,e: [ self.b, self.j ] self.b.propogation_list = lambda s,e: [ self.a, self.i ] self.x.set(3)
def setUp(self): cells.reset() self.observerlog = [] class MyModel(cells.Model): x = cells.makecell(value=5) a = cells.makecell(rule=lambda s,p: int(s.x) + s.offset) offset = 2 # observes whole model @MyModel.observer() def model_obs(model): self.observerlog.append("model") # observes an input cell instance @MyModel.observer(attrib="x") def incell_obs(model): self.observerlog.append("x") # observes a rule cell instance @MyModel.observer(attrib="a") def rulecell_obs(model): self.observerlog.append("a") # observes a non-cell instance @MyModel.observer(attrib="offset") def noncell_obs(model): self.observerlog.append("offset") # observe an old value type @MyModel.observer(oldvalue=lambda v: type(v) == type(1)) def oldval_obs(model): self.observerlog.append("oldval") # observe a new value type @MyModel.observer(newvalue=lambda v: type(v) == type(1.0)) def newval_obs(model): self.observerlog.append("newval") self.M = MyModel self.m = MyModel() # this will test the very basics
def setUp(self): cells.reset() self.observerlog = [] class MyModel(cells.Model): x = cells.makecell(value=5) a = cells.makecell(rule=lambda s, p: int(s.x) + s.offset) offset = 2 # observes whole model @MyModel.observer() def model_obs(model): self.observerlog.append("model") # observes an input cell instance @MyModel.observer(attrib="x") def incell_obs(model): self.observerlog.append("x") # observes a rule cell instance @MyModel.observer(attrib="a") def rulecell_obs(model): self.observerlog.append("a") # observes a non-cell instance @MyModel.observer(attrib="offset") def noncell_obs(model): self.observerlog.append("offset") # observe an old value type @MyModel.observer(oldvalue=lambda v: type(v) == type(1)) def oldval_obs(model): self.observerlog.append("oldval") # observe a new value type @MyModel.observer(newvalue=lambda v: type(v) == type(1.0)) def newval_obs(model): self.observerlog.append("newval") self.M = MyModel self.m = MyModel() # this will test the very basics
def setUp(self): cells.reset() self.x = cells.Cell(None, name="x", value=1) self.b = cells.Cell(None, name="b", rule=lambda s,p: (p or 40) + 2) self.a = cells.Cell(None, name="a", rule=lambda s,p: self.b.getvalue() * self.x.getvalue())
def setUp(self): cells.reset()
def test_1a_Nonsettability(self): "Rule 1: Rule cells may not be set" cells.reset() x = cells.RuleCell(None, lambda s,p: 0, name="x") self.failUnlessRaises(cells.RuleCellSetError, x.set, 5)
def setUp(self): cells.reset() self.x = cells.InputCell(None, 5, name="x")
def setUp(self): cells.reset() self.x = cells.DictCell(None, name="x")
def setUp(self): cells.reset() self.x = cells.InputCell(None, 5, name="x")
def test_1a_Nonsettability(self): "Rule 1: Rule cells may not be set" cells.reset() x = cells.RuleCell(None, lambda s, p: 0, name="x") self.failUnlessRaises(cells.RuleCellSetError, x.set, 5)
def setUp(self): cells.reset() self.x = cells.Cell(None, name="x", value=21)
def setUp(self): cells.reset()
def setUp(self): cells.reset() self.x = cells.Cell(None, name="x", value=21)
def setUp(self): cells.reset() self.x = cells.DictCell(None, name="x")