[damned-lies] Fix and test Domain.get_linguas



commit d183474f445d391d431cce1a7004a94adf0ef98f
Author: Claude Paroz <claude 2xlibre net>
Date:   Fri Mar 30 12:30:19 2018 +0200

    Fix and test Domain.get_linguas

 stats/models.py      |    4 ++--
 stats/tests/tests.py |   22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 77eb135..042bee3 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -958,9 +958,9 @@ class Domain(models.Model):
                     file_path, variable = self.linguas_location.split("#")
                 else:
                     file_path = self.linguas_location
-                linguas_file = utils.MakefileWrapper(base_path / file_path)
+                linguas_file = utils.MakefileWrapper(branch, base_path / file_path)
                 langs = linguas_file.read_variable(variable)
-                return {'langs': langs,
+                return {'langs': langs.split() if langs is not None else None,
                         'error': ugettext_noop("Entry for this language is not present in %(var)s variable 
in %(file)s file." % {
                             'var': variable, 'file': file_path})}
         # Standard linguas location
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 73f4036..5013346 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -119,6 +119,28 @@ class ModuleTestCase(TestCase):
         help_domain.save()
         self.assertEqual(list(self.branch.get_domains().keys()), ['po'])
 
+    def test_domain_linguas(self):
+        help_domain = self.branch.get_domains()['help']
+        help_domain.linguas_location = "help/Makefile.am"
+        self.assertEqual(help_domain.get_linguas(self.branch), {
+            'langs': None,
+            'error': 'Entry for this language is not present in ALL_LINGUAS variable in '
+                     'help/Makefile.am file.',
+        })
+        help_domain.linguas_location = "help/Makefile.am#HELP_LINGUAS"
+        self.assertEqual(help_domain.get_linguas(self.branch), {
+            'langs': ['cs', 'da', 'de', 'el', 'eo', 'es', 'fr', 'ja', 'oc', 'os',
+                      'pl', 'pt_BR', 'sl', 'sv', 'uk', 'zh_CN'],
+            'error': 'Entry for this language is not present in HELP_LINGUAS variable in '
+                     'help/Makefile.am file.',
+        })
+        help_domain.linguas_location = ''
+        self.assertEqual(help_domain.get_linguas(self.branch), {
+            'langs': ['cs', 'da', 'de', 'el', 'eo', 'es', 'fr', 'ja', 'oc', 'os',
+                      'pl', 'pt_BR', 'sl', 'sv', 'uk', 'zh_CN'],
+            'error': 'DOC_LINGUAS list doesn’t include this language.',
+        })
+
     def test_domain_xgettext_command(self):
         domain = self.branch.get_domains()['po']
         self.assertEqual(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]