Skip to content

Commit c56690d

Browse files
author
llllllllll
committed
TST: Makes the tests work with python 3.
1 parent 1fa99cf commit c56690d

File tree

7 files changed

+28
-19
lines changed

7 files changed

+28
-19
lines changed

qdb/tracer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from logbook import Logger, FileHandler
2424

2525
from qdb.comm import RemoteCommandManager, fmt_msg
26-
from qdb.compat import map, items
26+
from qdb.compat import map, items, ExitStack
2727
from qdb.config import QdbConfig
2828
from qdb.errors import QdbUnreachableBreakpoint, QdbQuit, QdbExecutionTimeout
2929
from qdb.output import RemoteOutput, OutputTee

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
'Topic :: Software Development :: Debuggers',
6868
],
6969
install_requires=[
70-
'contextlib2',
7170
'Logbook',
7271
'websocket-client',
7372
] + py2_requires,

tests/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
try:
15+
from qdb.compat import gevent
16+
if gevent is not None:
1617
from gevent.monkey import patch_all
17-
except ImportError:
18-
pass
19-
else:
2018
patch_all() # Patch out the modules before executing the tests.
2119

2220
import os

tests/compat.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
from unittest import skipIf
15-
from qdb.compat import PY3
15+
from qdb.compat import PY3, items
1616

1717
try:
1818
from unittest import mock
@@ -28,8 +28,19 @@ def __init__(self, value):
2828
skip_py3 = skipIf(PY3, 'This test will not work with python3')
2929

3030

31+
class Py2TestMeta(type):
32+
def __new__(mcls, name, bases, dict_):
33+
return type.__new__(
34+
mcls,
35+
name,
36+
bases,
37+
{k: skip_py3(v) for k, v in items(dict_) if k.startswith('test_')},
38+
)
39+
40+
3141
__all__ = [
3242
'NonLocal',
43+
'Py2TestMeta',
3344
'mock',
3445
'skip_py3',
3546
]

tests/test_cmd_manager.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from qdb import Qdb
2525
from qdb.comm import RemoteCommandManager, ServerLocalCommandManager, fmt_msg
26-
from qdb.compat import PY2, gevent
26+
from qdb.compat import with_metaclass, PY2, gevent
2727
from qdb.errors import (
2828
QdbFailedToConnect,
2929
QdbAuthenticationError,
@@ -40,6 +40,9 @@
4040
patch = mock.patch
4141
MagicMock = mock.MagicMock
4242

43+
patch = mock.patch
44+
MagicMock = mock.MagicMock
45+
4346

4447
def set_break_params(tracer, filename, lineno, temporary=False, cond=None,
4548
funcname=None, **kwargs):
@@ -56,7 +59,7 @@ def set_break_params(tracer, filename, lineno, temporary=False, cond=None,
5659
}
5760

5861

59-
class RemoteCommandManagerTester(TestCase):
62+
class RemoteCommandManagerTester(with_metaclass(Py2TestMeta, TestCase)):
6063
"""
6164
Tests the various behaviors that the RemoteCommandManager should conform
6265
to. Some tests rely on how the command manager affects the tracer that it

tests/test_server.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
from struct import pack
2020

2121
from qdb.comm import fmt_msg, fmt_err_msg, get_events_from_socket
22-
from qdb.compat import gevent, PY2
23-
24-
from tests.compat import skip_py3
22+
from qdb.compat import gevent, with_metaclass, PY2
2523

2624
if PY2:
2725
# These need python 2
@@ -34,6 +32,8 @@
3432
from qdb.server.session_store import ALLOW_ORPHANS
3533
from qdb.server.client import DEFAULT_ROUTE_FMT
3634

35+
from tests.compat import Py2TestMeta
36+
3737

3838
def send_tracer_event(sck, event, payload):
3939
"""
@@ -68,8 +68,7 @@ def recv_client_event(ws):
6868
return json.loads(ws.recv())
6969

7070

71-
@skip_py3
72-
class ServerTester(TestCase):
71+
class ServerTester(with_metaclass(Py2TestMeta, TestCase)):
7372
def test_start_stop(self):
7473
"""
7574
Tests starting and stopping the server.

tests/utils.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
from time import sleep
1818

1919
from qdb.comm import CommandManager, NopCommandManager
20-
from qdb.compat import PY3
20+
from qdb.compat import gevent, PY3
2121

22-
if PY3:
22+
23+
if gevent is None:
2324
from queue import Queue, Empty
24-
else:
25-
from Queue import Queue, Empty
2625

2726

2827
class QueueCommandManager(CommandManager):
@@ -45,7 +44,7 @@ def user_wait(self, duration):
4544
"""
4645
Simulates waiting on the user to feed us input for duration seconds.
4746
"""
48-
self.enqueue(lambda t: sleep(duration + 1))
47+
self.enqueue(lambda t: sleep(duration + int(PY3)))
4948

5049
def clear(self):
5150
"""

0 commit comments

Comments
 (0)