Author: Brian Kearns <[email protected]> Branch: Changeset: r61059:b724dd140134 Date: 2013-02-11 01:37 -0500 http://bitbucket.org/pypy/pypy/changeset/b724dd140134/
Log: update the pyrepl tests from upstream diff --git a/pypy/module/test_lib_pypy/pyrepl/__init__.py b/pypy/module/test_lib_pypy/pyrepl/__init__.py --- a/pypy/module/test_lib_pypy/pyrepl/__init__.py +++ b/pypy/module/test_lib_pypy/pyrepl/__init__.py @@ -1,20 +1,3 @@ -# Copyright 2000-2004 Michael Hudson-Doyle <[email protected]> -# -# All Rights Reserved -# -# -# Permission to use, copy, modify, and distribute this software and -# its documentation for any purpose is hereby granted without fee, -# provided that the above copyright notice appear in all copies and -# that both that copyright notice and this permission notice appear in -# supporting documentation. -# -# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO -# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, -# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF -# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -# moo +import sys +import lib_pypy.pyrepl +sys.modules['pyrepl'] = sys.modules['lib_pypy.pyrepl'] diff --git a/pypy/module/test_lib_pypy/pyrepl/infrastructure.py b/pypy/module/test_lib_pypy/pyrepl/infrastructure.py --- a/pypy/module/test_lib_pypy/pyrepl/infrastructure.py +++ b/pypy/module/test_lib_pypy/pyrepl/infrastructure.py @@ -17,66 +17,57 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +from __future__ import print_function from pyrepl.reader import Reader from pyrepl.console import Console, Event -import unittest -import sys + class EqualsAnything(object): def __eq__(self, other): return True + + EA = EqualsAnything() + class TestConsole(Console): height = 24 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) self.next_screen = sc if not isinstance(ev, tuple): - ev = (ev,) + ev = (ev, None) self.last_event_name = ev[0] if self.verbose: - print "event", ev + print("event", ev) return Event(*ev) + class TestReader(Reader): + def get_prompt(self, lineno, cursor_on_line): return '' + def refresh(self): 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() -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) - +def read_spec(test_spec, reader_class=TestReader): + # remember to finish your test_spec with 'accept' or similar! + con = TestConsole(test_spec, verbose=True) + reader = reader_class(con) + reader.readline() diff --git a/pypy/module/test_lib_pypy/pyrepl/test_basic.py b/pypy/module/test_lib_pypy/pyrepl/test_basic.py --- a/pypy/module/test_lib_pypy/pyrepl/test_basic.py +++ b/pypy/module/test_lib_pypy/pyrepl/test_basic.py @@ -16,100 +16,99 @@ # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +import pytest +from .infrastructure import read_spec -from pyrepl.console import Event -from pyrepl.tests.infrastructure import ReaderTestCase, EA, run_testcase -class SimpleTestCase(ReaderTestCase): +def test_basic(): + read_spec([(('self-insert', 'a'), ['a']), + ( 'accept', ['a'])]) - def test_basic(self): - self.run_test([(('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_unix_line_discard(self): - self.run_test([(('self-insert', 'abc'), ['abc']), - ( 'left', None), - ( 'unix-word-rubout', ['c']), - ( 'accept', ['c'])]) +def test_kill_line(): + read_spec([(('self-insert', 'abc'), ['abc']), + ( 'left', None), + ( 'kill-line', ['ab']), + ( 'accept', ['ab'])]) - 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_backward_kill_word(self): - self.run_test([(('self-insert', 'ab cd'), ['ab cd']), - ( 'backward-kill-word', ['ab ']), - ( 'accept', ['ab '])]) +def test_unix_line_discard(): + read_spec([(('self-insert', 'abc'), ['abc']), + ( 'left', None), + ( 'unix-word-rubout', ['c']), + ( 'accept', ['c'])]) - 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_interrupt(self): - try: - self.run_test([( 'interrupt', [''])]) - except KeyboardInterrupt: - pass - else: - self.fail('KeyboardInterrupt got lost') +def test_kill_word(): + read_spec([(('self-insert', 'ab cd'), ['ab cd']), + ( 'beginning-of-line', ['ab cd']), + ( 'kill-word', [' cd']), + ( 'accept', [' cd'])]) - # 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_backward_kill_word(): + read_spec([(('self-insert', 'ab cd'), ['ab cd']), + ( 'backward-kill-word', ['ab ']), + ( 'accept', ['ab '])]) - 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_left(self): - self.run_test([(('self-insert', 'ab'), ['ab']), - ( 'left', ['ab']), - (('self-insert', 'c'), ['acb']), - ( 'accept', ['acb'])]) +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_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) -if __name__ == '__main__': - test() +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(): + with pytest.raises(KeyboardInterrupt): + read_spec([('interrupt', [''])]) + + +# test_suspend -- hah +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(): + 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(): + read_spec([(('self-insert', 'ab'), ['ab']), + ( 'left', ['ab']), + (('self-insert', 'c'), ['acb']), + ( 'accept', ['acb'])]) + + +def test_right(): + read_spec([(('self-insert', 'ab'), ['ab']), + ( 'left', ['ab']), + (('self-insert', 'c'), ['acb']), + ( 'right', ['acb']), + (('self-insert', 'd'), ['acbd']), + ( 'accept', ['acbd'])]) diff --git a/pypy/module/test_lib_pypy/pyrepl/test_bugs.py b/pypy/module/test_lib_pypy/pyrepl/test_bugs.py --- a/pypy/module/test_lib_pypy/pyrepl/test_bugs.py +++ b/pypy/module/test_lib_pypy/pyrepl/test_bugs.py @@ -17,20 +17,30 @@ # 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 pyrepl.tests.infrastructure import ReaderTestCase, EA, run_testcase +from pyrepl.historical_reader import HistoricalReader +from .infrastructure import EA, TestReader, read_spec # this test case should contain as-verbatim-as-possible versions of # (applicable) bug reports -class BugsTestCase(ReaderTestCase): +import pytest - def test_transpose_at_start(self): - self.run_test([( 'transpose', [EA, '']), - ( 'accept', [''])]) -def test(): - run_testcase(BugsTestCase) +class HistoricalTestReader(HistoricalReader, TestReader): + pass -if __name__ == '__main__': - test() + [email protected](reason='event missing', run=False) +def test_transpose_at_start(): + read_spec([ + ('transpose', [EA, '']), + ('accept', [''])]) + + +def test_cmd_instantiation_crash(): + spec = [ + ('reverse-history-isearch', ["(r-search `') "]), + (('key', 'left'), ['']), + ('accept', ['']) + ] + read_spec(spec, HistoricalTestReader) diff --git a/pypy/module/test_lib_pypy/pyrepl/test_functional.py b/pypy/module/test_lib_pypy/pyrepl/test_functional.py --- a/pypy/module/test_lib_pypy/pyrepl/test_functional.py +++ b/pypy/module/test_lib_pypy/pyrepl/test_functional.py @@ -1,50 +1,25 @@ # Copyright 2000-2007 Michael Hudson-Doyle <[email protected]> # Maciek Fijalkowski -# -# All Rights Reserved -# -# -# Permission to use, copy, modify, and distribute this software and -# its documentation for any purpose is hereby granted without fee, -# provided that the above copyright notice appear in all copies and -# that both that copyright notice and this permission notice appear in -# supporting documentation. -# -# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO -# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, -# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF -# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - +# License: MIT # some functional tests, to see if this is really working -import py +import pytest import sys -class TestTerminal(object): - def _spawn(self, *args, **kwds): - try: - import pexpect - except ImportError, e: - py.test.skip(str(e)) - kwds.setdefault('timeout', 10) - child = pexpect.spawn(*args, **kwds) - child.logfile = sys.stdout - return child - def spawn(self, argv=[]): - # avoid running start.py, cause it might contain - # things like readline or rlcompleter(2) included - child = self._spawn(sys.executable, ['-S'] + argv) - child.sendline('from pyrepl.python_reader import main') - child.sendline('main()') - return child +def pytest_funcarg__child(request): + try: + pexpect = pytest.importorskip('pexpect') + except SyntaxError: + pytest.skip('pexpect wont work on py3k') + child = pexpect.spawn(sys.executable, ['-S'], timeout=10) + child.logfile = sys.stdout + child.sendline('from pyrepl.python_reader import main') + child.sendline('main()') + return child - def test_basic(self): - child = self.spawn() - child.sendline('a = 3') - child.sendline('a') - child.expect('3') - + +def test_basic(child): + child.sendline('a = 3') + child.sendline('a') + child.expect('3') diff --git a/pypy/module/test_lib_pypy/pyrepl/test_keymap.py b/pypy/module/test_lib_pypy/pyrepl/test_keymap.py new file mode 100644 --- /dev/null +++ b/pypy/module/test_lib_pypy/pyrepl/test_keymap.py @@ -0,0 +1,10 @@ +from pyrepl.keymap import compile_keymap + + +def test_compile_keymap(): + k = compile_keymap({ + b'a': 'test', + b'bc': 'test2', + }) + + assert k == {b'a': 'test', b'b': {b'c': 'test2'}} diff --git a/pypy/module/test_lib_pypy/pyrepl/test_readline.py b/pypy/module/test_lib_pypy/pyrepl/test_readline.py new file mode 100644 --- /dev/null +++ b/pypy/module/test_lib_pypy/pyrepl/test_readline.py @@ -0,0 +1,15 @@ +from pyrepl.readline import _ReadlineWrapper +import os +import pty + + +def test_raw_input(): + master, slave = pty.openpty() + readline_wrapper = _ReadlineWrapper(slave, slave) + os.write(master, b'input\n') + + result = readline_wrapper.get_reader().readline() + #result = readline_wrapper.raw_input('prompt:') + assert result == 'input' + # A bytes string on python2, a unicode string on python3. + assert isinstance(result, str) diff --git a/pypy/module/test_lib_pypy/pyrepl/test_wishes.py b/pypy/module/test_lib_pypy/pyrepl/test_wishes.py --- a/pypy/module/test_lib_pypy/pyrepl/test_wishes.py +++ b/pypy/module/test_lib_pypy/pyrepl/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 pyrepl.tests.infrastructure import ReaderTestCase, EA, run_testcase +from .infrastructure import 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(): - run_testcase(WishesTestCase) - -if __name__ == '__main__': - test() +def test_quoted_insert_repeat(): + read_spec([ + (('digit-arg', '3'), ['']), + (('quoted-insert', None), ['']), + (('self-insert', '\033'), ['^[^[^[']), + (('accept', None), None)]) _______________________________________________ pypy-commit mailing list [email protected] http://mail.python.org/mailman/listinfo/pypy-commit
