Example #1
0
    def test_lang_mapping(self):
        generate.main(verbose=0, strict=False, root_dir=MOCK_APPLICATION_DIR)
        self.assertTrue(len(self.configuration.edx_lang_map) > 0)

        for source_locale, dest_locale in self.configuration.edx_lang_map.items():
            source_dirname = self.configuration.get_messages_dir(source_locale)
            dest_dirname = self.configuration.get_messages_dir(dest_locale)

            self.assertTrue(Path.exists(dest_dirname))
            from filecmp import dircmp

            diff = dircmp(source_dirname, dest_dirname)
            self.assertEqual(len(diff.left_only), 0)
            self.assertEqual(len(diff.right_only), 0)
            self.assertEqual(len(diff.diff_files), 0)
 def test_main(self):
     """
     Runs generate.main() which should merge source files,
     then compile all sources in all configured languages.
     Validates output by checking all .mo files in all configured languages.
     .mo files should exist, and be recently created (modified
     after start of test suite)
     """
     generate.main(verbosity=0, strict=False)
     for locale in CONFIGURATION.translated_locales:
         for filename in ('django', 'djangojs'):
             mofile = filename+'.mo'
             path = os.path.join(CONFIGURATION.get_messages_dir(locale), mofile)
             exists = os.path.exists(path)
             self.assertTrue(exists, msg='Missing file in locale %s: %s' % (locale, mofile))
             self.assertTrue(datetime.fromtimestamp(os.path.getmtime(path), UTC) >= self.start_time,
                             msg='File not recently modified: %s' % path)
Example #3
0
    def test_resolve_merge_conflicts(self, mock_log):
        django_po_path = os.path.join(CONFIGURATION.get_messages_dir('fake2'), 'django.po')
        # File ought to have been generated in test_main
        # if not os.path.exists(django_po_path):
        generate.main(verbose=0, strict=False)

        with open(django_po_path, 'r') as django_po_file:
            po_lines = django_po_file.read()

        # check that there are no merge conflicts present
        # "#-#-#-#-#  django-partial.po (edx-platform)  #-#-#-#-#\n"
        pattern = re.compile('\"#-#-#-#-#.*#-#-#-#-#', re.M)
        match = pattern.findall(po_lines)
        self.assertEqual(len(match), 0, msg="Error, found merge conflicts in django.po: %s" % match)
        # Validate that the appropriate log warnings were shown
        self.assertTrue(mock_log.warn.called)
        self.assertIn(
            " %s duplicates in %s, details in .dup file",
            # the first item of call_args is the call arguments themselves as a tuple
            mock_log.warn.call_args[0]
        )
    def test_main(self):
        """
        Runs generate.main() which should merge source files,
        then compile all sources in all configured languages.
        Validates output by checking all .mo files in all configured languages.
        .mo files should exist, and be recently created (modified
        after start of test suite)
        """
        # Change dummy_locales to not have Esperanto present.
        self.configuration.dummy_locales = ['fake2']

        generate.main(verbosity=0, strict=False)
        for locale in self.configuration.translated_locales:
            for filename in ('django', 'djangojs'):
                mofile = filename + '.mo'
                path = os.path.join(self.configuration.get_messages_dir(locale), mofile)
                exists = os.path.exists(path)
                self.assertTrue(exists, msg=u'Missing file in locale %s: %s' % (locale, mofile))
                self.assertGreaterEqual(
                    datetime.fromtimestamp(os.path.getmtime(path), UTC),
                    self.start_time,
                    msg=u'File not recently modified: %s' % path
                )
Example #5
0
    def test_main(self):
        """
        Runs generate.main() which should merge source files,
        then compile all sources in all configured languages.
        Validates output by checking all .mo files in all configured languages.
        .mo files should exist, and be recently created (modified
        after start of test suite)
        """
        generate.main(verbose=0, strict=False, root_dir=MOCK_APPLICATION_DIR)
        for locale in ['mock']:
            for (filename, num_headers) in zip(('django', 'djangojs'), (6, 4)):
                mofile = filename + '.mo'
                file_path = Path.joinpath(self.configuration.get_messages_dir(locale), mofile)
                exists = Path.exists(file_path)
                self.assertTrue(exists, msg='Missing file in locale %s: %s' % (locale, mofile))
                self.assertTrue(
                    datetime.fromtimestamp(Path.getmtime(file_path), UTC) >= self.start_time,
                    msg='File should be recently modified: %s' % file_path
                )

                # Assert merge headers look right
                file_path = Path.joinpath(self.configuration.get_messages_dir(locale), filename + '.po')
                self.assert_merge_headers(file_path, num_headers)