[damned-lies] Fixed object sortability on Python 3
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Fixed object sortability on Python 3
- Date: Wed, 22 Feb 2017 13:45:00 +0000 (UTC)
commit 9d04bdc18e17108374f65edd628f38b17ad74c02
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Feb 22 14:44:28 2017 +0100
Fixed object sortability on Python 3
stats/models.py | 8 ++++----
stats/tests/tests.py | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index c3f5ddb..1e092af 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -101,8 +101,8 @@ class Module(models.Model):
def __str__(self):
return self.name
- def __cmp__(self, other):
- return cmp(self.name, other.name)
+ def __lt__(self, other):
+ return self.name < other.name
def get_absolute_url(self):
return reverse('module', args=[self.name])
@@ -1867,8 +1867,8 @@ class Information(models.Model):
info_dict[info.statistics_id] = [info]
return info_dict
- def __cmp__(self, other):
- return cmp(self.statistics.module_name, other.statistics.module_name)
+ def __lt__(self, other):
+ return self.statistics.module_name < other.statistics.module_name
def get_icon(self):
return "%simg/%s.png" % (settings.STATIC_URL, self.type.split("-")[0])
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 08e121b..0139951 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -34,6 +34,7 @@ from django.test import TestCase
from stats.models import (
Module, Domain, Branch, Release, CategoryName, Statistics, FakeLangStatistics,
+ Information,
)
from stats import utils
from languages.models import Language
@@ -115,6 +116,10 @@ class ModuleTestCase(TestCase):
def test_module_methods(self):
self.assertEqual(self.mod.get_description(), 'gnome-hello')
+ def test_module_comparable(self):
+ modules = [Module.objects.get(name='zenity'), Module.objects.get(name='gnome-hello')]
+ self.assertEqual(sorted(modules)[0].name, 'gnome-hello')
+
def test_modules_list(self):
response = self.client.get(reverse('modules'))
self.assertContains(response, '<li><a href="/module/zenity/">zenity</a></li>')
@@ -507,6 +512,21 @@ class StatisticsTests(TestCase):
self.assertEqual(len(state), 1)
self.assertTrue(isinstance(state[0], StateTranslating))
+ def test_information_comparable(self):
+ infos = [
+ Information.objects.create(
+ statistics=Statistics.objects.filter(branch__module__name='zenity').first(),
+ type='info',
+ description="Some information",
+ ),
+ Information.objects.create(
+ statistics=Statistics.objects.filter(branch__module__name='gnome-hello').first(),
+ type='info',
+ description="Other information",
+ ),
+ ]
+ self.assertEqual(sorted(infos)[0].statistics.branch.module.name, 'gnome-hello')
+
class FigureTests(TestCase):
fixtures = ['sample_data.json']
def test_figure_view(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]