提交 cac3e5b1 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Use pytest.importorskip with optional libraries

上级 f3e6e78e
...@@ -3,10 +3,16 @@ ignore=E501,E123,E133,FI12,FI14,FI15,FI50,FI51,FI53,W503,W504,E203,C901,E231,E74 ...@@ -3,10 +3,16 @@ ignore=E501,E123,E133,FI12,FI14,FI15,FI50,FI51,FI53,W503,W504,E203,C901,E231,E74
per-file-ignores = per-file-ignores =
theano/sparse/sandbox/truedot.py:F401 theano/sparse/sandbox/truedot.py:F401
theano/sparse/sandbox/sp2.py:F401 theano/sparse/sandbox/sp2.py:F401
theano/gpuarray/tests/test_type.py:E402
theano/gpuarray/tests/test_abstractconv.py:E402
theano/gpuarray/tests/test_dnn.py:E402
theano/gpuarray/tests/test_elemwise.py:E402
theano/gpuarray/tests/test_others.py:E402
theano/gpuarray/tests/test_basic_ops.py:E402
exclude = exclude =
versioneer.py versioneer.py
doc/ doc/
__init__.py, __init__.py
theano/_version.py theano/_version.py
[versioneer] [versioneer]
......
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
import pytest import pytest
import numpy as np import numpy as np
pygpu = pytest.importorskip("pygpu")
gpuarray = pygpu.gpuarray
from theano.tensor.nnet.tests.test_abstract_conv import ( from theano.tensor.nnet.tests.test_abstract_conv import (
BaseTestConv2d, BaseTestConv2d,
BaseTestConv3d, BaseTestConv3d,
...@@ -22,7 +24,7 @@ from ..blas import ( ...@@ -22,7 +24,7 @@ from ..blas import (
) )
from .config import mode_with_gpu, test_ctx_name from .config import mode_with_gpu, test_ctx_name
from pygpu import gpuarray
gpu_ftensor4 = GpuArrayType(dtype="float32", broadcastable=(False,) * 4) gpu_ftensor4 = GpuArrayType(dtype="float32", broadcastable=(False,) * 4)
......
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
from theano.compat import izip
import pytest import pytest
from six import iteritems pygpu = pytest.importorskip("pygpu")
gpuarray = pygpu.gpuarray
import numpy as np import numpy as np
import theano import theano
import theano.tensor as T import theano.tensor as T
from six import iteritems
from theano.compat import izip
from theano.tensor import TensorType from theano.tensor import TensorType
from theano.tensor.basic import alloc from theano.tensor.basic import alloc
...@@ -20,7 +22,6 @@ from theano.tensor.tests.test_basic import ( ...@@ -20,7 +22,6 @@ from theano.tensor.tests.test_basic import (
TestJoinAndSplit, TestJoinAndSplit,
) )
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from ..type import GpuArrayType, get_context, gpuarray_shared_constructor from ..type import GpuArrayType, get_context, gpuarray_shared_constructor
from ..basic_ops import ( from ..basic_ops import (
host_from_gpu, host_from_gpu,
...@@ -40,11 +41,8 @@ from ..basic_ops import ( ...@@ -40,11 +41,8 @@ from ..basic_ops import (
) )
from ..elemwise import GpuDimShuffle, GpuElemwise from ..elemwise import GpuDimShuffle, GpuElemwise
from ..subtensor import GpuSubtensor from ..subtensor import GpuSubtensor
from .config import mode_with_gpu, mode_without_gpu, test_ctx_name from .config import mode_with_gpu, mode_without_gpu, test_ctx_name
from pygpu import gpuarray
utt.seed_rng() utt.seed_rng()
rng = np.random.RandomState(seed=utt.fetch_seed()) rng = np.random.RandomState(seed=utt.fetch_seed())
......
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
import pytest
import numpy as np import numpy as np
import theano
from six.moves import xrange from six.moves import xrange
import theano
from theano import tensor, config, Apply, Op from theano import tensor, config, Apply, Op
from theano.scalar import int32 as int_t from theano.scalar import int32 as int_t
from theano.gof import ParamsType from theano.gof import ParamsType
...@@ -33,10 +35,10 @@ class GpuEye(CGpuKernelBase, Op): ...@@ -33,10 +35,10 @@ class GpuEye(CGpuKernelBase, Op):
) )
def get_params(self, node): def get_params(self, node):
from pygpu.gpuarray import dtype_to_typecode pygpu_gpuarray = pytest.importorskip("pygpu.gpuarray")
return self.params_type.get_params( return self.params_type.get_params(
typecode=dtype_to_typecode(self.dtype), typecode=pygpu_gpuarray.dtype_to_typecode(self.dtype),
context=get_context(self.context_name), context=get_context(self.context_name),
) )
......
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
import logging import logging
from collections import OrderedDict
import numpy as np
import pytest import pytest
from itertools import product, chain import numpy as np
pygpu = pytest.importorskip("pygpu")
import theano import theano
from six import StringIO
import theano.tensor as T import theano.tensor as T
import theano.tests.unittest_tools as utt import theano.tests.unittest_tools as utt
from six import StringIO
from itertools import product, chain
from collections import OrderedDict
from theano.tensor.signal.pool import pool_2d, pool_3d from theano.tensor.signal.pool import pool_2d, pool_3d
from theano.tensor.signal.pool import Pool, MaxPoolGrad, AveragePoolGrad from theano.tensor.signal.pool import Pool, MaxPoolGrad, AveragePoolGrad
from theano.tensor.nnet.abstract_conv import ( from theano.tensor.nnet.abstract_conv import (
...@@ -17,6 +18,9 @@ from theano.tensor.nnet.abstract_conv import ( ...@@ -17,6 +18,9 @@ from theano.tensor.nnet.abstract_conv import (
get_conv_gradinputs_shape, get_conv_gradinputs_shape,
) )
from theano.tensor.nnet import bn from theano.tensor.nnet import bn
from theano.configdefaults import SUPPORTED_DNN_CONV_ALGO_FWD
from theano.tensor.nnet.tests.test_abstract_conv import Grouped_conv_noOptim
from theano.tensor.nnet.tests.test_abstract_conv import Grouped_conv3d_noOptim
from .. import dnn from .. import dnn
from ..basic_ops import GpuAllocEmpty from ..basic_ops import GpuAllocEmpty
...@@ -26,15 +30,6 @@ from .config import mode_with_gpu, mode_without_gpu, test_ctx_name, ref_cast ...@@ -26,15 +30,6 @@ from .config import mode_with_gpu, mode_without_gpu, test_ctx_name, ref_cast
from . import test_nnet from . import test_nnet
from .rnn_support import Model, GRU, LSTM, WrapperLayer from .rnn_support import Model, GRU, LSTM, WrapperLayer
from theano.configdefaults import SUPPORTED_DNN_CONV_ALGO_FWD
from theano.tensor.nnet.tests.test_abstract_conv import Grouped_conv_noOptim
from theano.tensor.nnet.tests.test_abstract_conv import Grouped_conv3d_noOptim
try:
import pygpu
except ImportError:
pass
mode_with_gpu = mode_with_gpu.including() mode_with_gpu = mode_with_gpu.including()
# Globally disabled for mode_without_gpu # Globally disabled for mode_without_gpu
mode_with_gpu.check_py_code = False mode_with_gpu.check_py_code = False
......
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
from copy import copy
import pytest import pytest
import numpy as np import numpy as np
import theano import theano
pygpu = pytest.importorskip("pygpu")
gpuarray = pygpu.ndgpuarray
from copy import copy
from theano import scalar, gof, tensor from theano import scalar, gof, tensor
from theano.compile import DebugMode, Mode from theano.compile import DebugMode, Mode
from theano.tests.unittest_tools import assert_allclose from theano.tests.unittest_tools import assert_allclose
...@@ -25,17 +27,6 @@ from ..dnn import GpuDnnReduction ...@@ -25,17 +27,6 @@ from ..dnn import GpuDnnReduction
from ..type import GpuArrayType, get_context, gpuarray_shared_constructor from ..type import GpuArrayType, get_context, gpuarray_shared_constructor
from pygpu import ndgpuarray as gpuarray
imported_scipy_special = False
try:
import scipy.special
imported_scipy_special = True
except ImportError:
pass
# This is actually a test for GpuElemwise # This is actually a test for GpuElemwise
class TestGpuBroadcast(test_elemwise.TestBroadcast): class TestGpuBroadcast(test_elemwise.TestBroadcast):
cop = GpuElemwise cop = GpuElemwise
...@@ -96,8 +87,8 @@ class TestMathErrorFunctions: ...@@ -96,8 +87,8 @@ class TestMathErrorFunctions:
@classmethod @classmethod
def setup_class(cls): def setup_class(cls):
if not imported_scipy_special: scipy_special = pytest.importorskip("scipy.special")
pytest.skip("scipy.special needed")
# NB: erfinv is defined in ]-1;1[, and erfcinv is defined in ]0;2[, # NB: erfinv is defined in ]-1;1[, and erfcinv is defined in ]0;2[,
# so we just take some values in an interval that covers both domains # so we just take some values in an interval that covers both domains
# (this will also allow to test some values outside the domains). # (this will also allow to test some values outside the domains).
...@@ -107,8 +98,8 @@ class TestMathErrorFunctions: ...@@ -107,8 +98,8 @@ class TestMathErrorFunctions:
for dtype in cls.dtypes: for dtype in cls.dtypes:
numpy_array = np.asarray(default_array, dtype=dtype) numpy_array = np.asarray(default_array, dtype=dtype)
cls.default_arrays[dtype] = numpy_array cls.default_arrays[dtype] = numpy_array
cls.expected_erfinv_outputs[dtype] = scipy.special.erfinv(numpy_array) cls.expected_erfinv_outputs[dtype] = scipy_special.erfinv(numpy_array)
cls.expected_erfcinv_outputs[dtype] = scipy.special.erfcinv(numpy_array) cls.expected_erfcinv_outputs[dtype] = scipy_special.erfcinv(numpy_array)
# Since there are infinite values, we need to disable that check # Since there are infinite values, we need to disable that check
# in DebugMode if needed # in DebugMode if needed
......
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
from .config import test_ctx_name, mode_with_gpu import pytest
import numpy as np
pygpu = pytest.importorskip("pygpu")
from theano.misc.tests.test_may_share_memory import may_share_memory_core
from theano.misc.pkl_utils import dump, load
from theano.tensor.tests import test_opt
from .config import test_ctx_name, mode_with_gpu
from ..basic_ops import HostFromGpu, GpuFromHost from ..basic_ops import HostFromGpu, GpuFromHost
from ..type import ( from ..type import (
get_context, get_context,
...@@ -9,14 +16,6 @@ from ..type import ( ...@@ -9,14 +16,6 @@ from ..type import (
gpuarray_shared_constructor, gpuarray_shared_constructor,
) )
import pygpu
import numpy as np
from theano.misc.tests.test_may_share_memory import may_share_memory_core
from theano.misc.pkl_utils import dump, load
from theano.tensor.tests import test_opt
class TestFusion(test_opt.TestFusion): class TestFusion(test_opt.TestFusion):
mode = mode_with_gpu.excluding("local_dnn_reduction") mode = mode_with_gpu.excluding("local_dnn_reduction")
......
...@@ -19,19 +19,15 @@ from theano.misc.pkl_utils import CompatUnpickler ...@@ -19,19 +19,15 @@ from theano.misc.pkl_utils import CompatUnpickler
from ..type import ContextNotDefined from ..type import ContextNotDefined
try: try:
from . import config as _ # noqa import pygpu # noqa: F401
have_pygpu = True have_pygpu = True
except ImportError: except ImportError:
have_pygpu = False have_pygpu = False
@pytest.mark.skipif(have_pygpu, reason="pygpu active")
def test_unpickle_gpuarray_as_numpy_ndarray_flag1(): def test_unpickle_gpuarray_as_numpy_ndarray_flag1():
# Only test when pygpu isn't
# available. test_unpickle_gpuarray_as_numpy_ndarray_flag0 in test_type.py
# test it when pygpu is there.
if have_pygpu:
pytest.skip("pygpu active")
oldflag = config.experimental.unpickle_gpu_on_cpu oldflag = config.experimental.unpickle_gpu_on_cpu
config.experimental.unpickle_gpu_on_cpu = False config.experimental.unpickle_gpu_on_cpu = False
......
...@@ -3,7 +3,8 @@ import os ...@@ -3,7 +3,8 @@ import os
import pytest import pytest
import numpy as np import numpy as np
import theano import theano
import pygpu
pygpu = pytest.importorskip("pygpu")
from theano.compat import PY3 from theano.compat import PY3
from theano import config from theano import config
......
...@@ -3,7 +3,7 @@ import numpy as np ...@@ -3,7 +3,7 @@ import numpy as np
try: try:
import scipy.sparse as sp import scipy.sparse as sp
import scipy.sparse import scipy.sparse # noqa: F401
except ImportError: except ImportError:
pass # The variable enable_sparse will be used to disable the test file. pass # The variable enable_sparse will be used to disable the test file.
import pytest import pytest
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论