def testGetNextMemoryAddressWithParentContext(self): parent = Context() context = Context(parent) address0 = toMemoryAddress(0) address1 = toMemoryAddress(1) address2 = toMemoryAddress(2) address3 = toMemoryAddress(3) self.assertEqual(address0, context.getNextAddress()) parent.varsByAddress[address0] = Variable("var1", address0, Context()) self.assertEqual(address1, context.getNextAddress()) parent.varsByAddress[address2] = Variable("var2", address2, Context()) self.assertEqual(address1, context.getNextAddress()) parent.varsByAddress[address1] = Variable("var3", address1, Context()) self.assertEqual(address3, context.getNextAddress()) del parent.varsByAddress[address0] self.assertEqual(address0, context.getNextAddress())
def testDestroyWithoutParent(self): context = Context() result = context.getVariable("var1") context.destroy() self.assertEqual(result, context.getVariable("var1"))
def testDestroyAtMultipleLevels(self): root = Context() context1 = Context(root) context2 = Context(context1) result = context2.getVariable("var2") context2.destroy() self.assertFalse(result == context2.getVariable("var2"))
def testGetVariableWithParentContext(self): parent = Context() context = Context(parent) result1 = parent.getVariable("var1") result2 = context.getVariable("var1") result3 = context.getVariable("var2") result4 = parent.getVariable("var2") self.assertTrue(result1 == result2) self.assertFalse(result3 == result4)
def testGetVariableWithoutParentContext(self): context = Context() result1 = context.getVariable("var1") result2 = context.getVariable("var2") result3 = context.getVariable("var1") for result in [result1, result2, result3]: self.assertFalse(result is None) self.assertTrue(result1 == result3) self.assertTrue(result1 != result2)
def testDestroyWithParent(self): parent = Context() context = Context(parent) result1 = parent.getVariable("var1") result2 = context.getVariable("var2") context.destroy() self.assertTrue(result1 == parent.getVariable("var1")) self.assertFalse(result2 == context.getVariable("var2"))
def testStartChildContextProducesContextWithCurrentContextAsParent(self): parent = Context() child = parent.startChildContext() self.assertEqual(parent, child.parent)