def test(): # for the locators import pyre.tracking # get the constructor from pyre.framework.Slot import Slot # build a few slots var = Slot.variable(key=None, value=None) one = Slot.variable(key=None, value=1) two = Slot.variable(key=None, value=2) three = one + two double = var + var # check that {var} has no value assert var.value is None # set it to {two) var.value = two.value # check that the cache has the right value assert var._value == 2 # and that {var} knows it assert var.value == 2 # and that double got updated assert double.value == 2 * var.value # verify {three} can compute correctly assert three.value == 3 # now, replace {var} by {three} in {double} three.replace(var) # check all expected invariants # operands assert len(tuple(one.operands)) == 0 assert len(tuple(two.operands)) == 0 assert len(tuple(var.operands)) == 0 assert len(tuple(three.operands)) == 2 assert identical(three.operands, [one, two]) assert len(tuple(double.operands)) == 2 assert identical(double.operands, [three, three]) # observers assert len(tuple(one.observers)) == 1 assert identical(one.observers, [three]) assert len(tuple(two.observers)) == 1 assert identical(two.observers, [three]) assert len(tuple(var.observers)) == 0 assert len(tuple(three.observers)) == 1 assert identical(three.observers, [double]) assert len(tuple(double.observers)) == 0 # all done return var, double
def test(): # for the locator import pyre.tracking # get the constructor from pyre.framework.Slot import Slot # build a few slots zero = Slot.variable(key=None, value=0) one = Slot.variable(key=None, value=1) two = Slot.variable(key=None, value=2) # verify their values assert zero.value == 0 assert one.value == 1 assert two.value == 2 # add them s = one + two # check that the new slot has an invalid cache assert s._value is None # force it to evaluate assert s.value == 3 # check that the cache has been updated properly assert s._value == 3 # check that variables have no operands assert len(tuple(zero.operands)) == 0 assert len(tuple(one.operands)) == 0 assert len(tuple(two.operands)) == 0 # check that {zero} has no observers assert len(tuple(zero.observers)) == 0 # but {one} and {two} have one each assert len(tuple(one.observers)) == 1 assert len(tuple(two.observers)) == 1 # the right one assert identical(one.observers, [s]) assert identical(two.observers, [s]) # check that {s} has two operands assert len(tuple(s.operands)) == 2 assert identical(s.operands, [one, two]) # all done return zero, one, two, s
def test(): # for the locator import pyre.tracking # get the constructor from pyre.framework.Slot import Slot # build a few slots zero = Slot.variable(key=None, value=0) one = Slot.variable(key=None, value=1) two = Slot.variable(key=None, value=2) # verify their values assert zero.value == 0 assert one.value == 1 assert two.value == 2 # add them s = one + two # check that the new slot has an invalid cache assert s._cache is None # force it to evaluate assert s.value == 3 # check that the cache has been updated properly assert s._cache == 3 # check that variables have no operands assert len(tuple(zero.operands)) == 0 assert len(tuple(one.operands)) == 0 assert len(tuple(two.operands)) == 0 # check that {zero} has no observers assert len(tuple(zero.observers)) == 0 # but {one} and {two} have one each assert len(tuple(one.observers)) == 1 assert len(tuple(two.observers)) == 1 # the right one assert identical(one.observers, [s]) assert identical(two.observers, [s]) # check that {s} has two operands assert len(tuple(s.operands)) == 2 assert identical(s.operands, [one, two]) # all done return zero, one, two, s
def test(): # for the locator import pyre.tracking # get the slot class from pyre.framework.Slot import Slot # make a key key = None # and a value value = 4 # make a slot return Slot.variable(key=key, value=value)