python类importorskip()的实例源码

test_functional.py 文件源码 项目:pyrepl 作者: dajose 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def pytest_funcarg__child(request):
    try:
        pexpect = pytest.importorskip('pexpect')
    except SyntaxError:
        pytest.skip('pexpect wont work on py3k')
    child = pexpect.spawn(sys.executable, ['-S'], timeout=10)
    if sys.version_info >= (3, ):
        child.logfile = sys.stdout.buffer
    else:
        child.logfile = sys.stdout
    child.sendline('from pyrepl.python_reader import main')
    child.sendline('main()')
    return child
test_core.py 文件源码 项目:knit 作者: dask 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_existing_path(k):
    # TODO: is this a good test if we noisily log the upload of files?
    hdfs3 = pytest.importorskip('hdfs3')
    hdfs = hdfs3.HDFileSystem()
    k.hdfs = hdfs
    cmd = 'ls -l'
    hdfs.put(__file__, '/tmp/mytestfile')
    k.start(cmd, files=['hdfs://tmp/mytestfile'])
    wait_for_status(k, 'FINISHED')
    time.sleep(2)
    out = k.logs()
    assert ' mytestfile ' in str(out)
test_integration.py 文件源码 项目:pymapd 作者: mapd 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_select_ipc_parametrized(self, con, stocks, query, parameters):
        pd = pytest.importorskip("pandas")
        import numpy as np
        import pandas.util.testing as tm

        result = con.select_ipc(query, parameters=parameters)
        expected = pd.DataFrame({
            "qty": np.array([100, 100], dtype=np.int32),
            "price": np.array([35.13999938964844, 12.140000343322754],
                              dtype=np.float32)
        })[['qty', 'price']]
        tm.assert_frame_equal(result, expected)
test_integration.py 文件源码 项目:pymapd 作者: mapd 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_select_ipc_first_n(self, con, stocks):
        pytest.importorskip("pandas")
        result = con.select_ipc("select * from stocks", first_n=1)
        assert len(result) == 1
test_integration.py 文件源码 项目:pymapd 作者: mapd 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_select_ipc_pandas(self, con):
        pytest.importorskip("pyarrow")
        with mock.patch.dict('sys.modules', {'pandas': None}):
            with pytest.raises(ImportError) as m:
                con.select_ipc("select * from foo;")

        assert m.match("pandas is required for `select_ipc`")
test_integration.py 文件源码 项目:pymapd 作者: mapd 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_load_empty_table_pandas(self, con, empty_table):
        # TODO: just require arrow and pandas for tests
        pd = pytest.importorskip("pandas")

        data = [(1, 1.1, 'a'),
                (2, 2.2, '2'),
                (3, 3.3, '3')]
        df = pd.DataFrame(data, columns=list('abc'))
        con.load_table(empty_table, df, method='columnar')
        result = sorted(con.execute("select * from {}".format(empty_table)))
        self.check_empty_insert(result, data)
test_integration.py 文件源码 项目:pymapd 作者: mapd 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def test_load_infer(self, con, empty_table):
        pd = pytest.importorskip("pandas")
        skip_if_no_arrow_loader(con)
        import numpy as np

        data = pd.DataFrame(
            {'a': np.array([0, 1], dtype=np.int32),
             'b': np.array([1.1, 2.2], dtype=np.float32),
             'c': ['a', 'b']}
        )
        con.load_table(empty_table, data)
test_integration.py 文件源码 项目:pymapd 作者: mapd 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_create_table(self, con, not_a_table):
        pd = pytest.importorskip("pandas")
        df = pd.DataFrame({"A": [1, 2], "B": [1., 2.]})
        con.create_table(not_a_table, df)
test_pdb.py 文件源码 项目:pdb 作者: antocuni 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def test_track_with_no_args():
    pytest.importorskip('rpython.translator.tool.reftracker')

    def fn():
        set_trace()
        return 42

    check(fn, """
[NUM] > .*fn()
-> return 42
# track
... SyntaxError:
# c
""")
common.py 文件源码 项目:parsec-cloud 作者: Scille 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def init_or_skiptest_parsec_postgresql():
    if pytest.config.getoption('--no-postgresql'):
        pytest.skip('`--no-postgresql` option provided')
    module = pytest.importorskip('parsec.backend.postgresql')
    url = postgresql_url()
    await module._init_db(url, force=True)
    return module, url
conftest.py 文件源码 项目:camisole 作者: prologin 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def http_request(request):
    if request.param == 'json':
        return request.getfuncargvalue('json_request')
    if request.param == 'msgpack':
        pytest.importorskip('msgpack')
        return request.getfuncargvalue('msgpack_request')
conftest.py 文件源码 项目:execnet 作者: pytest-dev 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def execmodel(request):
    if request.param != "thread":
        pytest.importorskip(request.param)
    if sys.platform == "win32":
        pytest.xfail("eventlet/gevent do not work onwin32")
    return get_execmodel(request.param)
