當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。