Example #1
0
    def test_candidates(self):
        c = SpellChecker(enabled=True)
        candidates = list(c.candidates("hell1"))
        self.assertTrue("hell" in candidates)
        self.assertTrue("hello" in candidates)

        candidates = list(c.candidates("hel"))
        self.assertEqual(len(candidates), 15)
Example #2
0
    def test_check_word_without_verification(self):
        c = SpellChecker(enabled=True)

        self.assertTrue(c.check_word_without_verification("HELLO"))
        c._enabled_all = False
        self.assertFalse(c.check_word_without_verification("HELLO"))

        c._man = SpellDict("man", enable_add=True)
        c.add_word("TTT")
        self.assertTrue(c.check_word("TTT"))
Example #3
0
    def test_enabled(self):
        c = SpellChecker()
        self.assertFalse(c.enabled("rus"))
        self.assertFalse(c.enabled("eng"))
        self.assertFalse(c.enabled("all"))

        c = SpellChecker(enabled=True)
        self.assertTrue(c.enabled("rus"))
        self.assertTrue(c.enabled("eng"))
        self.assertTrue(c.enabled("all"))
        self.assertFalse(c.enabled("---"))
Example #4
0
    def setUpClass(cls):
        cls.test = QTestHelper()

        # ---------------------------------------------------------------------
        # customize editor
        # noinspection PyUnusedLocal
        def save(txt):  # pragma: no cover
            return None

        def load():
            return "HELLO hello1 hell привет приве 2"  # i18n

        cls.widget = TestableWidget(None)
        cls.editor = TextEditor(cls.widget,
                                Config(),
                                save=save,
                                load=load,
                                spell=SpellChecker(enabled=True),
                                auto_load=True,
                                auto_key_switch=True)
        cls.keyswitcher = cls.editor._keyswitcher
        cls.spell = cls.editor._spell

        # ---------------------------------------------------------------------
        # customize the widget for placement
        layout = QHBoxLayout()
        layout.addWidget(cls.editor, alignment=Qt.Alignment())
        cls.widget.setLayout(layout)
        cls.widget.resize(800, 450)
        cls.widget.move(800, 150)

        cls.test.show_and_wait_for_active(cls.widget)
Example #5
0
    def setUpClass(cls):
        cls.test = QTestHelper()

        # ---------------------------------------------------------------------
        # customize editor
        # noinspection PyUnusedLocal
        def save(txt):
            return None

        def load():
            return "HELLO"

        cls.widget = TestableWidget(None)
        cls.spell = SpellChecker(enabled=True)
        cls.editor = TextEditor(cls.widget,
                                Config(),
                                save=save,
                                load=load,
                                spell=cls.spell)

        # ---------------------------------------------------------------------
        # customize the widget for placement
        layout = QHBoxLayout()
        layout.addWidget(cls.editor, alignment=Qt.Alignment())
        cls.widget.setLayout(layout)
        cls.widget.resize(800, 450)
        cls.widget.move(800, 150)

        cls.test.show_and_wait_for_active(cls.widget)
Example #6
0
    def test_highlightBlock(self):

        self.test = QTestHelper()

        # ---------------------------------------------------------------------
        # customize editor
        text = " hello \n world1"

        # noinspection PyUnusedLocal
        def save(txt):  # pragma: no cover
            return None

        def load():
            return text

        # ---------------------------------------------------------------------

        self.widget = TestableWidget(None)
        self.editor = TextEditor(self.widget,
                                 Config(),
                                 save=save,
                                 load=load,
                                 format="HTML",
                                 spell=SpellChecker(True))
        self.editor.load()

        # ---------------------------------------------------------------------
        # customize the widget for placement
        layout = QHBoxLayout()
        layout.addWidget(self.editor, alignment=Qt.Alignment())
        self.widget.setLayout(layout)
        self.widget.resize(800, 450)
        self.widget.move(800, 150)

        self.test.show_and_wait_for_active(self.widget)

        idx = {
            text.index("hello"): [None, False],
            text.index("world1"): [None, True],
        }

        cursor = self.editor._view.text.textCursor()
        cursor.movePosition(QTextCursor.Start)
        self.test.sleep()
        for i in range(len(text)):
            pos_in_block = cursor.positionInBlock()
            formats = cursor.block().layout().additionalFormats()

            for fmt in formats:
                if fmt.start <= pos_in_block < fmt.start + fmt.length:
                    if i in idx:
                        idx[i][0] = fmt.format

            cursor.movePosition(QTextCursor.NextCharacter)

        self.test.sleep()

        for i in idx:
            if idx[i][1]:
                fmt = idx[i][0]
                self.assertEqual(QTextCharFormat.SpellCheckUnderline,
                                 fmt.underlineStyle())
                self.assertEqual(
                    QColor("red").name(),
                    fmt.underlineColor().name())
            else:
                self.assertIsNone(idx[i][0])
Example #7
0
    def test_word_needs_no_verification(self):
        c = SpellChecker()

        self.assertTrue(c.word_needs_no_verification(""))
        self.assertTrue(c.word_needs_no_verification("a"))

        c._enabled_all = False
        self.assertTrue(c.word_needs_no_verification("hello"))
        c._enabled_all = True

        c.set_enabled("eng", False)
        self.assertTrue(c.word_needs_no_verification("hello"))

        c.set_enabled("rus", False)
        self.assertTrue(c.word_needs_no_verification("hello_"))

        c.set_enabled("eng", True)
        self.assertFalse(c.word_needs_no_verification("hello"))

        self.assertTrue(c.word_needs_no_verification("1"))
        self.assertTrue(c.word_needs_no_verification("1.0"))
        self.assertTrue(c.word_needs_no_verification("1e-5"))
Example #8
0
    def test_set_enabled(self):
        c = SpellChecker()

        c.set_enabled("rus", True)
        self.assertFalse(c.enabled("rus"))
        c.set_enabled("eng", True)
        self.assertFalse(c.enabled("eng"))
        c.set_enabled("all", True)
        self.assertFalse(c.enabled("all"))

        c = SpellChecker(enabled=True)
        self.assertTrue(c.enabled("rus"))
        self.assertTrue(c.enabled("eng"))
        self.assertTrue(c.enabled("all"))
        self.assertFalse(c.enabled("---"))

        c.set_enabled("rus", False)
        self.assertFalse(c.enabled("rus"))
        c.set_enabled("eng", False)
        self.assertFalse(c.enabled("eng"))

        c.set_enabled("all", True)
        self.assertTrue(c.enabled("rus"))
        self.assertTrue(c.enabled("eng"))

        c.set_enabled("all", False)
        self.assertFalse(c.enabled("rus"))
        self.assertFalse(c.enabled("eng"))

        c = SpellChecker(enabled=True)
        change_enabled = []
        c.change_enabled.connect(lambda: change_enabled.append(1))
        c.set_enabled("rus", True)
        c.set_enabled("rus", True)
        self.assertEqual(len(change_enabled), 2)
Example #9
0
    def test_check_word(self):
        c = SpellChecker(enabled=True)

        self.assertTrue(c.check_word("HELLO"))
        self.assertFalse(c.check_word("ERR_ERR"))
        self.assertTrue(c.check_word("2.045E-25"))