当前位置: 首页>>代码示例>>Python>>正文


Python capture.CaptureFixture方法代码示例

本文整理汇总了Python中_pytest.capture.CaptureFixture方法的典型用法代码示例。如果您正苦于以下问题:Python capture.CaptureFixture方法的具体用法?Python capture.CaptureFixture怎么用?Python capture.CaptureFixture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_pytest.capture的用法示例。


在下文中一共展示了capture.CaptureFixture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_sanitized_model_directory_when_not_passing_model

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_get_sanitized_model_directory_when_not_passing_model(
    capsys: CaptureFixture, tmp_path: Path, monkeypatch: MonkeyPatch
):
    from rasa.test import _get_sanitized_model_directory

    monkeypatch_get_latest_model(tmp_path, monkeypatch)

    # Create a fake model on disk so that `is_file` returns `True`
    latest_model = Path(rasa.model.get_latest_model())
    latest_model.touch()

    # Input: default model file
    # => Should return containing directory
    new_modeldir = _get_sanitized_model_directory(str(latest_model))
    captured = capsys.readouterr()
    assert not captured.out
    assert new_modeldir == str(latest_model.parent) 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:19,代码来源:test_test.py

示例2: test_get_sanitized_model_directory_when_passing_model_file_explicitly

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_get_sanitized_model_directory_when_passing_model_file_explicitly(
    capsys: CaptureFixture, tmp_path: Path, monkeypatch: MonkeyPatch
):
    from rasa.test import _get_sanitized_model_directory

    monkeypatch_get_latest_model(tmp_path, monkeypatch)

    other_model = tmp_path / "my_test_model1.tar.gz"
    assert str(other_model) != rasa.model.get_latest_model()
    other_model.touch()

    # Input: some file
    # => Should return containing directory and print a warning
    new_modeldir = _get_sanitized_model_directory(str(other_model))
    captured = capsys.readouterr()
    assert captured.out
    assert new_modeldir == str(other_model.parent) 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:19,代码来源:test_test.py

示例3: test_train_nlu_wrong_format_error_message

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_train_nlu_wrong_format_error_message(
    capsys: CaptureFixture,
    tmp_path: Text,
    monkeypatch: MonkeyPatch,
    default_stack_config: Text,
    incorrect_nlu_data: Text,
):
    monkeypatch.setattr(tempfile, "tempdir", tmp_path)

    train_nlu(
        default_stack_config,
        incorrect_nlu_data,
        output="test_train_nlu_temp_files_models",
    )

    captured = capsys.readouterr()
    assert "Please verify the data format" in captured.out 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:19,代码来源:test_train.py

示例4: test_main_custom_template_dir

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_main_custom_template_dir(capsys: CaptureFixture) -> None:
    """Test main function with custom template directory."""

    input_filename = OPEN_API_DATA_PATH / 'api.yaml'
    custom_template_dir = DATA_PATH / 'templates'
    extra_template_data = OPEN_API_DATA_PATH / 'extra_data.json'

    with freeze_time(TIMESTAMP):
        main(
            [
                '--input',
                str(input_filename),
                '--custom-template-dir',
                str(custom_template_dir),
                '--extra-template-data',
                str(extra_template_data),
            ]
        )

    captured = capsys.readouterr()
    assert (
        captured.out
        == (EXPECTED_MAIN_PATH / 'main_custom_template_dir' / 'output.py').read_text()
    )
    assert not captured.err 
开发者ID:koxudaxi,项目名称:datamodel-code-generator,代码行数:27,代码来源:test_main.py

示例5: test_no_capture

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_no_capture(
        self,
        capfd: CaptureFixture,
        dcos_node: Node,
    ) -> None:
        """
        When given ``Output.NO_CAPTURE``, no output is captured.
        """
        stdout_message = uuid.uuid4().hex
        stderr_message = uuid.uuid4().hex
        args = ['echo', stdout_message, '&&', '>&2', 'echo', stderr_message]
        result = dcos_node.run(args=args, shell=True, output=Output.NO_CAPTURE)
        assert result.stdout is None
        assert result.stderr is None

        captured = capfd.readouterr()
        assert captured.out.strip() == stdout_message
        assert captured.err.strip() == stderr_message 
开发者ID:dcos,项目名称:dcos-e2e,代码行数:20,代码来源:test_node.py

示例6: test_builtin_settings

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_builtin_settings(capsys: CaptureFixture):
    main(['settings'])
    captured = capsys.readouterr()
    assert captured.out == f'{scanpy.settings}\n' 
开发者ID:theislab,项目名称:scanpy,代码行数:6,代码来源:test_binary.py

