def test_top(self): key = "foo" context = Context({key: "bar"}, {key: "buzz"}) self.assertEquals(context.get(key), "buzz") top = context.top() self.assertEquals(top, {"foo": "buzz"}) # Make sure calling top() didn't remove the item from the stack. self.assertEquals(context.get(key), "buzz")
def test_top(self): key = "foo" context = Context({key: "bar"}, {key: "buzz"}) self.assertEqual(context.get(key), "buzz") top = context.top() self.assertEqual(top, {"foo": "buzz"}) # Make sure calling top() didn't remove the item from the stack. self.assertEqual(context.get(key), "buzz")
def test_push(self): """ Test push(). """ key = "foo" context = Context({key: "bar"}) self.assertEqual(context.get(key), "bar") context.push({key: "buzz"}) self.assertEqual(context.get(key), "buzz")
def test_push(self): """ Test push(). """ key = "foo" context = Context({key: "bar"}) self.assertEquals(context.get(key), "bar") context.push({key: "buzz"}) self.assertEquals(context.get(key), "buzz")
def test_pop(self): """ Test pop(). """ key = "foo" context = Context({key: "bar"}, {key: "buzz"}) self.assertEqual(context.get(key), "buzz") item = context.pop() self.assertEqual(item, {"foo": "buzz"}) self.assertEqual(context.get(key), "bar")
def test_pop(self): """ Test pop(). """ key = "foo" context = Context({key: "bar"}, {key: "buzz"}) self.assertEquals(context.get(key), "buzz") item = context.pop() self.assertEquals(item, {"foo": "buzz"}) self.assertEquals(context.get(key), "bar")
def test_copy(self): key = "foo" original = Context({key: "bar"}, {key: "buzz"}) self.assertEquals(original.get(key), "buzz") new = original.copy() # Confirm that the copy behaves the same. self.assertEquals(new.get(key), "buzz") # Change the copy, and confirm it is changed. new.pop() self.assertEquals(new.get(key), "bar") # Confirm the original is unchanged. self.assertEquals(original.get(key), "buzz")
def test_copy(self): key = "foo" original = Context({key: "bar"}, {key: "buzz"}) self.assertEqual(original.get(key), "buzz") new = original.copy() # Confirm that the copy behaves the same. self.assertEqual(new.get(key), "buzz") # Change the copy, and confirm it is changed. new.pop() self.assertEqual(new.get(key), "bar") # Confirm the original is unchanged. self.assertEqual(original.get(key), "buzz")
def test_get__fallback(self): """ Check that first-added stack items are queried on context misses. """ context = Context({"fuzz": "buzz"}, {"foo": "bar"}) self.assertEqual(context.get("fuzz"), "buzz")
def test_get__precedence(self): """ Test that get() respects the order of precedence (later items first). """ context = Context({"foo": "bar"}, {"foo": "buzz"}) self.assertEqual(context.get("foo"), "buzz")
def test_get__default(self): """ Test that get() respects the default value. """ context = Context() self.assertEqual(context.get("foo", "bar"), "bar")
def test_get__key_missing(self): """ Test getting a missing key. """ context = Context() self.assertTrue(context.get("foo") is None)
def test_get__fallback(self): """ Check that first-added stack items are queried on context misses. """ context = Context({"fuzz": "buzz"}, {"foo": "bar"}) self.assertEquals(context.get("fuzz"), "buzz")
def test_get__precedence(self): """ Test that get() respects the order of precedence (later items first). """ context = Context({"foo": "bar"}, {"foo": "buzz"}) self.assertEquals(context.get("foo"), "buzz")
def test_get__default(self): """ Test that get() respects the default value . """ context = Context() self.assertEquals(context.get("foo", "bar"), "bar")
def test_get__key_present(self): """ Test getting a key. """ context = Context({"foo": "bar"}) self.assertEqual(context.get("foo"), "bar")
def test_get__key_present(self): """ Test getting a key. """ context = Context({"foo": "bar"}) self.assertEquals(context.get("foo"), "bar")