def test_pop_item_with_default(self): d = NamespaceDict({"/foo/bar": "baz", "/foo/baz": "bar"}) popped_val = d.pop("/foo/baz/", "foobar") self.assertEqual("bar", popped_val) self.assertDictEqual({"/foo/bar": "baz"}, d) self.assertEqual(3, len(d)) self.assertTrue("foobar", d.pop("/foo/baz/", "foobar")) self.assertEqual(3, len(d))
def test_pop_item_with_default(self): d = NamespaceDict({'/foo/bar': 'baz', '/foo/baz': 'bar'}) popped_val = d.pop('/foo/baz/', 'foobar') self.assertEqual('bar', popped_val) self.assertDictEqual({'/foo/bar': 'baz'}, d) self.assertEqual(3, len(d)) self.assertTrue('foobar', d.pop('/foo/baz/', 'foobar')) self.assertEqual(3, len(d))
def test_pop_everything(self): d = NamespaceDict({"/foo/bar": "baz"}) popped_val = d.pop("/") self.assertEqual(1, len(d)) self.assertIsInstance(popped_val, NamespaceDict) self.assertDictEqual({"/foo/bar": "baz"}, popped_val) self.assertDictEqual({}, d) self.assertSetEqual(set(["/"]), d.keys())
def test_pop_item(self): d = NamespaceDict({"/foo/bar": "baz", "/foo/baz": "bar"}) val = d.pop("/foo/bar/") self.assertEqual("baz", val) self.assertDictEqual({"/foo/baz": "bar"}, d) self.assertSetEqual(set(["/", "/foo", "/foo/baz"]), d.keys()) self.assertEqual(3, len(d)) val = d.pop("/foo/baz") self.assertEqual("bar", val) self.assertDictEqual({}, d) self.assertEqual(1, len(d)) val = d.pop("/foo", "foobar") self.assertEqual("foobar", val) self.assertDictEqual({}, d) self.assertEqual(1, len(d))
def test_pop_everything(self): d = NamespaceDict({'/foo/bar': 'baz'}) popped_val = d.pop('/') self.assertEqual(1, len(d)) self.assertIsInstance(popped_val, NamespaceDict) self.assertDictEqual({'/foo/bar': 'baz'}, popped_val) self.assertDictEqual({}, d) self.assertSetEqual(set(['/']), d.keys())
def test_pop_item(self): d = NamespaceDict({'/foo/bar': 'baz', '/foo/baz': 'bar'}) val = d.pop('/foo/bar/') self.assertEqual('baz', val) self.assertDictEqual({'/foo/baz': 'bar'}, d) self.assertSetEqual(set(['/', '/foo', '/foo/baz']), d.keys()) self.assertEqual(3, len(d)) val = d.pop('/foo/baz') self.assertEqual('bar', val) self.assertDictEqual({}, d) self.assertEqual(1, len(d)) val = d.pop('/foo', 'foobar') self.assertEqual('foobar', val) self.assertDictEqual({}, d) self.assertEqual(1, len(d))
def test_deep_names(self): d = NamespaceDict() d["/f/o/o/b/a/r"] = "baz" d["/f/o/o/b/a/z"] = "bar" self.assertEqual(8, len(d)) d["/b/a/z/b/a/r"] = "foo" self.assertEqual(14, len(d)) popped_val = d.pop("/f/o/o/") self.assertDictEqual({"/b/a/r": "baz", "/b/a/z": "bar"}, popped_val) self.assertEqual(5, len(popped_val)) self.assertDictEqual({"/b/a/z/b/a/r": "foo"}, d) self.assertEqual(7, len(d))
def test_deep_names(self): d = NamespaceDict() d['/f/o/o/b/a/r'] = 'baz' d['/f/o/o/b/a/z'] = 'bar' self.assertEqual(8, len(d)) d['/b/a/z/b/a/r'] = 'foo' self.assertEqual(14, len(d)) popped_val = d.pop('/f/o/o/') self.assertDictEqual({'/b/a/r': 'baz', '/b/a/z': 'bar'}, popped_val) self.assertEqual(5, len(popped_val)) self.assertDictEqual({'/b/a/z/b/a/r': 'foo'}, d) self.assertEqual(7, len(d))