test_basics.py 文件源码 项目:execnet 作者: pytest-dev 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_mmap(self, tmpdir, val):
        mmap = pytest.importorskip("mmap").mmap
        p = tmpdir.join("data")
        with p.open("wb") as f:
            f.write(execnet.dumps(val))
        f = p.open("r+b")
        m = mmap(f.fileno(), 0)
        val2 = execnet.load(m)
        assert val == val2
test_analysis.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_porter2():
    from whoosh.lang.porter2 import stem

    plurals = ['caresses', 'flies', 'dies', 'mules', 'denied',
               'died', 'agreed', 'owned', 'humbled', 'sized',
               'meeting', 'stating', 'siezing', 'itemization',
               'sensational', 'traditional', 'reference', 'colonizer',
               'plotted']
    singles = [stem(w) for w in plurals]

    assert singles == ['caress', 'fli', 'die', 'mule', 'deni', 'die',
                       'agre', 'own', 'humbl', 'size', 'meet', 'state',
                       'siez', 'item', 'sensat', 'tradit', 'refer',
                       'colon', 'plot']
    assert stem("bill's") == "bill"
    assert stem("y's") == "y"


#def test_pystemmer():
#    Stemmer = pytest.importorskip("Stemmer")
#
#    ana = (analysis.RegexTokenizer()
#           | analysis.LowercaseFilter()
#           | analysis.PyStemmerFilter())
#    schema = fields.Schema(text=fields.TEXT(analyzer=ana))
#    st = RamStorage()
#
#    ix = st.create_index(schema)
#    with ix.writer() as w:
#        w.add_document(text=u("rains falling strangely"))
#
#    ix = st.open_index()
#    with ix.writer() as w:
#        w.add_document(text=u("pains stalling strongly"))
#
#    ix = st.open_index()
#    with ix.reader() as r:
#        assert (list(r.field_terms("text"))
#                == ["fall", "pain", "rain", "stall", "strang", "strong"])
test_stats.py 文件源码 项目:crick 作者: jcrist 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_skew(x, bias):
    stats = pytest.importorskip('scipy.stats')
    s = SummaryStats()
    s.update(x)
    res = s.skew(bias=bias)
    sol = stats.skew(x[~np.isnan(x)], bias=bias) if len(x) else np.nan
    np.testing.assert_allclose(res, sol, rtol=RTOL, atol=ATOL)
test_stats.py 文件源码 项目:crick 作者: jcrist 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_kurt(x, bias, fisher):
    stats = pytest.importorskip('scipy.stats')
    s = SummaryStats()
    s.update(x)

    res = s.kurt(bias=bias, fisher=fisher)
    if len(x):
        sol = stats.kurtosis(x[~np.isnan(x)], bias=bias, fisher=fisher)
    else:
        sol = np.nan
    np.testing.assert_allclose(res, sol, rtol=RTOL, atol=ATOL)
test_pytest.py 文件源码 项目:ml-utils 作者: LinxiFan 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_import():
    mylib = pytest.importorskip("weird-lib")
    print(mylib)
test_model_selection.py 文件源码 项目:dask-searchcv 作者: dask 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_scheduler_param(scheduler, n_jobs, get):
    if scheduler == 'multiprocessing':
        mp = pytest.importorskip('dask.multiprocessing')
        get = mp.get

    assert _normalize_scheduler(scheduler, n_jobs) is get

    X, y = make_classification(n_samples=100, n_features=10, random_state=0)
    gs = dcv.GridSearchCV(MockClassifier(), {'foo_param': [0, 1, 2]}, cv=3,
                          scheduler=scheduler, n_jobs=n_jobs)
    gs.fit(X, y)
test_math.py 文件源码 项目:nengo_spa 作者: nengo 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def test_prob_cleanup(rng):
    pytest.importorskip('scipy')

    assert 1.0 > prob_cleanup(0.7, 64, 10000) > 0.9999
    assert 0.9999 > prob_cleanup(0.6, 64, 10000) > 0.999
    assert 0.99 > prob_cleanup(0.5, 64, 1000) > 0.9

    assert 0.999 > prob_cleanup(0.4, 128, 1000) > 0.997
    assert 0.99 > prob_cleanup(0.4, 128, 10000) > 0.97
    assert 0.9 > prob_cleanup(0.4, 128, 100000) > 0.8
test_examples.py 文件源码 项目:nengo_spa 作者: nengo 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def assert_noexceptions(nb_file, tmpdir):
    plt = pytest.importorskip('matplotlib.pyplot')
    pytest.importorskip("IPython", minversion="1.0")
    pytest.importorskip("jinja2")
    from nengo.utils.ipython import export_py
    nb = load_example(nb_file)
    pyfile = "%s.py" % tmpdir.join(os.path.basename(nb_file))
    export_py(nb, pyfile)
    execfile(pyfile, {})
    plt.close('all')


问题


面经


文章

微信
公众号

扫码关注公众号