Esempio n. 1
0
    def test_get_selection(self):
        # text = Text(master=self.root)
        text = mockText()
        text.insert("1.0", "Hello World!")

        # fix text.index result when called in get_selection
        def sel(s):
            # select entire text, cursor irrelevant
            if s == "sel.first":
                return "1.0"
            if s == "sel.last":
                return "1.12"
            raise TclError

        text.index = sel  # replaces .tag_add('sel', '1.0, '1.12')
        self.assertEqual(se.get_selection(text), ("1.0", "1.12"))

        def mark(s):
            # no selection, cursor after 'Hello'
            if s == "insert":
                return "1.5"
            raise TclError

        text.index = mark  # replaces .mark_set('insert', '1.5')
        self.assertEqual(se.get_selection(text), ("1.5", "1.5"))
Esempio n. 2
0
 def setUpClass(cls):
     cls.text = mockText()
     test_text = 'First line\nLine with target\nLast line\n'
     cls.text.insert('1.0', test_text)
     cls.pat = re.compile('target')
     cls.engine = se.SearchEngine(None)
     cls.engine.search_forward = lambda *args: ('f', args)
     cls.engine.search_backward = lambda *args: ('b', args)
Esempio n. 3
0
 def setUpClass(cls):
     cls.text = mockText()
     test_text = 'First line\nLine with target\nLast line\n'
     cls.text.insert('1.0', test_text)
     cls.pat = re.compile('target')
     cls.engine = se.SearchEngine(None)
     cls.engine.search_forward = lambda *args: ('f', args)
     cls.engine.search_backward = lambda *args: ('b', args)
     return
 def setUpClass(cls):
     cls.text = mockText()
     test_text = "First line\nLine with target\nLast line\n"
     cls.text.insert("1.0", test_text)
     cls.pat = re.compile("target")
     cls.engine = se.SearchEngine(None)
     cls.engine.search_forward = lambda *args: ("f", args)
     cls.engine.search_backward = lambda *args: ("b", args)
     return
Esempio n. 5
0
 def setUpClass(cls):
     cls.engine = se.SearchEngine(None)
     cls.text = mockText()
     cls.text.index = lambda index: '4.0'
     test_text = 'First line\nLine with target\nLast line\n'
     cls.text.insert('1.0', test_text)
     cls.pat = re.compile('target')
     cls.res = 2, (10, 16)
     cls.failpat = re.compile('xyz')
     cls.emptypat = re.compile('\\w*')
Esempio n. 6
0
 def setUpClass(cls):
     cls.engine = se.SearchEngine(None)
     cls.text = mockText()
     cls.text.index = lambda index: '4.0'
     test_text = 'First line\nLine with target\nLast line\n'
     cls.text.insert('1.0', test_text)
     cls.pat = re.compile('target')
     cls.res = (2, (10, 16))
     cls.failpat = re.compile('xyz')
     cls.emptypat = re.compile('\\w*')
     return
 def setUpClass(cls):
     cls.engine = se.SearchEngine(None)
     cls.text = mockText()
     cls.text.index = lambda index: "4.0"
     test_text = "First line\nLine with target\nLast line\n"
     cls.text.insert("1.0", test_text)
     cls.pat = re.compile("target")
     cls.res = (2, (10, 16))
     cls.failpat = re.compile("xyz")
     cls.emptypat = re.compile("\\w*")
     return
Esempio n. 8
0
    def setUpClass(cls):
        ##        requires('gui')
        ##        cls.root = Tk()
        ##        cls.text = Text(master=cls.root)
        cls.text = mockText()
        test_text = ('First line\n' 'Line with target\n' 'Last line\n')
        cls.text.insert('1.0', test_text)
        cls.pat = re.compile('target')

        cls.engine = se.SearchEngine(None)
        cls.engine.search_forward = lambda *args: ('f', args)
        cls.engine.search_backward = lambda *args: ('b', args)
Esempio n. 9
0
    def setUpClass(cls):
        ##        requires('gui')
        ##        cls.root = Tk()
        ##        cls.text = Text(master=cls.root)
        cls.text = mockText()
        test_text = "First line\n" "Line with target\n" "Last line\n"
        cls.text.insert("1.0", test_text)
        cls.pat = re.compile("target")

        cls.engine = se.SearchEngine(None)
        cls.engine.search_forward = lambda *args: ("f", args)
        cls.engine.search_backward = lambda *args: ("b", args)
