[damned-lies] Fixed sorting crash in Statistics.get_lang_stats_by_type
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Fixed sorting crash in Statistics.get_lang_stats_by_type
- Date: Thu, 23 Feb 2017 19:48:56 +0000 (UTC)
commit e7aec1d512fadff88d4c64601f633d41937697e2
Author: Claude Paroz <claude 2xlibre net>
Date: Thu Feb 23 20:48:16 2017 +0100
Fixed sorting crash in Statistics.get_lang_stats_by_type
stats/models.py | 5 +++--
stats/tests/tests.py | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index d2f54a7..86212a4 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -16,14 +16,15 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
-from collections import Counter, OrderedDict
import fnmatch
import logging
import os, sys, re
import shutil
import threading
+from collections import Counter, OrderedDict
from datetime import datetime
from functools import total_ordering
+from operator import itemgetter
from time import sleep
from urllib import request
from urllib.error import URLError
@@ -1717,7 +1718,7 @@ class Statistics(models.Model):
# Sort domains
for mod in categ['modules'].values():
for branch, doms in mod.items():
- doms.sort()
+ doms.sort(key=itemgetter(0))
# Sort errors
stats['all_errors'].sort()
return stats
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 3b8cc37..025cfcb 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -494,6 +494,29 @@ class StatisticsTests(TestCase):
self.assertEqual(stats['it']['diff'], 24)
self.assertEqual(stats['it']['stats'], [63, 87])
+ def test_get_lang_stats_by_type(self):
+ mod = Module.objects.get(name='zenity')
+ lang = Language.objects.get(locale='fr')
+ dom = Domain.objects.create(
+ module=mod, name='po2', dtype='ui', description='UI Translations'
+ )
+ branch = mod.branch_set.get(name='gnome-3-8')
+ # Add one more stat so as comparison happens on two real stat objects
+ Statistics.objects.create(
+ branch=branch,
+ domain=dom,
+ language=None
+ )
+ stats = Statistics.get_lang_stats_by_type(
+ lang, 'ui', Release.objects.get(name="gnome-3-8")
+ )
+ for key, value in {
+ 'total': 183, 'totaltrans': 183, 'totalfuzzy': 0, 'totaluntrans': 0,
+ 'totaltransperc': 100, 'totalfuzzyperc': 0, 'totaluntransperc': 0,
+ 'dtype': 'ui', 'all_errors': []
+ }.items():
+ self.assertEqual(stats[key], value)
+
def _test_update_statistics(self):
# Temporarily deactivated, since update_stats cannot receive stats any more
from vertimus.models import State, StateTranslating
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]