示例7: test_help_displayed

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_help_displayed(args: List[str], capsys: CaptureFixture):
    try:  # -h raises it, no args doesn’t. Maybe not ideal but meh.
        main(args)
    except SystemExit as se:
        assert se.code == 0
    captured = capsys.readouterr()
    assert captured.out.startswith('usage: ') 
开发者ID:theislab,项目名称:scanpy,代码行数:9,代码来源:test_binary.py

示例8: test_help_output

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_help_output(set_path: type(None), capsys: CaptureFixture):
    with pytest.raises(SystemExit, match='^0$'):
        main(['-h'])
    captured = capsys.readouterr()
    assert re.search(
        r'^positional arguments:\n\s+\{settings,[\w,-]*testbin[\w,-]*\}$',
        captured.out,
        re.MULTILINE,
    ) 
开发者ID:theislab,项目名称:scanpy,代码行数:11,代码来源:test_binary.py

示例9: test_error_wrong_command

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_error_wrong_command(capsys: CaptureFixture):
    with pytest.raises(SystemExit, match='^2$'):
        main(['idonotexist--'])
    captured = capsys.readouterr()
    assert 'No command “idonotexist--”. Choose from' in captured.err 
开发者ID:theislab,项目名称:scanpy,代码行数:7,代码来源:test_binary.py

示例10: stop_std_logging

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def stop_std_logging(request: FixtureRequest, capfd: CaptureFixture) -> None:
    patcher = mock.patch("bandersnatch.log.setup_logging")
    patcher.start()

    def tearDown() -> None:
        patcher.stop()

    request.addfinalizer(tearDown) 
开发者ID:pypa,项目名称:bandersnatch,代码行数:10,代码来源:conftest.py

示例11: test_package_fetch_metadata_gives_up_after_3_stale_responses

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_package_fetch_metadata_gives_up_after_3_stale_responses(
    caplog: CaptureFixture, mirror: Mirror
) -> None:
    mirror.master.get_package_metadata = asynctest.CoroutineMock(  # type: ignore
        side_effect=StalePage
    )

    pkg_name = "foo"
    package = Package(pkg_name, 11, mirror)

    with pytest.raises(StaleMetadata):
        await package.fetch_metadata()
    assert mirror.master.get_package_metadata.await_count == 3  # type: ignore
    assert "not updating. Giving up" in caplog.text 
开发者ID:pypa,项目名称:bandersnatch,代码行数:16,代码来源:test_package.py

示例12: test_main_help

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_main_help(capfd: CaptureFixture) -> None:
    sys.argv = ["bandersnatch", "--help"]
    with pytest.raises(SystemExit):
        main(asyncio.new_event_loop())
    out, err = capfd.readouterr()
    assert out.startswith("usage: bandersnatch")
    assert "" == err 
开发者ID:pypa,项目名称:bandersnatch,代码行数:9,代码来源:test_main.py

示例13: test_get_sanitized_model_directory_when_passing_other_input

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_get_sanitized_model_directory_when_passing_other_input(
    capsys: CaptureFixture, tmp_path: Path, monkeypatch: MonkeyPatch
):
    from rasa.test import _get_sanitized_model_directory

    monkeypatch_get_latest_model(tmp_path, monkeypatch)

    # Input: anything that is not an existing file
    # => Should return input
    modeldir = "random_dir"
    assert not Path(modeldir).is_file()
    new_modeldir = _get_sanitized_model_directory(modeldir)
    captured = capsys.readouterr()
    assert not captured.out
    assert new_modeldir == modeldir 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:17,代码来源:test_test.py

示例14: test_train_nlu_no_nlu_file_error_message

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_train_nlu_no_nlu_file_error_message(
    capsys: CaptureFixture,
    tmp_path: Text,
    monkeypatch: MonkeyPatch,
    default_stack_config: Text,
):
    monkeypatch.setattr(tempfile, "tempdir", tmp_path)

    train_nlu(
        default_stack_config, "", output="test_train_nlu_temp_files_models",
    )

    captured = capsys.readouterr()
    assert "No NLU data given" in captured.out 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:16,代码来源:test_train.py

示例15: test_main_no_file

# 需要导入模块: from _pytest import capture [as 别名]
# 或者: from _pytest.capture import CaptureFixture [as 别名]
def test_main_no_file(capsys: CaptureFixture) -> None:
    """Test main function on non-modular file with no output name."""

    input_filename = OPEN_API_DATA_PATH / 'api.yaml'

    with freeze_time(TIMESTAMP):
        main(['--input', str(input_filename)])

    captured = capsys.readouterr()
    assert (
        captured.out
        == (EXPECTED_MAIN_KR_PATH / 'main_no_file' / 'output.py').read_text()
    )

    assert not captured.err 
开发者ID:koxudaxi,项目名称:datamodel-code-generator,代码行数:17,代码来源:test_main_kr.py


注:本文中的_pytest.capture.CaptureFixture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。