def test_process(qtbot):
    utils = text_utils.TextUtils({})

    assert utils.process('<b>hello</b> world',
                         constants.TransformationType.Audio) == 'hello world'
    assert utils.process(
        '<span style="color: var(--field-fg); background: var(--field-bg);">&nbsp;gerund</span>',
        constants.TransformationType.Audio) == 'gerund'
def test_is_empty(qtbot):
    utils = text_utils.TextUtils({})

    assert utils.is_empty('yo') == False
    assert utils.is_empty('') == True
    assert utils.is_empty(' ') == True
    assert utils.is_empty('&nbsp;') == True
    assert utils.is_empty('&nbsp; ') == True
    assert utils.is_empty(' &nbsp; ') == True
    assert utils.is_empty('<br>') == True
    assert utils.is_empty('<div>\n</div>') == True
Esempio n. 3
0
    def update_transformed_text(self):
        # get the sample text
        sample_text = self.sample_text_input.text()
        transformation_type = constants.TransformationType[
            self.sample_transformation_type_combo_box.currentText()]
        if len(sample_text) == 0:
            label_text = BLANK_TEXT
        else:
            # get the text replacements
            utils = text_utils.TextUtils(self.get_text_processing_settings())
            sample_text_processed = utils.process(sample_text,
                                                  transformation_type)
            label_text = f'<b>{html.escape(sample_text_processed)}</b>'

        # self.sample_text_transformed_label.setText(label_text)
        self.languagetools.anki_utils.run_on_main(
            lambda: self.sample_text_transformed_label.setText(label_text))
    def __init__(self, anki_utils, deck_utils, cloud_language_tools):
        self.anki_utils = anki_utils
        self.deck_utils = deck_utils
        self.cloud_language_tools = cloud_language_tools
        self.error_manager = errors.ErrorManager(self.anki_utils)
        self.config = self.anki_utils.get_config()
        self.text_utils = text_utils.TextUtils(
            self.get_text_processing_settings())
        self.error_manager = errors.ErrorManager(self.anki_utils)

        self.language_data_load_error = False

        self.collectionLoaded = False
        self.mainWindowInitialized = False
        self.deckBrowserRendered = False
        self.initDone = False

        self.api_key_checked = False
def test_replace(qtbot):
    utils = text_utils.TextUtils({
        'replacements': [
            {
                'pattern': ' / ',
                'replace': ' ',
                'Audio': True,
                'Translation': False,
                'Transliteration': False
            },
            {
                'pattern': r'\(etw \+D\)',
                'replace': 'etwas +Dativ',
                'Audio': True,
                'Translation': False,
                'Transliteration': False
            },
        ]
    })

    assert utils.process('word1 / word2',
                         constants.TransformationType.Audio) == 'word1 word2'
    assert utils.process(
        'word1 / word2',
        constants.TransformationType.Translation) == 'word1 / word2'
    assert utils.process(
        'word1 / word2',
        constants.TransformationType.Transliteration) == 'word1 / word2'
    assert utils.process('<b>word1</b> / word2',
                         constants.TransformationType.Audio) == 'word1 word2'
    assert utils.process(
        'unter (etw +D)',
        constants.TransformationType.Audio) == 'unter etwas +Dativ'
    assert utils.process(
        '<b>unter</b> (etw +D)',
        constants.TransformationType.Audio) == 'unter etwas +Dativ'
    assert utils.process(
        '<b>unter</b> (etw +D)',
        constants.TransformationType.Transliteration) == 'unter (etw +D)'
 def store_text_processing_settings(self, settings):
     self.config[constants.CONFIG_TEXT_PROCESSING] = settings
     self.anki_utils.write_config(self.config)
     self.text_utils = text_utils.TextUtils(settings)