Author: Ronny Pfannschmidt <[email protected]>
Branch: py3ksupport
Changeset: r133:c3b33f80a61d
Date: 2011-10-18 12:12 +0200
http://bitbucket.org/pypy/pyrepl/changeset/c3b33f80a61d/
Log: pytest-ize test functions
diff --git a/testing/infrastructure.py b/testing/infrastructure.py
--- a/testing/infrastructure.py
+++ b/testing/infrastructure.py
@@ -32,18 +32,15 @@
width = 80
encoding = 'utf-8'
- def __init__(self, events, testcase, verbose=False):
+ def __init__(self, events, verbose=False):
self.events = events
self.next_screen = None
self.verbose = verbose
- self.testcase = testcase
def refresh(self, screen, xy):
if self.next_screen is not None:
- self.testcase.assertEqual(
- screen, self.next_screen,
- "[ %s != %s after %r ]"%(screen, self.next_screen,
- self.last_event_name))
+ assert screen == self.next_screen, "[ %s != %s after %r ]"%(
+ screen, self.next_screen, self.last_event_name)
def get_event(self, block=1):
ev, sc = self.events.pop(0)
@@ -62,21 +59,9 @@
Reader.refresh(self)
self.dirty = True
-class ReaderTestCase(unittest.TestCase):
- def run_test(self, test_spec, reader_class=TestReader):
- # remember to finish your test_spec with 'accept' or similar!
- con = TestConsole(test_spec, self)
- reader = reader_class(con)
- reader.readline()
+def read_spec(test_spec, reader_class=TestReader):
+ # remember to finish your test_spec with 'accept' or similar!
+ con = TestConsole(test_spec)
+ reader = reader_class(con)
+ reader.readline()
-class BasicTestRunner:
- def run(self, test):
- result = unittest.TestResult()
- test(result)
- return result
-
-def run_testcase(testclass):
- suite = unittest.makeSuite(testclass)
- runner = unittest.TextTestRunner(sys.stdout, verbosity=1)
- result = runner.run(suite)
-
diff --git a/testing/test_basic.py b/testing/test_basic.py
--- a/testing/test_basic.py
+++ b/testing/test_basic.py
@@ -18,98 +18,88 @@
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from pyrepl.console import Event
-from .infrastructure import ReaderTestCase, EA, run_testcase
+from .infrastructure import read_spec, EA
-class SimpleTestCase(ReaderTestCase):
- def test_basic(self):
- self.run_test([(('self-insert', 'a'), ['a']),
- ( 'accept', ['a'])])
+def test_basic():
+ read_spec([(('self-insert', 'a'), ['a']),
+ ( 'accept', ['a'])])
- def test_repeat(self):
- self.run_test([(('digit-arg', '3'), ['']),
- (('self-insert', 'a'), ['aaa']),
- ( 'accept', ['aaa'])])
+def test_repeat():
+ read_spec([(('digit-arg', '3'), ['']),
+ (('self-insert', 'a'), ['aaa']),
+ ( 'accept', ['aaa'])])
- def test_kill_line(self):
- self.run_test([(('self-insert', 'abc'), ['abc']),
- ( 'left', None),
- ( 'kill-line', ['ab']),
- ( 'accept', ['ab'])])
+def test_kill_line():
+ read_spec([(('self-insert', 'abc'), ['abc']),
+ ( 'left', None),
+ ( 'kill-line', ['ab']),
+ ( 'accept', ['ab'])])
- def test_unix_line_discard(self):
- self.run_test([(('self-insert', 'abc'), ['abc']),
- ( 'left', None),
- ( 'unix-word-rubout', ['c']),
- ( 'accept', ['c'])])
+def test_unix_line_discard():
+ read_spec([(('self-insert', 'abc'), ['abc']),
+ ( 'left', None),
+ ( 'unix-word-rubout', ['c']),
+ ( 'accept', ['c'])])
- def test_kill_word(self):
- self.run_test([(('self-insert', 'ab cd'), ['ab cd']),
- ( 'beginning-of-line', ['ab cd']),
- ( 'kill-word', [' cd']),
- ( 'accept', [' cd'])])
+def test_kill_word():
+ read_spec([(('self-insert', 'ab cd'), ['ab cd']),
+ ( 'beginning-of-line', ['ab cd']),
+ ( 'kill-word', [' cd']),
+ ( 'accept', [' cd'])])
- def test_backward_kill_word(self):
- self.run_test([(('self-insert', 'ab cd'), ['ab cd']),
- ( 'backward-kill-word', ['ab ']),
- ( 'accept', ['ab '])])
+def test_backward_kill_word():
+ read_spec([(('self-insert', 'ab cd'), ['ab cd']),
+ ( 'backward-kill-word', ['ab ']),
+ ( 'accept', ['ab '])])
- def test_yank(self):
- self.run_test([(('self-insert', 'ab cd'), ['ab cd']),
- ( 'backward-kill-word', ['ab ']),
- ( 'beginning-of-line', ['ab ']),
- ( 'yank', ['cdab ']),
- ( 'accept', ['cdab '])])
-
- def test_yank_pop(self):
- self.run_test([(('self-insert', 'ab cd'), ['ab cd']),
- ( 'backward-kill-word', ['ab ']),
- ( 'left', ['ab ']),
- ( 'backward-kill-word', [' ']),
- ( 'yank', ['ab ']),
- ( 'yank-pop', ['cd ']),
- ( 'accept', ['cd '])])
+def test_yank():
+ read_spec([(('self-insert', 'ab cd'), ['ab cd']),
+ ( 'backward-kill-word', ['ab ']),
+ ( 'beginning-of-line', ['ab ']),
+ ( 'yank', ['cdab ']),
+ ( 'accept', ['cdab '])])
+
+def test_yank_pop():
+ read_spec([(('self-insert', 'ab cd'), ['ab cd']),
+ ( 'backward-kill-word', ['ab ']),
+ ( 'left', ['ab ']),
+ ( 'backward-kill-word', [' ']),
+ ( 'yank', ['ab ']),
+ ( 'yank-pop', ['cd ']),
+ ( 'accept', ['cd '])])
- def test_interrupt(self):
- try:
- self.run_test([( 'interrupt', [''])])
- except KeyboardInterrupt:
- pass
- else:
- self.fail('KeyboardInterrupt got lost')
+def test_interrupt():
+ with pytest.raises(KeyboardInterrupt):
+ read_spec([( 'interrupt', [''])])
- # test_suspend -- hah
+# test_suspend -- hah
- def test_up(self):
- self.run_test([(('self-insert', 'ab\ncd'), ['ab', 'cd']),
- ( 'up', ['ab', 'cd']),
- (('self-insert', 'e'), ['abe', 'cd']),
- ( 'accept', ['abe', 'cd'])])
+def test_up():
+ read_spec([(('self-insert', 'ab\ncd'), ['ab', 'cd']),
+ ( 'up', ['ab', 'cd']),
+ (('self-insert', 'e'), ['abe', 'cd']),
+ ( 'accept', ['abe', 'cd'])])
- def test_down(self):
- self.run_test([(('self-insert', 'ab\ncd'), ['ab', 'cd']),
- ( 'up', ['ab', 'cd']),
- (('self-insert', 'e'), ['abe', 'cd']),
- ( 'down', ['abe', 'cd']),
- (('self-insert', 'f'), ['abe', 'cdf']),
- ( 'accept', ['abe', 'cdf'])])
+def test_down():
+ read_spec([(('self-insert', 'ab\ncd'), ['ab', 'cd']),
+ ( 'up', ['ab', 'cd']),
+ (('self-insert', 'e'), ['abe', 'cd']),
+ ( 'down', ['abe', 'cd']),
+ (('self-insert', 'f'), ['abe', 'cdf']),
+ ( 'accept', ['abe', 'cdf'])])
- def test_left(self):
- self.run_test([(('self-insert', 'ab'), ['ab']),
- ( 'left', ['ab']),
- (('self-insert', 'c'), ['acb']),
- ( 'accept', ['acb'])])
+def test_left():
+ read_spec([(('self-insert', 'ab'), ['ab']),
+ ( 'left', ['ab']),
+ (('self-insert', 'c'), ['acb']),
+ ( 'accept', ['acb'])])
- def test_right(self):
- self.run_test([(('self-insert', 'ab'), ['ab']),
- ( 'left', ['ab']),
- (('self-insert', 'c'), ['acb']),
- ( 'right', ['acb']),
- (('self-insert', 'd'), ['acbd']),
- ( 'accept', ['acbd'])])
-
-def test():
- run_testcase(SimpleTestCase)
+def test_right():
+ read_spec([(('self-insert', 'ab'), ['ab']),
+ ( 'left', ['ab']),
+ (('self-insert', 'c'), ['acb']),
+ ( 'right', ['acb']),
+ (('self-insert', 'd'), ['acbd']),
+ ( 'accept', ['acbd'])])
-if __name__ == '__main__':
- test()
diff --git a/testing/test_bugs.py b/testing/test_bugs.py
--- a/testing/test_bugs.py
+++ b/testing/test_bugs.py
@@ -17,20 +17,13 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-from pyrepl.console import Event
-from .infrastructure import ReaderTestCase, EA, run_testcase
+from .infrastructure import EA, read_spec
# this test case should contain as-verbatim-as-possible versions of
# (applicable) bug reports
-class BugsTestCase(ReaderTestCase):
- def test_transpose_at_start(self):
- self.run_test([( 'transpose', [EA, '']),
- ( 'accept', [''])])
+def test_transpose_at_start():
+ read_spec([( 'transpose', [EA, '']),
+ ( 'accept', [''])])
-def test():
- run_testcase(BugsTestCase)
-
-if __name__ == '__main__':
- test()
diff --git a/testing/test_wishes.py b/testing/test_wishes.py
--- a/testing/test_wishes.py
+++ b/testing/test_wishes.py
@@ -17,22 +17,15 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-from pyrepl.console import Event
-from .infrastructure import ReaderTestCase, EA, run_testcase
+from .infrastructure import EA, read_spec
# this test case should contain as-verbatim-as-possible versions of
# (applicable) feature requests
-class WishesTestCase(ReaderTestCase):
- def test_quoted_insert_repeat(self):
- self.run_test([(('digit-arg', '3'), ['']),
- ( 'quoted-insert', ['']),
- (('self-insert', '\033'), ['^[^[^[']),
- ( 'accept', None)])
+def test_quoted_insert_repeat():
+ read_spec([(('digit-arg', '3'), ['']),
+ ( 'quoted-insert', ['']),
+ (('self-insert', '\033'), ['^[^[^[']),
+ ( 'accept', None)])
-def test():
- run_testcase(WishesTestCase)
-
-if __name__ == '__main__':
- test()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit