python类fixture()的实例源码

test_rust_pypi_example.py 文件源码 项目:rust_pypi_example 作者: mckaymatt 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_content(response):
    """Sample pytest test function with the pytest fixture as an argument.
    """
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string
test_forms.py 文件源码 项目:fakester 作者: pawelad 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def redirect_form(self):
        """Helper fixture for initializing `RedirectModelForm`"""
        return RedirectModelForm()
test_create_pipeline.py 文件源码 项目:foremast 作者: gogoair 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def spinnaker_pipeline(mock_os, mock_get_details, mock_get_prop):
    """Sets up pipeline fixture object"""
    mock_get_prop.return_value = TEST_SETTINGS
    pipelineObj = SpinnakerPipeline(
        app='appgroup',
        trigger_job='a_group_app', )
    pipelineObj.generated = 'test'
    pipelineObj.app_name = 'appgroup'
    pipelineObj.group_name = 'group'
    return pipelineObj
test_giphy.py 文件源码 项目:TeleGiphy 作者: JessicaNgo 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_gif_api_call_functions(self, json_filename):
        if 'translate' in json_filename:
            resp = gif_translate(string='doge', api_key='dc6zaTOxFJmzC')
            expected = load_json("translate_{}.json".format(self.status))
        elif 'random' in json_filename:
            resp = gif_random(tag='doge', api_key='dc6zaTOxFJmzC')
            expected = load_json("random_{}.json".format(self.status))
        else:
            raise ValueError
        expected = self.json
        # status code
        assert resp.status_code == 200
        # json is the same between fixture and request
        for item in expected:
            assert item in resp.json()
test_giphy.py 文件源码 项目:TeleGiphy 作者: JessicaNgo 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_gif_api_call_functions_return(self, json_filename):
        if 'translate' in json_filename:
            resp = gif_translate(api_key='abc', string='doge')
            expected = load_json("translate_{}.json".format(self.status))
        elif 'random' in json_filename:
            resp = gif_random(api_key='abc', tag='doge')
            expected = load_json("random_{}.json".format(self.status))
        else:
            raise ValueError
        expected = self.json
        # status code
        assert resp.status_code == 403
        # json is the same between fixture and request
        for item in expected:
            assert item in resp.json()
test_model.py 文件源码 项目:xarray-simlab 作者: benbovy 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def model(model):
    """Override fixture defined in conftest.py, return a model
    with values set for some of its variables.
    """
    model.grid.x_size.value = 10
    model.quantity.quantity.state = np.zeros(10)
    model.some_process.some_param.value = 1

    return model
test_arguments.py 文件源码 项目:sphinxcontrib-versioning 作者: Robpol86 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def setup(monkeypatch, local_empty):
    """Set __main__.NO_EXECUTE to True before every test in this module and sets CWD to an empty git repo.

    :param monkeypatch: pytest fixture.
    :param local_empty: conftest fixture.
    """
    monkeypatch.setattr('sphinxcontrib.versioning.__main__.NO_EXECUTE', True)
    monkeypatch.chdir(local_empty)
test_arguments.py 文件源码 项目:sphinxcontrib-versioning 作者: Robpol86 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_overflow(local_empty, push, source_cli, source_conf):
    """Test -- overflow to sphinx-build.

    :param local_empty: conftest fixture.
    :param bool push: Run push sub command instead of build.
    :param bool source_cli: Set value from command line arguments.
    :param bool source_conf: Set value from conf.py file.
    """
    if push:
        args = ['push', 'docs', 'gh-pages', '.']
    else:
        args = ['build', 'docs', join('docs', '_build', 'html')]

    # Setup source(s).
    if source_cli:
        args += ['--', '-D', 'setting=value']
    if source_conf:
        local_empty.ensure('docs', 'contents.rst')
        local_empty.ensure('docs', 'conf.py').write('scv_overflow = ("-D", "key=value")')

    # Run.
    result = CliRunner().invoke(cli, args)
    config = result.exception.args[0]

    # Verify.
    if source_cli:
        assert config.overflow == ('-D', 'setting=value')
    elif source_conf:
        assert config.overflow == ('-D', 'key=value')
    else:
        assert config.overflow == tuple()
