aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Lamy <ronan.lamy@gmail.com>2018-02-20 02:39:12 +0000
committerRonan Lamy <ronan.lamy@gmail.com>2018-02-20 02:39:12 +0000
commit187b95055e4d9901323ed8bbe51d22146f17f08b (patch)
tree9e2837bd992f78bac10031afac7f4687eeb218d9 /extra_tests/test_pyrepl
parentfind the correct place to modify the tp_basicsize for "date" (diff)
downloadpypy-187b95055e4d9901323ed8bbe51d22146f17f08b.tar.gz
pypy-187b95055e4d9901323ed8bbe51d22146f17f08b.tar.bz2
pypy-187b95055e4d9901323ed8bbe51d22146f17f08b.zip
Move pyrepl tests to extra_tests/
Diffstat (limited to 'extra_tests/test_pyrepl')
-rw-r--r--extra_tests/test_pyrepl/__init__.py1
-rw-r--r--extra_tests/test_pyrepl/infrastructure.py87
-rw-r--r--extra_tests/test_pyrepl/test_basic.py116
-rw-r--r--extra_tests/test_pyrepl/test_bugs.py75
-rw-r--r--extra_tests/test_pyrepl/test_functional.py27
-rw-r--r--extra_tests/test_pyrepl/test_keymap.py10
-rw-r--r--extra_tests/test_pyrepl/test_reader.py9
-rw-r--r--extra_tests/test_pyrepl/test_readline.py22
-rw-r--r--extra_tests/test_pyrepl/test_wishes.py31
9 files changed, 378 insertions, 0 deletions
diff --git a/extra_tests/test_pyrepl/__init__.py b/extra_tests/test_pyrepl/__init__.py
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/extra_tests/test_pyrepl/__init__.py
@@ -0,0 +1 @@
+
diff --git a/extra_tests/test_pyrepl/infrastructure.py b/extra_tests/test_pyrepl/infrastructure.py
new file mode 100644
index 0000000000..b199e0dfa3
--- /dev/null
+++ b/extra_tests/test_pyrepl/infrastructure.py
@@ -0,0 +1,87 @@
+# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
+#
+# 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.
+
+from __future__ import print_function
+from contextlib import contextmanager
+import os
+
+from pyrepl.reader import Reader
+from pyrepl.console import Console, Event
+
+
+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, verbose=False):
+ self.events = events
+ self.next_screen = None
+ self.verbose = verbose
+
+ def refresh(self, screen, xy):
+ if self.next_screen is not None:
+ 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, None)
+ self.last_event_name = ev[0]
+ if self.verbose:
+ print("event", ev)
+ return Event(*ev)
+
+
+class BaseTestReader(Reader):
+
+ def get_prompt(self, lineno, cursor_on_line):
+ return ''
+
+ def refresh(self):
+ Reader.refresh(self)
+ self.dirty = True
+
+
+def read_spec(test_spec, reader_class=BaseTestReader):
+ # remember to finish your test_spec with 'accept' or similar!
+ con = TestConsole(test_spec, verbose=True)
+ reader = reader_class(con)
+ reader.readline()
+
+
+@contextmanager
+def sane_term():
+ """Ensure a TERM that supports clear"""
+ old_term, os.environ['TERM'] = os.environ.get('TERM'), 'xterm'
+ yield
+ if old_term is not None:
+ os.environ['TERM'] = old_term
+ else:
+ del os.environ['TERM']
diff --git a/extra_tests/test_pyrepl/test_basic.py b/extra_tests/test_pyrepl/test_basic.py
new file mode 100644
index 0000000000..1c69636504
--- /dev/null
+++ b/extra_tests/test_pyrepl/test_basic.py
@@ -0,0 +1,116 @@
+# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
+#
+# 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.
+import pytest
+from .infrastructure import read_spec
+
+
+def test_basic():
+ read_spec([(('self-insert', 'a'), ['a']),
+ ( 'accept', ['a'])])
+
+
+def test_repeat():
+ read_spec([(('digit-arg', '3'), ['']),
+ (('self-insert', 'a'), ['aaa']),
+ ( 'accept', ['aaa'])])
+
+
+def test_kill_line():
+ read_spec([(('self-insert', 'abc'), ['abc']),
+ ( 'left', None),
+ ( 'kill-line', ['ab']),
+ ( 'accept', ['ab'])])
+
+
+def test_unix_line_discard():
+ read_spec([(('self-insert', 'abc'), ['abc']),
+ ( 'left', None),
+ ( 'unix-word-rubout', ['c']),
+ ( 'accept', ['c'])])
+
+
+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():
+ read_spec([(('self-insert', 'ab cd'), ['ab cd']),
+ ( 'backward-kill-word', ['ab ']),
+ ( 'accept', ['ab '])])
+
+
+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 '])])
+
+
+# interrupt uses os.kill which doesn't go through signal handlers on windows
+@pytest.mark.skipif("os.name == 'nt'")
+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/extra_tests/test_pyrepl/test_bugs.py b/extra_tests/test_pyrepl/test_bugs.py
new file mode 100644
index 0000000000..2c4fc7c965
--- /dev/null
+++ b/extra_tests/test_pyrepl/test_bugs.py
@@ -0,0 +1,75 @@
+# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
+#
+# 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.
+
+from pyrepl.historical_reader import HistoricalReader
+from .infrastructure import EA, BaseTestReader, sane_term, read_spec
+
+# this test case should contain as-verbatim-as-possible versions of
+# (applicable) bug reports
+
+import pytest
+
+
+class HistoricalTestReader(HistoricalReader, BaseTestReader):
+ pass
+
+
+@pytest.mark.xfail(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)
+
+
+@pytest.mark.skipif("os.name != 'posix' or 'darwin' in sys.platform or "
+ "'kfreebsd' in sys.platform")
+def test_signal_failure(monkeypatch):
+ import os
+ import pty
+ import signal
+ from pyrepl.unix_console import UnixConsole
+
+ def failing_signal(a, b):
+ raise ValueError
+
+ def really_failing_signal(a, b):
+ raise AssertionError
+
+ mfd, sfd = pty.openpty()
+ try:
+ with sane_term():
+ c = UnixConsole(sfd, sfd)
+ c.prepare()
+ c.restore()
+ monkeypatch.setattr(signal, 'signal', failing_signal)
+ c.prepare()
+ monkeypatch.setattr(signal, 'signal', really_failing_signal)
+ c.restore()
+ finally:
+ os.close(mfd)
+ os.close(sfd)
diff --git a/extra_tests/test_pyrepl/test_functional.py b/extra_tests/test_pyrepl/test_functional.py
new file mode 100644
index 0000000000..ddca934e0c
--- /dev/null
+++ b/extra_tests/test_pyrepl/test_functional.py
@@ -0,0 +1,27 @@
+# Copyright 2000-2007 Michael Hudson-Doyle <micahel@gmail.com>
+# Maciek Fijalkowski
+# License: MIT
+# some functional tests, to see if this is really working
+
+import pytest
+import sys
+
+
+def pytest_funcarg__child(request):
+ try:
+ import pexpect
+ except ImportError:
+ pytest.skip("no pexpect module")
+ 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(child):
+ child.sendline('a = 3')
+ child.sendline('a')
+ child.expect('3')
diff --git a/extra_tests/test_pyrepl/test_keymap.py b/extra_tests/test_pyrepl/test_keymap.py
new file mode 100644
index 0000000000..12c4f0d878
--- /dev/null
+++ b/extra_tests/test_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/extra_tests/test_pyrepl/test_reader.py b/extra_tests/test_pyrepl/test_reader.py
new file mode 100644
index 0000000000..4b93ffa598
--- /dev/null
+++ b/extra_tests/test_pyrepl/test_reader.py
@@ -0,0 +1,9 @@
+
+def test_process_prompt():
+ from pyrepl.reader import Reader
+ r = Reader(None)
+ assert r.process_prompt("hi!") == ("hi!", 3)
+ assert r.process_prompt("h\x01i\x02!") == ("hi!", 2)
+ assert r.process_prompt("hi\033[11m!") == ("hi\033[11m!", 3)
+ assert r.process_prompt("h\x01i\033[11m!\x02") == ("hi\033[11m!", 1)
+ assert r.process_prompt("h\033[11m\x01i\x02!") == ("h\033[11mi!", 2)
diff --git a/extra_tests/test_pyrepl/test_readline.py b/extra_tests/test_pyrepl/test_readline.py
new file mode 100644
index 0000000000..32c4033dc4
--- /dev/null
+++ b/extra_tests/test_pyrepl/test_readline.py
@@ -0,0 +1,22 @@
+import pytest
+
+from .infrastructure import sane_term
+
+
+@pytest.mark.skipif("os.name != 'posix' or 'darwin' in sys.platform or "
+ "'freebsd' in sys.platform")
+def test_raw_input():
+ import os
+ import pty
+ from pyrepl.readline import _ReadlineWrapper
+
+ master, slave = pty.openpty()
+ readline_wrapper = _ReadlineWrapper(slave, slave)
+ os.write(master, b'input\n')
+
+ with sane_term():
+ 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/extra_tests/test_pyrepl/test_wishes.py b/extra_tests/test_pyrepl/test_wishes.py
new file mode 100644
index 0000000000..650dff7cd0
--- /dev/null
+++ b/extra_tests/test_pyrepl/test_wishes.py
@@ -0,0 +1,31 @@
+# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
+#
+# 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.
+
+from .infrastructure import read_spec
+
+# this test case should contain as-verbatim-as-possible versions of
+# (applicable) feature requests
+
+
+def test_quoted_insert_repeat():
+ read_spec([
+ (('digit-arg', '3'), ['']),
+ (('quoted-insert', None), ['']),
+ (('self-insert', '\033'), ['^[^[^[']),
+ (('accept', None), None)])