diff --git a/tests/conftest.py b/tests/conftest.py index 514c604..044963b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1 @@ -import sys - collect_ignore = ["setup.py"] -if sys.version_info < (3, 5): - collect_ignore.append("test_aio.py") diff --git a/tests/test_framed_transport.py b/tests/test_framed_transport.py index e3a8ca2..8959408 100644 --- a/tests/test_framed_transport.py +++ b/tests/test_framed_transport.py @@ -2,7 +2,6 @@ from __future__ import absolute_import -import sys import logging import socket import threading @@ -11,7 +10,6 @@ from os import path from unittest import TestCase -import pytest from tornado import ioloop import thriftpy2 @@ -103,7 +101,6 @@ def setUp(self): def tearDown(self): self.io_loop.stop() - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_make_client(self): linus = addressbook.Person('Linus Torvalds') success = self.client_created_using_url.add(linus) @@ -111,7 +108,6 @@ def test_make_client(self): success = self.client.add(linus) assert not success - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_able_to_communicate(self): dennis = addressbook.Person(name='Dennis Ritchie') success = self.client.add(dennis) @@ -119,7 +115,6 @@ def test_able_to_communicate(self): success = self.client.add(dennis) assert not success - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_zero_length_string(self): dennis = addressbook.Person(name='') success = self.client.add(dennis) diff --git a/tests/test_tornado.py b/tests/test_tornado.py index 1ad603f..83bf354 100644 --- a/tests/test_tornado.py +++ b/tests/test_tornado.py @@ -10,7 +10,6 @@ import logging import socket - import pytest from tornado import gen, testing import thriftpy2 @@ -104,7 +103,6 @@ def tearDown(self): super(TornadoRPCTestCase, self).tearDown() @testing.gen_test - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_make_client(self): linus = addressbook.Person(name='Linus Torvalds') success = yield self.client_with_url.add(linus) @@ -113,7 +111,6 @@ def test_make_client(self): assert not success @testing.gen_test - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_synchronous_result(self): dennis = addressbook.Person(name='Dennis Ritchie') success = yield self.client.add(dennis) @@ -124,7 +121,6 @@ def test_synchronous_result(self): assert person.name == dennis.name @testing.gen_test - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_synchronous_exception(self): exc = None try: @@ -135,7 +131,6 @@ def test_synchronous_exception(self): assert isinstance(exc, addressbook.PersonNotExistsError) @testing.gen_test - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_synchronous_undeclared_exception(self): exc = None try: @@ -146,7 +141,6 @@ def test_synchronous_undeclared_exception(self): assert isinstance(exc, TTransportException) @testing.gen_test - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_asynchronous_result(self): dennis = addressbook.Person(name='Dennis Ritchie') yield self.client.add(dennis) @@ -154,7 +148,6 @@ def test_asynchronous_result(self): assert success @testing.gen_test - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_asynchronous_exception(self): exc = None try: @@ -164,7 +157,6 @@ def test_asynchronous_exception(self): assert isinstance(exc, addressbook.PersonNotExistsError) @testing.gen_test - @pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support") def test_asynchronous_undeclared_exception(self): exc = None try: diff --git a/thriftpy2/hook.py b/thriftpy2/hook.py index f38d621..6d709e1 100644 --- a/thriftpy2/hook.py +++ b/thriftpy2/hook.py @@ -2,6 +2,8 @@ from __future__ import absolute_import +import importlib.abc +import importlib.util import sys from .parser import load_module @@ -10,41 +12,26 @@ # TODO: The load process does not compatible with Python standard, e.g., if the # specified thrift file does not exists, it raises FileNotFoundError, and skiped # the other meta finders in the sys.meta_path. -if sys.version_info >= (3, 4): - import importlib.abc - import importlib.util +class ThriftImporter(importlib.abc.MetaPathFinder): + def __init__(self, extension="_thrift"): + self.extension = extension - class ThriftImporter(importlib.abc.MetaPathFinder): - def __init__(self, extension="_thrift"): - self.extension = extension + def find_spec(self, fullname, path, target=None): + if not fullname.endswith(self.extension): + return None + return importlib.util.spec_from_loader(fullname, + ThriftLoader(fullname)) - def find_spec(self, fullname, path, target=None): - if not fullname.endswith(self.extension): - return None - return importlib.util.spec_from_loader(fullname, - ThriftLoader(fullname)) +class ThriftLoader(importlib.abc.Loader): + def __init__(self, fullname): + self.fullname = fullname - class ThriftLoader(importlib.abc.Loader): - def __init__(self, fullname): - self.fullname = fullname + def create_module(self, spec): + return load_module(self.fullname) - def create_module(self, spec): - return load_module(self.fullname) - - def exec_module(self, module): - pass -else: - class ThriftImporter(object): - def __init__(self, extension="_thrift"): - self.extension = extension - - def find_module(self, fullname, path=None): - if fullname.endswith(self.extension): - return self - - def load_module(self, fullname): - return load_module(fullname) + def exec_module(self, module): + pass _imp = ThriftImporter() diff --git a/thriftpy2/parser/parser.py b/thriftpy2/parser/parser.py index 69783c3..5948d0f 100644 --- a/thriftpy2/parser/parser.py +++ b/thriftpy2/parser/parser.py @@ -540,9 +540,6 @@ def parse(path, module_name=None, include_dirs=None, include_dir=None, cached, this is enabled by default. If `module_name` is provided, use it as cache key, else use the `path`. """ - if os.name == 'nt' and sys.version_info[0] < 3: - os.path.samefile = lambda f1, f2: os.stat(f1) == os.stat(f2) - # dead include checking on current stack for thrift in thrift_stack: if thrift.__thrift_file__ is not None and \