]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
graph: fix sort for py3
authorJoe Guo <joeg@catalyst.net.nz>
Tue, 10 Apr 2018 03:51:34 +0000 (15:51 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 13 Apr 2018 05:27:13 +0000 (07:27 +0200)
`sorted` can not sort `None` with str in py3, use the `key` arg to fix.
Sort None as ''.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/tests/graph.py

index 0a95afb1859723272d9b48cce89b96b017b6a80f..2193d4222400233805bd12d91b44d51a684fd49d 100644 (file)
@@ -101,6 +101,15 @@ class DotFileTests(samba.tests.TestCaseInTempDir):
 
 
 class DistanceTests(samba.tests.TestCase):
+
+    def setUp(self):
+        super(DistanceTests, self).setUp()
+        # a sorted list of colour set names.
+        self.sorted_colour_sets = sorted(
+            graph.COLOUR_SETS,
+            # return '' for None, so it's sortable.
+            key=lambda name: name or '')
+
     def test_simple_distance(self):
         edges = [('ant', 'bat'),
                  ('cat', 'dog'),
@@ -115,7 +124,7 @@ class DistanceTests(samba.tests.TestCase):
                  ('cat', 'dog')]
 
         for utf8 in (True, False):
-            for colour in sorted(graph.COLOUR_SETS):
+            for colour in self.sorted_colour_sets:
                 print('utf8 %s, colour %s' % (utf8, colour))
                 s = graph.distance_matrix(None, edges, utf8=utf8,
                                           colour=colour)
@@ -129,7 +138,7 @@ class DistanceTests(samba.tests.TestCase):
                  ('ant', 'cat')]
 
         for utf8 in (True, False):
-            for colour in sorted(graph.COLOUR_SETS):
+            for colour in self.sorted_colour_sets:
                 print('utf8 %s, colour %s' % (utf8, colour))
                 s = graph.distance_matrix(None, edges, utf8=utf8,
                                           colour=colour)
@@ -144,7 +153,7 @@ class DistanceTests(samba.tests.TestCase):
                  ('dog', 'eel')]
 
         for utf8 in (True, False):
-            for colour in sorted(graph.COLOUR_SETS):
+            for colour in self.sorted_colour_sets:
                 print('utf8 %s, colour %s' % (utf8, colour))
                 s = graph.distance_matrix(None, edges, utf8=utf8,
                                           colour=colour)