Example #1
0
def test_assert_equal_plugin(
    container,
    anyio_backend_name: str,
    returns: ReturnsAsserts,
):
    """Ensure that containers can be equal."""
    returns.assert_equal(container, container, backend=anyio_backend_name)
Example #2
0
def test_error_handled(returns: ReturnsAsserts, container, kwargs):
    """Demo on how to use ``pytest`` helpers to work with error handling."""
    error_handled = _under_test(container, **kwargs)

    assert returns.is_error_handled(error_handled)
    assert returns.is_error_handled(error_handled.map(identity))
    assert returns.is_error_handled(error_handled.alt(identity))
Example #3
0
async def test_error_not_handled_async(returns: ReturnsAsserts, container):
    """Demo on how to use ``pytest`` helpers to work with error handling."""
    error_handled = _under_test(container)

    assert not returns.is_error_handled(container)
    assert not returns.is_error_handled(error_handled)
    assert not returns.is_error_handled(error_handled.map(identity))
    assert not returns.is_error_handled(error_handled.alt(identity))
Example #4
0
def test_assert_equal_not_plugin(
    container,
    anyio_backend_name: str,
    returns: ReturnsAsserts,
):
    """Ensure that containers can be not equal."""
    with pytest.raises(AssertionError):
        returns.assert_equal(
            container,
            container.from_value(2),
            backend=anyio_backend_name,
        )
def test_assert_trace2(container_type, returns: ReturnsAsserts):
    """Test if our plugin will identify the container creation correctly."""
    with returns.assert_trace(container_type, _create_container_function):
        _create_container_function_intermediate(  # type: ignore
            container_type,
            1,
        )
def test_failed_assert_trace1(
    desired_type, wrong_type, returns: ReturnsAsserts,
):
    """Test if our plugin will identify the conainter was not created."""
    with pytest.raises(pytest.fail.Exception):  # noqa: PT012
        with returns.assert_trace(desired_type, _create_container_function):
            _create_container_function(wrong_type, 1)  # type: ignore
Example #7
0
def test_no_metadata_results(uploader: LibgenUploader,
                             returns: ReturnsAsserts):
    file_path = os.path.join(files_path, "minimal.epub")
    with returns.assert_trace(Failure, uploader._fetch_metadata):
        uploader.upload_fiction(file_path,
                                metadata_source="amazon_de",
                                metadata_query="012kd3o2llds")
Example #8
0
def test_invalid_metadata_language(uploader: LibgenUploader,
                                   returns: ReturnsAsserts):
    file_path = os.path.join(files_path, "minimal.epub")
    metadata = LibgenMetadata(language="Invalid")

    with returns.assert_trace(Failure, uploader._update_metadata):
        uploader.upload_fiction(
            file_path,
            metadata=metadata,
            metadata_source="amazon_it",
            metadata_query="8854165069",
        )
def test_safe_decorated_assert(container_type, returns: ReturnsAsserts):
    """Test if our plugin will catch containers from @safe-wrapped functions."""
    with returns.assert_trace(container_type, _safe_decorated_function):
        _safe_decorated_function(return_failure=container_type is Failure)