Skip to content

Commit 58ad887

Browse files
Added test class for issue 28, which runs OK under Python2.7 but throws an exception under Python3.5 (both on macOS).
As well as adding the test class, this commit turns on DEBUG level logging, which makes it easier to spot the point at which the behaviour of the two versions diverge.
1 parent a898bf2 commit 58ad887

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

cluster/test/test_hierarchical.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,42 @@ def euclidian_distance(a, b):
231231
result = cl.getlevel(40)
232232
self.assertIsNotNone(result)
233233

234+
class Issue28TestCase(Py23TestCase):
235+
'''
236+
Test case to cover the case where the data consist
237+
of dictionary keys, and the distance function executes
238+
on the values these keys are associated with in the
239+
dictionary, rather than the keys themselves.
240+
241+
Behaviour for this test case differs between Python2.7
242+
and Python3.5: on 2.7 the test behaves as expected,
243+
244+
See Github issue #28.
245+
'''
246+
247+
def testIssue28(self):
248+
"Issue28 (Hierarchical Clustering)"
234249

250+
points1D = {
251+
'p4' : 5, 'p2' : 6, 'p7' : 10,
252+
'p9' : 120, 'p10' : 121, 'p11' : 119,
253+
}
254+
255+
distance_func = lambda a,b : abs(points1D[a]-points1D[b])
256+
cl = HierarchicalClustering(list(points1D.keys()), distance_func)
257+
result = cl.getlevel(20)
258+
self.assertIsNotNone(result)
259+
235260
if __name__ == '__main__':
261+
262+
import logging
263+
236264
suite = unittest.TestSuite((
237265
unittest.makeSuite(HClusterIntegerTestCase),
238266
unittest.makeSuite(HClusterSmallListTestCase),
239267
unittest.makeSuite(HClusterStringTestCase),
268+
unittest.makeSuite(Issue28TestCase),
240269
))
241270

271+
logging.basicConfig(level=logging.DEBUG)
242272
unittest.TextTestRunner(verbosity=2).run(suite)

0 commit comments

Comments
 (0)