Skip to content

Commit f1aa4fe

Browse files
author
Kevin Turner
committed
[project @ oidutil.Symbol.__hash__: define]
(deepcopy really does break everything. You can have d.keys() == deepcopy(d).keys() without d[s] == deepcopy(d)[s])
1 parent 956192f commit f1aa4fe

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎openid/oidutil.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,8 @@ def __eq__(self, other):
9595
def __ne__(self, other):
9696
return not (self == other)
9797

98+
def __hash__(self):
99+
return hash((self.__class__, self.name))
100+
98101
def __repr__(self):
99102
return '<Symbol %s>' % (self.name,)

‎openid/test/oidutil.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ def runTest(self):
5353
def shortDescription(self):
5454
return self.desc
5555

56+
57+
58+
class TestSymbol(unittest.TestCase):
59+
def testCopyHash(self):
60+
import copy
61+
s = oidutil.Symbol("Foo")
62+
d = {s: 1}
63+
d_prime = copy.deepcopy(d)
64+
self.failUnless(s in d_prime, "%r isn't in %r" % (s, d_prime))
65+
66+
t = oidutil.Symbol("Bar")
67+
self.failIfEqual(hash(s), hash(t))
68+
69+
5670
def buildAppendTests():
5771
simple = 'http://www.example.com/'
5872
cases = [
@@ -138,10 +152,13 @@ def buildAppendTests():
138152
return unittest.TestSuite(tests)
139153

140154
def pyUnitTests():
141-
return buildAppendTests()
155+
some = buildAppendTests()
156+
some.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestSymbol))
157+
return some
142158

143159
def test_appendArgs():
144160
suite = buildAppendTests()
161+
suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestSymbol))
145162
runner = unittest.TextTestRunner()
146163
result = runner.run(suite)
147164
assert result.wasSuccessful()

0 commit comments

Comments
 (0)