Allow running unit-tests with 0test
[rox-edit/bju.git] / tests / testreplace.py
blobb5e2a96252b81c2fbfd6f50dbeee141629a7cee9
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 import unittest
5 import sys
6 import os, time
7 from os.path import dirname, abspath, join
9 sys.path.insert(0, '..')
10 sys.argv[0] = dirname(sys.argv[0])
12 import setup
13 from EditWindow import EditWindow
14 import search
16 class TestReplace(unittest.TestCase):
17 def setUp(self):
18 self.win = EditWindow(show = False)
19 self.win.buffer.begin_user_action()
20 self.win.buffer.insert_at_cursor("Hello\n")
21 self.win.buffer.end_user_action()
22 self.win.buffer.start_undo_history()
24 def tearDown(self):
25 self.win.destroy()
27 def get_text(self):
28 s = self.win.buffer.get_start_iter()
29 e = self.win.buffer.get_end_iter()
30 return self.win.buffer.get_text(s, e, True)
32 def assertNow(self, expected):
33 actual = self.get_text()
34 if actual != expected:
35 raise AssertionError("Incorrect final text.\n"
36 "Expected:\n%s\nActual:\n%s" % (expected[:100], actual[:100]))
38 def testSimple(self):
39 self.win.process_selected(lambda x: "World")
40 self.assertNow("World\n")
41 self.win.undo()
42 self.assertNow("Hello\n")
44 def testReplace(self):
45 self.win.undo()
46 self.win.buffer.begin_user_action()
47 self.win.buffer.insert_at_cursor("deàça")
48 self.win.buffer.end_user_action()
49 replace = search.Replace(self.win)
50 replace.replace_entry.set_text("a")
51 replace.with_entry.set_text("b")
52 replace.do_replace(show_info = False)
54 self.assertNow("deàçb")
56 self.win.undo()
57 self.assertNow("deàça")
60 sys.argv.append('-v')
61 unittest.main()