From: Joe Guo Date: Tue, 10 Apr 2018 03:51:34 +0000 (+1200) Subject: graph: fix sort for py3 X-Git-Tag: ldb-1.4.0~590 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6d696d61dd2b3eb144a2ccabb0f7e2cd974959b7;p=thirdparty%2Fsamba.git graph: fix sort for py3 `sorted` can not sort `None` with str in py3, use the `key` arg to fix. Sort None as ''. Signed-off-by: Joe Guo Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/tests/graph.py b/python/samba/tests/graph.py index 0a95afb1859..2193d422240 100644 --- a/python/samba/tests/graph.py +++ b/python/samba/tests/graph.py @@ -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)