File: test_frontend_widget.py

package info (click to toggle)
python-qtconsole 5.6.1-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,184 kB
  • sloc: python: 7,222; makefile: 180; sh: 36
file content (96 lines) | stat: -rw-r--r-- 3,219 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import unittest

import pytest

from qtpy import QtWidgets
from qtconsole.frontend_widget import FrontendWidget
from qtpy.QtTest import QTest
from . import no_display


@pytest.mark.skipif(no_display, reason="Doesn't work without a display")
class TestFrontendWidget(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        """ Create the application for the test case.
        """
        cls._app = QtWidgets.QApplication.instance()
        if cls._app is None:
            cls._app = QtWidgets.QApplication([])
        cls._app.setQuitOnLastWindowClosed(False)

    @classmethod
    def tearDownClass(cls):
        """ Exit the application.
        """
        QtWidgets.QApplication.quit()

    def test_transform_classic_prompt(self):
        """ Test detecting classic prompts.
        """
        w = FrontendWidget(kind='rich')
        t = w._highlighter.transform_classic_prompt

        # Base case
        self.assertEqual(t('>>> test'), 'test')
        self.assertEqual(t(' >>> test'), 'test')
        self.assertEqual(t('\t >>> test'), 'test')

        # No prompt
        self.assertEqual(t(''), '')
        self.assertEqual(t('test'), 'test')

        # Continuation prompt
        self.assertEqual(t('... test'), 'test')
        self.assertEqual(t(' ... test'), 'test')
        self.assertEqual(t('  ... test'), 'test')
        self.assertEqual(t('\t ... test'), 'test')

        # Prompts that don't match the 'traditional' prompt
        self.assertEqual(t('>>>test'), '>>>test')
        self.assertEqual(t('>> test'), '>> test')
        self.assertEqual(t('...test'), '...test')
        self.assertEqual(t('.. test'), '.. test')

        # Prefix indicating input from other clients
        self.assertEqual(t('[remote] >>> test'), 'test')

        # Random other prefix
        self.assertEqual(t('[foo] >>> test'), '[foo] >>> test')

    def test_transform_ipy_prompt(self):
        """ Test detecting IPython prompts.
        """
        w = FrontendWidget(kind='rich')
        t = w._highlighter.transform_ipy_prompt

        # In prompt
        self.assertEqual(t('In [1]: test'), 'test')
        self.assertEqual(t('In [2]: test'), 'test')
        self.assertEqual(t('In [10]: test'), 'test')
        self.assertEqual(t(' In [1]: test'), 'test')
        self.assertEqual(t('\t In [1]: test'), 'test')

        # No prompt
        self.assertEqual(t(''), '')
        self.assertEqual(t('test'), 'test')

        # Continuation prompt
        self.assertEqual(t('   ...: test'), 'test')
        self.assertEqual(t('    ...: test'), 'test')
        self.assertEqual(t('     ...: test'), 'test')
        self.assertEqual(t('\t   ...: test'), 'test')

        # Prompts that don't match the in-prompt
        self.assertEqual(t('In [1]:test'), 'In [1]:test')
        self.assertEqual(t('[1]: test'), '[1]: test')
        self.assertEqual(t('In: test'), 'In: test')
        self.assertEqual(t(': test'), ': test')
        self.assertEqual(t('...: test'), '...: test')

        # Prefix indicating input from other clients
        self.assertEqual(t('[remote] In [1]: test'), 'test')

        # Random other prefix
        self.assertEqual(t('[foo] In [1]: test'), '[foo] In [1]: test')