Skip to content

Commit bcaf0e8

Browse files
committed
tests: merge testing/{infrastructure,test_bugs}.py from PyPy (py3.6)
1 parent ab7da93 commit bcaf0e8

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

testing/infrastructure.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1919

2020
from __future__ import print_function
21+
from contextlib import contextmanager
22+
import os
23+
2124
from pyrepl.reader import Reader
2225
from pyrepl.console import Console, Event
2326

@@ -60,8 +63,7 @@ def getpending(self):
6063
return Event('key', '', b'')
6164

6265

63-
class TestReader(Reader):
64-
__test__ = False
66+
class BaseTestReader(Reader):
6567

6668
def get_prompt(self, lineno, cursor_on_line):
6769
return ''
@@ -71,8 +73,19 @@ def refresh(self):
7173
self.dirty = True
7274

7375

74-
def read_spec(test_spec, reader_class=TestReader):
76+
def read_spec(test_spec, reader_class=BaseTestReader):
7577
# remember to finish your test_spec with 'accept' or similar!
7678
con = TestConsole(test_spec, verbose=True)
7779
reader = reader_class(con)
7880
reader.readline()
81+
82+
83+
@contextmanager
84+
def sane_term():
85+
"""Ensure a TERM that supports clear"""
86+
old_term, os.environ['TERM'] = os.environ.get('TERM'), 'xterm'
87+
yield
88+
if old_term is not None:
89+
os.environ['TERM'] = old_term
90+
else:
91+
del os.environ['TERM']

testing/test_bugs.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1818
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1919

20-
import sys
21-
2220
from pyrepl.historical_reader import HistoricalReader
23-
from .infrastructure import EA, TestReader, read_spec
21+
from .infrastructure import EA, BaseTestReader, sane_term, read_spec
2422

2523
# this test case should contain as-verbatim-as-possible versions of
2624
# (applicable) bug reports
2725

2826
import pytest
2927

3028

31-
class HistoricalTestReader(HistoricalReader, TestReader):
29+
class HistoricalTestReader(HistoricalReader, BaseTestReader):
3230
pass
3331

3432

@@ -48,7 +46,8 @@ def test_cmd_instantiation_crash():
4846
read_spec(spec, HistoricalTestReader)
4947

5048

51-
@pytest.mark.skipif(sys.platform == "osx", reason="hangs on osx")
49+
@pytest.mark.skipif("os.name != 'posix' or 'darwin' in sys.platform or "
50+
"'kfreebsd' in sys.platform")
5251
def test_signal_failure(monkeypatch):
5352
import os
5453
import pty
@@ -63,13 +62,14 @@ def really_failing_signal(a, b):
6362

6463
mfd, sfd = pty.openpty()
6564
try:
66-
c = UnixConsole(sfd, sfd)
67-
c.prepare()
68-
c.restore()
69-
monkeypatch.setattr(signal, 'signal', failing_signal)
70-
c.prepare()
71-
monkeypatch.setattr(signal, 'signal', really_failing_signal)
72-
c.restore()
65+
with sane_term():
66+
c = UnixConsole(sfd, sfd)
67+
c.prepare()
68+
c.restore()
69+
monkeypatch.setattr(signal, 'signal', failing_signal)
70+
c.prepare()
71+
monkeypatch.setattr(signal, 'signal', really_failing_signal)
72+
c.restore()
7373
finally:
7474
os.close(mfd)
7575
os.close(sfd)

0 commit comments

Comments
 (0)