Пример #1
0
    def test_translations_found(self, tdir):
        translations = unittest.mock.Mock()

        with unittest.mock.patch('mkdocs.localization.Translations.load', return_value=translations):
            install_translations(self.env, parse_locale('en'), [tdir])

        self.env.install_gettext_translations.assert_called_once_with(translations)
Пример #2
0
    def get_env(self):
        """ Return a Jinja environment for the theme. """

        loader = jinja2.FileSystemLoader(self.dirs)
        # No autoreload because editing a template in the middle of a build is not useful.
        env = jinja2.Environment(loader=loader, auto_reload=False)
        env.filters['url'] = filters.url_filter
        localization.install_translations(env, self._vars['locale'], self.dirs)
        return env
Пример #3
0
    def test_merge_translations(self, custom_dir, theme_dir):
        custom_dir_translations = unittest.mock.Mock()
        theme_dir_translations = unittest.mock.Mock()

        def side_effet(*args, **kwargs):
            dirname = args[0]
            if dirname.startswith(custom_dir):
                return custom_dir_translations
            elif dirname.startswith(theme_dir):
                return theme_dir_translations
            else:
                self.fail()

        with unittest.mock.patch('mkdocs.localization.Translations.load', side_effect=side_effet):
            install_translations(self.env, parse_locale('en'), [custom_dir, theme_dir])

        theme_dir_translations.merge.assert_called_once_with(custom_dir_translations)
 def test_no_translations_found(self, dir_without_translations):
     install_translations(self.env, parse_locale('fr_CA'),
                          [dir_without_translations])
     self.env.install_null_translations.assert_called_once()
 def test_jinja_extension_installed(self):
     install_translations(self.env, parse_locale('en'), [])
     self.env.add_extension.assert_called_once_with('jinja2.ext.i18n')