File: test_configuration.py

package info (click to toggle)
mnemosyne 2.7.3%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,804 kB
  • sloc: python: 34,077; ansic: 837; xml: 625; makefile: 249; sh: 63
file content (64 lines) | stat: -rw-r--r-- 3,152 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import sys

from mnemosyne.libmnemosyne import Mnemosyne
from mnemosyne_test import MnemosyneTest
from unittest.mock import patch


class TestConfiguration(MnemosyneTest):

    def setup(self):
        self.initialise_data_dir()
        path = os.path.join(os.getcwd(), "..", "mnemosyne", "libmnemosyne",
                            "renderers")
        if path not in sys.path:
            sys.path.append(path)
        self.mnemosyne = Mnemosyne(upload_science_logs=False, interested_in_old_reps=True,
            asynchronous_database=True)
        self.mnemosyne.components.insert(0,
           ("mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator", "GetTextGuiTranslator"))
        self.mnemosyne.components.append(\
            ("test_add_cards", "Widget"))
        self.mnemosyne.gui_for_component["ScheduledForgottenNew"] = \
            [("mnemosyne_test", "TestReviewWidget")]
        self.mnemosyne.components.append(\
            ("mnemosyne.libmnemosyne.ui_components.dialogs", "EditCardDialog"))
        self.mnemosyne.initialise(os.path.abspath("dot_test"),  automatic_upgrades=False)
        self.review_controller().reset()

    def test_default_language_default(self):
        # the default language should be the en
        assert self.config().default_language() == 'en'

    def test_supported_language_as_default(self):

        locale_map_to_test = {
                              "ca_ES@valencia.UTF-8": "ca@valencia",
                              "de_DE.UTF-8": "de",
                              "en_US.UTF-8": "en",
                              "hu_HU.UTF-8": "hu",
                              "ja_JP.UTF-8": "ja",
                              "pt_BR.UTF-8": "pt_BR",
                              "pt_PT.UTF-8": "pt",
                              "sv_SE.UTF-8": "sv",
                              "zh_CN.UTF-8": "zh_CN",
                              "zh_HK.UTF-8": "zh_HK",
                              "zh_TW.UTF-8": "zh_TW",
                              }

        with patch('mnemosyne.libmnemosyne.gui_translators.gettext_gui_translator.GetTextGuiTranslator.supported_languages') as mock_supported:
            # in development mode, we need to mock the supported_languages
            mock_supported.return_value = ['ca', 'gl', 'ja', 'pt', 'pl',
                                           'nb', 'tr', 'id', 'ca@valencia',
                                           'zh_TW', 'cs', 'zh_CN', 'nl', 'fr',
                                           'he', 'it', 'da', 'sr', 'de',
                                           'pt_BR', 'ru', 'eo', 'hr', 'sv',
                                           'uk', 'fa', 'hu', 'zh_HK', 'es']
            for lang_locale in locale_map_to_test:
                lang_code, encoding = lang_locale.split(".")
                with patch('mnemosyne.libmnemosyne.configuration.getdefaultlocale') as mock_locale:
                    mock_locale.return_value = (lang_code, encoding)
                    lang = self.config().default_language()
                    assert lang == locale_map_to_test[lang_locale]
                    mock_locale.assert_called_once()