Esempio n. 10
0
 def setUpClass(cls):
     cls.engine = se.SearchEngine(None)
     ##        requires('gui')
     ##        cls.root = Tk()
     ##        cls.text = Text(master=cls.root)
     cls.text = mockText()
     # search_backward calls index('end-1c')
     cls.text.index = lambda index: '4.0'
     test_text = ('First line\n' 'Line with target\n' 'Last line\n')
     cls.text.insert('1.0', test_text)
     cls.pat = re.compile('target')
     cls.res = (2, (10, 16))  # line, slice indexes of 'target'
     cls.failpat = re.compile('xyz')  # not in text
     cls.emptypat = re.compile(r'\w*')  # empty match possible
Esempio n. 11
0
 def setUpClass(cls):
     cls.engine = se.SearchEngine(None)
     ##        requires('gui')
     ##        cls.root = Tk()
     ##        cls.text = Text(master=cls.root)
     cls.text = mockText()
     # search_backward calls index('end-1c')
     cls.text.index = lambda index: "4.0"
     test_text = "First line\n" "Line with target\n" "Last line\n"
     cls.text.insert("1.0", test_text)
     cls.pat = re.compile("target")
     cls.res = (2, (10, 16))  # line, slice indexes of 'target'
     cls.failpat = re.compile("xyz")  # not in text
     cls.emptypat = re.compile("\w*")  # empty match possible
Esempio n. 12
0
    def setUpClass(cls):
##        requires('gui')
##        cls.root = Tk()
##        cls.text = Text(master=cls.root)
        cls.text = mockText()
        test_text = (
            'First line\n'
            'Line with target\n'
            'Last line\n')
        cls.text.insert('1.0', test_text)
        cls.pat = re.compile('target')

        cls.engine = se.SearchEngine(None)
        cls.engine.search_forward = lambda *args: ('f', args)
        cls.engine.search_backward = lambda *args: ('b', args)
Esempio n. 13
0
    def setUpClass(cls):
        cls.engine = se.SearchEngine(None)
##        requires('gui')
##        cls.root = Tk()
##        cls.text = Text(master=cls.root)
        cls.text = mockText()
        # search_backward calls index('end-1c')
        cls.text.index = lambda index: '4.0'
        test_text = (
            'First line\n'
            'Line with target\n'
            'Last line\n')
        cls.text.insert('1.0', test_text)
        cls.pat = re.compile('target')
        cls.res = (2, (10, 16))  # line, slice indexes of 'target'
        cls.failpat = re.compile('xyz')  # not in text
        cls.emptypat = re.compile(r'\w*')  # empty match possible
Esempio n. 14
0
    def test_get_selection(self):
        # text = Text(master=self.root)
        text = mockText()
        text.insert('1.0',  'Hello World!')

        # fix text.index result when called in get_selection
        def sel(s):
            # select entire text, cursor irrelevant
            if s == 'sel.first': return '1.0'
            if s == 'sel.last': return '1.12'
            raise TclError
        text.index = sel  # replaces .tag_add('sel', '1.0, '1.12')
        self.assertEqual(se.get_selection(text), ('1.0', '1.12'))

        def mark(s):
            # no selection, cursor after 'Hello'
            if s == 'insert': return '1.5'
            raise TclError
        text.index = mark  # replaces .mark_set('insert', '1.5')
        self.assertEqual(se.get_selection(text), ('1.5', '1.5'))
Esempio n. 15
0
    def test_get_selection(self):
        text = mockText()
        text.insert('1.0', 'Hello World!')

        def sel(s):
            if s == 'sel.first':
                return '1.0'
            if s == 'sel.last':
                return '1.12'
            raise TclError

        text.index = sel
        self.assertEqual(se.get_selection(text), ('1.0', '1.12'))

        def mark(s):
            if s == 'insert':
                return '1.5'
            raise TclError

        text.index = mark
        self.assertEqual(se.get_selection(text), ('1.5', '1.5'))
Esempio n. 16
0
    def test_get_selection(self):
        text = mockText()
        text.insert('1.0', 'Hello World!')

        def sel(s):
            if s == 'sel.first':
                return '1.0'
            if s == 'sel.last':
                return '1.12'
            raise TclError

        text.index = sel
        self.assertEqual(se.get_selection(text), ('1.0', '1.12'))

        def mark(s):
            if s == 'insert':
                return '1.5'
            raise TclError

        text.index = mark
        self.assertEqual(se.get_selection(text), ('1.5', '1.5'))
Esempio n. 17
0
    def test_get_selection(self):
        text = mockText()
        text.insert("1.0", "Hello World!")

        def sel(s):
            if s == "sel.first":
                return "1.0"
            if s == "sel.last":
                return "1.12"
            raise TclError

        text.index = sel
        self.assertEqual(se.get_selection(text), ("1.0", "1.12"))

        def mark(s):
            if s == "insert":
                return "1.5"
            raise TclError

        text.index = mark
        self.assertEqual(se.get_selection(text), ("1.5", "1.5"))