forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
267 lines (226 loc) · 6.17 KB
/
Copy pathconftest.py
File metadata and controls
267 lines (226 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import pytest
from pyarrow import Codec
from pyarrow import fs
groups = [
'brotli',
'bz2',
'cython',
'dataset',
'hypothesis',
'fastparquet',
'gandiva',
'gcs',
'gdb',
'gzip',
'hdfs',
'large_memory',
'lz4',
'memory_leak',
'nopandas',
'orc',
'pandas',
'parquet',
'parquet_encryption',
'plasma',
's3',
'snappy',
'substrait',
'tensorflow',
'flight',
'slow',
'requires_testing_data',
'zstd',
]
defaults = {
'brotli': Codec.is_available('brotli'),
'bz2': Codec.is_available('bz2'),
'cython': False,
'dataset': False,
'fastparquet': False,
'flight': False,
'gandiva': False,
'gcs': False,
'gdb': True,
'gzip': Codec.is_available('gzip'),
'hdfs': False,
'hypothesis': False,
'large_memory': False,
'lz4': Codec.is_available('lz4'),
'memory_leak': False,
'nopandas': False,
'orc': False,
'pandas': False,
'parquet': False,
'parquet_encryption': False,
'plasma': False,
'requires_testing_data': True,
's3': False,
'slow': False,
'snappy': Codec.is_available('snappy'),
'substrait': False,
'tensorflow': False,
'zstd': Codec.is_available('zstd'),
}
try:
import cython # noqa
defaults['cython'] = True
except ImportError:
pass
try:
import fastparquet # noqa
defaults['fastparquet'] = True
except ImportError:
pass
try:
import pyarrow.gandiva # noqa
defaults['gandiva'] = True
except ImportError:
pass
try:
import pyarrow.dataset # noqa
defaults['dataset'] = True
except ImportError:
pass
try:
import pyarrow.orc # noqa
defaults['orc'] = True
except ImportError:
pass
try:
import pandas # noqa
defaults['pandas'] = True
except ImportError:
defaults['nopandas'] = True
try:
import pyarrow.parquet # noqa
defaults['parquet'] = True
except ImportError:
pass
try:
import pyarrow.parquet.encryption # noqa
defaults['parquet_encryption'] = True
except ImportError:
pass
try:
import pyarrow.plasma # noqa
defaults['plasma'] = True
except ImportError:
pass
try:
import tensorflow # noqa
defaults['tensorflow'] = True
except ImportError:
pass
try:
import pyarrow.flight # noqa
defaults['flight'] = True
except ImportError:
pass
try:
from pyarrow.fs import GcsFileSystem # noqa
defaults['gcs'] = True
except ImportError:
pass
try:
from pyarrow.fs import S3FileSystem # noqa
defaults['s3'] = True
except ImportError:
pass
try:
from pyarrow.fs import HadoopFileSystem # noqa
defaults['hdfs'] = True
except ImportError:
pass
try:
import pyarrow.substrait # noqa
defaults['substrait'] = True
except ImportError:
pass
# Doctest should ignore files for the modules that are not built
def pytest_ignore_collect(path, config):
if config.option.doctestmodules:
# don't try to run doctests on the /tests directory
if "/pyarrow/tests/" in str(path):
return True
doctest_groups = [
'dataset',
'orc',
'parquet',
'plasma',
'flight',
'substrait',
]
# handle cuda, flight, etc
for group in doctest_groups:
if 'pyarrow/{}'.format(group) in str(path):
if not defaults[group]:
return True
if 'pyarrow/parquet/encryption' in str(path):
if not defaults['parquet_encryption']:
return True
if 'pyarrow/cuda' in str(path):
try:
import pyarrow.cuda # noqa
return False
except ImportError:
return True
if 'pyarrow/fs' in str(path):
try:
from pyarrow.fs import S3FileSystem # noqa
return False
except ImportError:
return True
if getattr(config.option, "doctest_cython", False):
if "/pyarrow/tests/" in str(path):
return True
if "/pyarrow/_parquet_encryption" in str(path):
return True
return False
# Save output files from doctest examples into temp dir
@pytest.fixture(autouse=True)
def _docdir(request):
# Trigger ONLY for the doctests
doctest_m = request.config.option.doctestmodules
doctest_c = getattr(request.config.option, "doctest_cython", False)
if doctest_m or doctest_c:
# Get the fixture dynamically by its name.
tmpdir = request.getfixturevalue('tmpdir')
# Chdir only for the duration of the test.
with tmpdir.as_cwd():
yield
else:
yield
# Define doctest_namespace for fs module docstring import
@pytest.fixture(autouse=True)
def add_fs(doctest_namespace, request, tmp_path):
# Trigger ONLY for the doctests
doctest_m = request.config.option.doctestmodules
doctest_c = getattr(request.config.option, "doctest_cython", False)
if doctest_m or doctest_c:
# fs import
doctest_namespace["fs"] = fs
# Creation of an object and file with data
local = fs.LocalFileSystem()
path = tmp_path / 'pyarrow-fs-example.dat'
with local.open_output_stream(str(path)) as stream:
stream.write(b'data')
doctest_namespace["local"] = local
doctest_namespace["local_path"] = str(tmp_path)
doctest_namespace["path"] = str(path)
yield