py2 compat

This commit is contained in:
Krisztián Szűcs committed 2019-09-24 16:49:04 +02:00
1 parent 8585a6085a
commit 88e0c9f792
3 files changed
+21 -17

No files matched your search

+10 -6
View File
@@ -27,6 +27,8 @@ try:
except ImportError:
import pathlib2 as pathlib # py2 compat
from pyarrow.util import find_free_port
# setup hypothesis profiles
h.settings.register_profile('ci', max_examples=1000)
@@ -246,10 +248,10 @@ except ImportError:
shutil.rmtree(self.tmp)
@pytest.fixture(scope='module')
@pytest.fixture(scope='session')
@pytest.mark.s3
def minio_server():
host, port = 'localhost', 9000
host, port = 'localhost', find_free_port()
access_key, secret_key = 'arrow', 'apachearrow'
address = '{}:{}'.format(host, port)
@@ -263,14 +265,16 @@ def minio_server():
with TemporaryDirectory() as tempdir:
args = ['minio', '--compat', 'server', '--quiet', '--address',
address, tempdir]
with subprocess.Popen(args, env=env) as proc:
try:
proc = subprocess.Popen(args, env=env)
yield address, access_key, secret_key
proc.terminate()
finally:
proc.kill()
except IOError:
pytest.skip('`minio` command cannot be located')
@pytest.fixture(scope='module')
@pytest.fixture(scope='session')
def minio_client(minio_server):
minio = pytest.importorskip('minio')
address, access_key, secret_key = minio_server
@@ -282,7 +286,7 @@ def minio_client(minio_server):
)
@pytest.fixture(scope='module')
@pytest.fixture(scope='session')
def minio_bucket(minio_client):
bucket_name = 'pyarrow-bucket'
minio_client.make_bucket(bucket_name)
+1 -11
View File
@@ -17,9 +17,7 @@
# under the License.
import base64
import contextlib
import os
import socket
import struct
import tempfile
import threading
@@ -30,7 +28,7 @@ import pytest
import pyarrow as pa
from pyarrow.compat import tobytes
from pyarrow.util import pathlib
from pyarrow.util import pathlib, find_free_port
try:
from pyarrow import flight
@@ -48,14 +46,6 @@ except ImportError:
pytestmark = pytest.mark.flight
def find_free_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
with contextlib.closing(sock) as sock:
sock.bind(('', 0))
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return sock.getsockname()[1]
def test_import():
# So we see the ImportError somewhere
import pyarrow.flight # noqa
+10
View File
@@ -19,8 +19,10 @@
from __future__ import absolute_import
import contextlib
import functools
import six
import socket
import warnings
@@ -125,3 +127,11 @@ def get_contiguous_span(shape, strides, itemsize):
if end - start != itemsize * product(shape):
raise ValueError('array data is non-contiguous')
return start, end
def find_free_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
with contextlib.closing(sock) as sock:
sock.bind(('', 0))
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return sock.getsockname()[1]