Skip to content

Commit

Permalink
py2 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Sep 24, 2019
1 parent 8585a60 commit 88e0c9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
16 changes: 10 additions & 6 deletions python/pyarrow/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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)
Expand Down Expand Up @@ -246,10 +248,10 @@ def __exit__(self, exc_type, exc_value, traceback):
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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
12 changes: 1 addition & 11 deletions python/pyarrow/tests/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
# under the License.

import base64
import contextlib
import os
import socket
import struct
import tempfile
import threading
Expand All @@ -30,7 +28,7 @@
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
Expand All @@ -48,14 +46,6 @@
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
Expand Down
10 changes: 10 additions & 0 deletions python/pyarrow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

from __future__ import absolute_import

import contextlib
import functools
import six
import socket
import warnings


Expand Down Expand Up @@ -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]

0 comments on commit 88e0c9f

Please sign in to comment.