Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wichert committed Nov 16, 2007
1 parent 7c346e5 commit b5f00b6
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
96 changes: 96 additions & 0 deletions bicop/tests/testNestedDict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import operator
from unittest import TestCase
from bicop.nestdict import NestedDict

class NestedDictTests(TestCase):
def testEmptyConstructor(self):
n=NestedDict()
self.assertEqual(n.keys(), [])

def testFlatCopyConstructor(self):
n=NestedDict(dict(one="one"))
self.assertEqual(n.items(), [("one", "one")])

def testNestedCopyConstructor(self):
n=NestedDict(dict(one=dict(two="two")))
self.assertEqual(n.items(), [("one", dict(two="two"))])

def testDirectGetItem(self):
n=NestedDict(dict(one="one"))
self.assertEqual(n["one"], "one")

def testDeepDirectGetItem(self):
n=NestedDict(dict(one=dict(two="two")))
self.assertEqual(n["one"]["two"], "two")

def testDeepSmartGetItem(self):
n=NestedDict(dict(one=dict(two="two")))
self.assertEqual(n["one/two"], "two")

def testDeepSmartGetItemWithDifferentSeparator(self):
n=NestedDict(dict(one=dict(two="two")), separator=":")
self.assertEqual(n["one:two"], "two")

def testGetItemReturnsNestedDict(self):
n=NestedDict(dict(one=dict(two="two")))
self.failUnless(isinstance(n["one"], NestedDict))

def testDirectHasKey(self):
n=NestedDict(dict(one=dict(two="two")))
self.failUnless(n.has_key("one"))

def testDeepHasKey(self):
n=NestedDict(dict(one=dict(two="two")))
self.failUnless(n.has_key("one/two"))
self.failUnless(not n.has_key("one/one"))

def testDeepHasKeyWithDifferentSeparator(self):
n=NestedDict(dict(one=dict(two="two")), separator=":")
self.failUnless(n.has_key("one:two"))
self.failUnless(not n.has_key("one:one"))

def testDirectDelItem(self):
n=NestedDict(dict(one=dict(two="two")))
del n["one"]
self.assertEqual(n.keys(), [])

def testRemoveShallowMissingItem(self):
n=NestedDict(dict(one=dict(two="two")))
self.assertRaises(KeyError, operator.__delitem__, n, "two/three")

def testRemoveDeepMissingItem(self):
n=NestedDict(dict(one=dict(two="two")))
self.assertRaises(KeyError, operator.__delitem__, n, "one/three")

def testDeepDelItem(self):
n=NestedDict(dict(one=dict(two="two")))
del n["one"]["two"]
self.assertEqual(n.keys(), ["one"])
self.assertEqual(n["one"].keys(), [])

def testSmartDeepDelItem(self):
n=NestedDict(dict(one=dict(two="two")))
del n["one/two"]
self.assertEqual(n.keys(), ["one"])
self.assertEqual(n["one"].keys(), [])

def testSmartDeepDelItemWithDifferentSeparator(self):
n=NestedDict(dict(one=dict(two="two")), separator=":")
del n["one:two"]
self.assertEqual(n.keys(), ["one"])
self.assertEqual(n["one"].keys(), [])

def testSetItem(self):
n=NestedDict()
n["one"]=1
self.assertEqual(n["one"], 1)

def testSetDeepItem(self):
n=NestedDict()
n["one/two"]=1
self.assertEqual(n["one"]["two"], 1)

def testSetDeepItemWithDifferentSeperator(self):
n=NestedDict(separator=":")
n["one:two"]=1
self.assertEqual(n["one"]["two"], 1)
2 changes: 1 addition & 1 deletion bicop/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def merge(one, two, overwrite=False, typecheck=True):
return

if typecheck and not same_type(one, two):
raise ValuError, "Type mismatch"
raise ValueError, "Type mismatch"

for (key,value) in two.items():
if key not in one:
Expand Down

0 comments on commit b5f00b6

Please sign in to comment.