Skip to content

Commit be3d65f

Browse files
committed
Unit tests fixed.
1 parent 9b781e3 commit be3d65f

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

cluster/test/test_hierarchical.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,19 @@
1515
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1616
#
1717

18-
import unittest
18+
"""
19+
Tests for hierarchical clustering.
20+
21+
.. note::
22+
23+
Even though the results are lists, the order of items in the resulting
24+
clusters is non-deterministic. This should be taken into consideration when
25+
writing "expected" values!
26+
"""
27+
1928
from difflib import SequenceMatcher
29+
from sys import hexversion
30+
import unittest
2031

2132
from cluster import HierarchicalClustering
2233

@@ -26,13 +37,20 @@ class HClusterSmallListTestCase(unittest.TestCase):
2637
Test for Bug #1516204
2738
"""
2839

40+
def __init__(self, *args, **kwargs):
41+
super(HClusterSmallListTestCase, self).__init__(*args, **kwargs)
42+
if hexversion < 0x030000f0:
43+
self.assertCItemsEqual = self.assertItemsEqual
44+
else:
45+
self.assertCItemsEqual = self.assertCountEqual
46+
2947
def testClusterLen1(self):
3048
"""
3149
Testing if hierarchical clustering a set of length 1 returns a set of
3250
length 1
3351
"""
3452
cl = HierarchicalClustering([876], lambda x, y: abs(x - y))
35-
self.assertEqual([876], cl.getlevel(40))
53+
self.assertCItemsEqual([876], cl.getlevel(40))
3654

3755
def testClusterLen0(self):
3856
"""
@@ -44,6 +62,13 @@ def testClusterLen0(self):
4462

4563
class HClusterIntegerTestCase(unittest.TestCase):
4664

65+
def __init__(self, *args, **kwargs):
66+
super(HClusterIntegerTestCase, self).__init__(*args, **kwargs)
67+
if hexversion < 0x030000f0:
68+
self.assertCItemsEqual = self.assertItemsEqual
69+
else:
70+
self.assertCItemsEqual = self.assertCountEqual
71+
4772
def setUp(self):
4873
self.__data = [791, 956, 676, 124, 564, 84, 24, 365, 594, 940, 398,
4974
971, 131, 365, 542, 336, 518, 835, 134, 391]
@@ -54,15 +79,15 @@ def testSingleLinkage(self):
5479
result = cl.getlevel(40)
5580

5681
# sort the values to make the tests less prone to algorithm changes
57-
result = sorted([sorted(_) for _ in result])
58-
self.assertEqual([
82+
result = [sorted(_) for _ in result]
83+
self.assertCItemsEqual([
5984
[24],
60-
[84, 124, 131, 134],
6185
[336, 365, 365, 391, 398],
6286
[518, 542, 564, 594],
6387
[676],
6488
[791],
6589
[835],
90+
[84, 124, 131, 134],
6691
[940, 956, 971],
6792
], result)
6893

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[pytest]
22
looponfailroots = cluster
3-
norecursedirs = env env3 .git
3+
norecursedirs = env env3 env3_nonumpy .git

0 commit comments

Comments
 (0)