conftest.py 文件源码 项目:sphinxcontrib-versioning 作者: Robpol86 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def config(monkeypatch):
    """Mock config from Click context.

    :param monkeypatch: pytest fixture.

    :return: Config instance.
    :rtype: sphinxcontrib.versioning.lib.Config
    """
    instance = Config()
    ctx = type('', (), {'find_object': staticmethod(lambda _: instance)})
    monkeypatch.setattr('click.get_current_context', lambda: ctx)
    return instance
conftest.py 文件源码 项目:sphinxcontrib-versioning 作者: Robpol86 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def fx_local_empty(tmpdir):
    """Local git repository with no commits.

    :param tmpdir: pytest fixture.

    :return: Path to repo root.
    :rtype: py.path.local
    """
    repo = tmpdir.ensure_dir('local')
    run(repo, ['git', 'init'])
    return repo
conftest.py 文件源码 项目:sphinxcontrib-versioning 作者: Robpol86 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def fx_local_commit(local_empty):
    """Local git repository with one commit.

    :param local_empty: local fixture.

    :return: Path to repo root.
    :rtype: py.path.local
    """
    local_empty.join('README').write('Dummy readme file.')
    run(local_empty, ['git', 'add', 'README'])
    run(local_empty, ['git', 'commit', '-m', 'Initial commit.'], environ=author_committer_dates(0))
    return local_empty
test_widget_abstract.py 文件源码 项目:engel 作者: Dalloriam 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def TestPageTitleStructure():

    @pytest.fixture(scope="class")
    def title():
        return PageTitle(id='id', text='test')

    def test_widget_abstract_pagetitle_html_tag(self, title):
        assert title.html_tag == 'title', 'PageTitle should set PageTitle.html_tag = "title"'

    def test_widget_abstract_pagetitle_sets_content(self, title):
        assert title.content == 'test', 'PageTitle.build() should set PagetTitle.content.'
test_widget_abstract.py 文件源码 项目:engel 作者: Dalloriam 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def TestScriptStructure():
    @pytest.fixture(scope="class")
    def script():
        return Script(js_path="//js")

    def test_widget_abstract_script_html_tag(self, script):
        assert script.html_tag == 'script', 'Script should set Script.html_tag = "script".'

    def test_widget_abstract_script_has_source(self, script):
        assert hasattr('source', script) and isinstance(script.__class__.source, property)

    def test_widget_abstract_script_sets_source(self, script):
        assert script.source == '//js', "Script.build() should set Script.source."
test_tuning.py 文件源码 项目:search-MjoLniR 作者: wikimedia 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def df_train(spark_context, hive_context):
    # TODO: Use some fixture dataset representing real-ish data? But
    # it needs to be pretty small
    return spark_context.parallelize(
        _make_q('abc') + _make_q('def') + _make_q('ghi') + _make_q('jkl')
        + _make_q('mno') + _make_q('pqr') + _make_q('stu')
    ).toDF(['wikiid', 'norm_query_id', 'query', 'label', 'features'])
test_hyperopt.py 文件源码 项目:search-MjoLniR 作者: wikimedia 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def df_train(spark_context, hive_context):
    # TODO: Use some fixture dataset representing real-ish data? But
    # it needs to be pretty small
    return spark_context.parallelize(
        _make_q('abc') + _make_q('def') + _make_q('ghi') + _make_q('jkl')
        + _make_q('mno') + _make_q('pqr') + _make_q('stu')
    ).toDF(['wikiid', 'norm_query_id', 'query', 'label', 'features'])
conftest.py 文件源码 项目:SWEETer-Cat 作者: DanielAndreasen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def SCdata():
    """SWEET-Cat database fixture."""
    return readSC()
conftest.py 文件源码 项目:SWEETer-Cat 作者: DanielAndreasen 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def planetStardata():
    """SWEET-Cat + ExoplanetEU + database fixture."""
    return planetAndStar()
conftest.py 文件源码 项目:salt-toaster 作者: openSUSE 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def master(setup):
    config, initconfig = setup
    master = config['masters'][0]['fixture']
    def _cmd(master, cmd):
        SSH = "salt-ssh -l quiet -i --out json --key-deploy --passwd {0} {1} {{0}}".format(
            PASSWORD, TARGET_ID)
        return json.loads(master['container'].run(SSH.format(cmd))).get(TARGET_ID)
    master.salt_ssh = partial(_cmd, master)
    return master


问题


面经


文章

微信
公众号

扫码关注公众号