本文整理汇总了Python中pytest.importorskip函数的典型用法代码示例。如果您正苦于以下问题:Python importorskip函数的具体用法?Python importorskip怎么用?Python importorskip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了importorskip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scan
def test_scan(ctx_factory, dtype, scan_cls):
from pytest import importorskip
importorskip("mako")
context = ctx_factory()
queue = cl.CommandQueue(context)
knl = scan_cls(context, dtype, "a+b", "0")
for n in scan_test_counts:
host_data = np.random.randint(0, 10, n).astype(dtype)
dev_data = cl_array.to_device(queue, host_data)
# /!\ fails on Nv GT2?? for some drivers
assert (host_data == dev_data.get()).all()
knl(dev_data)
desired_result = np.cumsum(host_data, axis=0)
if scan_cls is ExclusiveScanKernel:
desired_result -= host_data
is_ok = (dev_data.get() == desired_result).all()
if 1 and not is_ok:
print("something went wrong, summarizing error...")
print(summarize_error(dev_data.get(), desired_result, host_data))
print("dtype:%s n:%d %s worked:%s" % (dtype, n, scan_cls, is_ok))
assert is_ok
from gc import collect
collect()
示例2: test_writing_parquet_with_kwargs
def test_writing_parquet_with_kwargs(tmpdir, engine):
fn = str(tmpdir)
path1 = os.path.join(fn, 'normal')
path2 = os.path.join(fn, 'partitioned')
pytest.importorskip("snappy")
df = pd.DataFrame({'a': np.random.choice(['A', 'B', 'C'], size=100),
'b': np.random.random(size=100),
'c': np.random.randint(1, 5, size=100)})
ddf = dd.from_pandas(df, npartitions=3)
engine_kwargs = {
'pyarrow': {
'compression': 'snappy',
'coerce_timestamps': None,
'use_dictionary': True
},
'fastparquet': {
'compression': 'snappy',
'times': 'int64',
'fixed_text': None
}
}
ddf.to_parquet(path1, engine=engine, **engine_kwargs[engine])
out = dd.read_parquet(path1, engine=engine, infer_divisions=should_check_divs(engine))
assert_eq(out, ddf, check_index=(engine != 'fastparquet'), check_divisions=should_check_divs(engine))
# Avoid race condition in pyarrow 0.8.0 on writing partitioned datasets
with dask.config.set(scheduler='sync'):
ddf.to_parquet(path2, engine=engine, partition_on=['a'],
**engine_kwargs[engine])
out = dd.read_parquet(path2, engine=engine).compute()
for val in df.a.unique():
assert set(df.b[df.a == val]) == set(out.b[out.a == val])
示例3: test_get_store
def test_get_store(self):
pytest.importorskip('tables')
with tm.ensure_clean() as path:
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
s = pd.get_store(path)
s.close()
示例4: test_to_castra
def test_to_castra():
pytest.importorskip("castra")
df = pd.DataFrame({"x": ["a", "b", "c", "d"], "y": [2, 3, 4, 5]}, index=pd.Index([1.0, 2.0, 3.0, 4.0], name="ind"))
a = dd.from_pandas(df, 2)
c = a.to_castra()
b = c.to_dask()
try:
tm.assert_frame_equal(df, c[:])
tm.assert_frame_equal(b.compute(), df)
finally:
c.drop()
c = a.to_castra(categories=["x"])
try:
assert c[:].dtypes["x"] == "category"
finally:
c.drop()
c = a.to_castra(sorted_index_column="y")
try:
tm.assert_frame_equal(c[:], df.set_index("y"))
finally:
c.drop()
dsk, keys = a.to_castra(compute=False)
assert isinstance(dsk, dict)
assert isinstance(keys, list)
c, last = keys
assert last[1] == a.npartitions - 1
示例5: test_nose_setup_partial
def test_nose_setup_partial(testdir):
pytest.importorskip("functools")
p = testdir.makepyfile("""
from functools import partial
values = []
def my_setup(x):
a = x
values.append(a)
def my_teardown(x):
b = x
values.append(b)
my_setup_partial = partial(my_setup, 1)
my_teardown_partial = partial(my_teardown, 2)
def test_hello():
print (values)
assert values == [1]
def test_world():
print (values)
assert values == [1,2]
test_hello.setup = my_setup_partial
test_hello.teardown = my_teardown_partial
""")
result = testdir.runpytest(p, '-p', 'nose')
result.stdout.fnmatch_lines([
"*2 passed*"
])
示例6: test_hdf_key
def test_hdf_key(self, tmpdir):
pytest.importorskip('tables')
# tmp hdf store
folder = str(tmpdir)
vo = v.drop('o', axis=1)
vs = pd.HDFStore(folder + 'vs.h5', mode='w')
vs.put('v', vo, format='t', data_columns=True, index=False)
e_true = e_full_true[(e_full_true.dsi <= 3) &
(e_full_true.dsf <= 1)]
g = DeepGraph(vs)
g.create_edges(selectors=[dsi_dsf_t], hdf_key='v')
e_test = g.e
pdt.assert_frame_equal(e_test.sort(axis=1), e_true.sort(axis=1))
g.create_edges_ft(('si', v.si.max()),
selectors=[dsi_dsf_t], hdf_key='v')
e_test = g.e.drop('ft_r', axis=1)
vs.close()
pdt.assert_frame_equal(e_test.sort(axis=1), e_true.sort(axis=1))
示例7: test_to_castra
def test_to_castra():
pytest.importorskip('castra')
df = pd.DataFrame({'x': ['a', 'b', 'c', 'd'],
'y': [2, 3, 4, 5]},
index=pd.Index([1., 2., 3., 4.], name='ind'))
a = dd.from_pandas(df, 2)
c = a.to_castra()
b = c.to_dask()
try:
tm.assert_frame_equal(df, c[:])
tm.assert_frame_equal(b.compute(), df)
finally:
c.drop()
c = a.to_castra(categories=['x'])
try:
assert c[:].dtypes['x'] == 'category'
finally:
c.drop()
c = a.to_castra(sorted_index_column='y')
try:
tm.assert_frame_equal(c[:], df.set_index('y'))
finally:
c.drop()
dsk, keys = a.to_castra(compute=False)
assert isinstance(dsk, dict)
assert isinstance(keys, list)
c, last = keys
assert last[1] == a.npartitions - 1
示例8: test_dot
def test_dot(ctx_factory):
from pytest import importorskip
importorskip("mako")
context = ctx_factory()
queue = cl.CommandQueue(context)
dtypes = [np.float32, np.complex64]
if has_double_support(context.devices[0]):
dtypes.extend([np.float64, np.complex128])
for a_dtype in dtypes:
for b_dtype in dtypes:
print(a_dtype, b_dtype)
a_gpu = general_clrand(queue, (200000,), a_dtype)
a = a_gpu.get()
b_gpu = general_clrand(queue, (200000,), b_dtype)
b = b_gpu.get()
dot_ab = np.dot(a, b)
dot_ab_gpu = cl_array.dot(a_gpu, b_gpu).get()
assert abs(dot_ab_gpu - dot_ab) / abs(dot_ab) < 1e-4
vdot_ab = np.vdot(a, b)
vdot_ab_gpu = cl_array.vdot(a_gpu, b_gpu).get()
assert abs(vdot_ab_gpu - vdot_ab) / abs(vdot_ab) < 1e-4
示例9: test_struct_reduce
def test_struct_reduce(ctx_factory):
pytest.importorskip("mako")
context = ctx_factory()
queue = cl.CommandQueue(context)
dev, = context.devices
if (dev.vendor == "NVIDIA" and dev.platform.vendor == "Apple"
and dev.driver_version == "8.12.47 310.40.00.05f01"):
pytest.skip("causes a compiler hang on Apple/Nv GPU")
mmc_dtype, mmc_c_decl = make_mmc_dtype(context.devices[0])
preamble = mmc_c_decl + r"""//CL//
minmax_collector mmc_neutral()
{
// FIXME: needs infinity literal in real use, ok here
minmax_collector result;
result.cur_min = 1<<30;
result.cur_max = -(1<<30);
return result;
}
minmax_collector mmc_from_scalar(float x)
{
minmax_collector result;
result.cur_min = x;
result.cur_max = x;
return result;
}
minmax_collector agg_mmc(minmax_collector a, minmax_collector b)
{
minmax_collector result = a;
if (b.cur_min < result.cur_min)
result.cur_min = b.cur_min;
if (b.cur_max > result.cur_max)
result.cur_max = b.cur_max;
return result;
}
"""
from pyopencl.clrandom import rand as clrand
a_gpu = clrand(queue, (20000,), dtype=np.int32, a=0, b=10**6)
a = a_gpu.get()
from pyopencl.reduction import ReductionKernel
red = ReductionKernel(context, mmc_dtype,
neutral="mmc_neutral()",
reduce_expr="agg_mmc(a, b)", map_expr="mmc_from_scalar(x[i])",
arguments="__global int *x", preamble=preamble)
minmax = red(a_gpu).get()
#print minmax["cur_min"], minmax["cur_max"]
#print np.min(a), np.max(a)
assert abs(minmax["cur_min"] - np.min(a)) < 1e-5
assert abs(minmax["cur_max"] - np.max(a)) < 1e-5
示例10: test_subsolvers_L2
def test_subsolvers_L2(rng, logger):
pytest.importorskip('scipy', minversion='0.11') # version for lsmr
ref_solver = cholesky
solvers = [conjgrad, block_conjgrad, conjgrad_scipy, lsmr_scipy]
A, B = get_system(m=2000, n=1000, d=10, rng=rng)
sigma = 0.1 * A.max()
with Timer() as t0:
x0, _ = ref_solver(A, B, sigma)
xs = np.zeros((len(solvers),) + x0.shape)
for i, solver in enumerate(solvers):
with Timer() as t:
xs[i], info = solver(A, B, sigma)
logger.info('solver: %s', solver.__name__)
logger.info('duration: %0.3f', t.duration)
logger.info('duration relative to reference solver: %0.2f',
(t.duration / t0.duration))
logger.info('info: %s', info)
for solver, x in zip(solvers, xs):
assert np.allclose(x0, x, atol=1e-5, rtol=1e-3), (
"Solver %s" % solver.__name__)
示例11: test_resources_provider_for_loader
def test_resources_provider_for_loader(self, testdir):
"""
Attempts to load resources from a package should succeed normally,
even when the AssertionRewriteHook is used to load the modules.
See #366 for details.
"""
pytest.importorskip("pkg_resources")
testdir.mkpydir('testpkg')
contents = {
'testpkg/test_pkg': """
import pkg_resources
import pytest
from _pytest.assertion.rewrite import AssertionRewritingHook
def test_load_resource():
assert isinstance(__loader__, AssertionRewritingHook)
res = pkg_resources.resource_string(__name__, 'resource.txt')
res = res.decode('ascii')
assert res == 'Load me please.'
""",
}
testdir.makepyfile(**contents)
testdir.maketxtfile(**{'testpkg/resource': "Load me please."})
result = testdir.runpytest_subprocess()
result.assert_outcomes(passed=1)
示例12: test_init
def test_init(backend, qapp, tmpdir, monkeypatch, cleanup_init):
if backend == usertypes.Backend.QtWebKit:
pytest.importorskip('PyQt5.QtWebKitWidgets')
else:
assert backend == usertypes.Backend.QtWebEngine
monkeypatch.setattr(history.objects, 'backend', backend)
history.init(qapp)
hist = objreg.get('web-history')
assert hist.parent() is qapp
try:
from PyQt5.QtWebKit import QWebHistoryInterface
except ImportError:
QWebHistoryInterface = None
if backend == usertypes.Backend.QtWebKit:
default_interface = QWebHistoryInterface.defaultInterface()
assert default_interface._history is hist
else:
assert backend == usertypes.Backend.QtWebEngine
if QWebHistoryInterface is None:
default_interface = None
else:
default_interface = QWebHistoryInterface.defaultInterface()
# For this to work, nothing can ever have called setDefaultInterface
# before (so we need to test webengine before webkit)
assert default_interface is None
示例13: test_boxed_option_default
def test_boxed_option_default(self, testdir):
tmpdir = testdir.tmpdir.ensure("subdir", dir=1)
config = testdir.parseconfig()
assert not config.option.boxed
pytest.importorskip("execnet")
config = testdir.parseconfig('-d', tmpdir)
assert not config.option.boxed
示例14: dont_test_dataframes
def dont_test_dataframes(s, a): # slow
pytest.importorskip('pandas')
n = 3000000
fn = '/tmp/test/file.csv'
with make_hdfs() as hdfs:
data = (b'name,amount,id\r\n' +
b'Alice,100,1\r\nBob,200,2\r\n' * n)
with hdfs.open(fn, 'w') as f:
f.write(data)
e = Executor((s.ip, s.port), start=False)
yield e._start()
futures = read_bytes(fn, hdfs=hdfs, delimiter=b'\r\n')
assert len(futures) > 1
def load(b, **kwargs):
assert b
from io import BytesIO
import pandas as pd
bio = BytesIO(b)
return pd.read_csv(bio, **kwargs)
dfs = e.map(load, futures, names=['name', 'amount', 'id'], skiprows=1)
dfs2 = yield e._gather(dfs)
assert sum(map(len, dfs2)) == n * 2 - 1
示例15: test_to_hdf_thread
def test_to_hdf_thread():
pytest.importorskip('tables')
df = pd.DataFrame({'x': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'],
'y': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]},
index=[1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16.])
a = dd.from_pandas(df, 16)
# test single file single node
with tmpfile('h5') as fn:
a.to_hdf(fn, '/data', get=dask.threaded.get)
out = pd.read_hdf(fn, '/data')
eq(df, out)
# test multiple files single node
with tmpdir() as dn:
fn = os.path.join(dn, 'data_*.h5')
a.to_hdf(fn, '/data', get=dask.threaded.get)
out = dd.read_hdf(fn, '/data')
eq(df, out)
# test single file multiple nodes
with tmpfile('h5') as fn:
a.to_hdf(fn, '/data*', get=dask.threaded.get)
out = dd.read_hdf(fn, '/data*')
eq(df, out)