Skip to content

Continue adding tests #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ documentation = "https://github.com/qaspen-python/psqlpy/blob/main/README.md"
profile = "black"
multi_line_output = 3

[tool.black]
line-length = 79

[tool.mypy]
strict = true
mypy_path = "python"
Expand Down
50 changes: 50 additions & 0 deletions python/tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,53 @@ async def test_cursor_fetch_relative(
)

assert not (records.result())


@pytest.mark.anyio
async def test_cursor_fetch_forward_all(
test_cursor: Cursor,
number_database_records: int,
) -> None:
"""Test that cursor execute FETCH FORWARD ALL correctly."""
default_fetch_number = 2
await test_cursor.fetch(fetch_number=default_fetch_number)

rest_results = await test_cursor.fetch_forward_all()

assert (
len(rest_results.result())
== number_database_records - default_fetch_number
)


@pytest.mark.anyio
async def test_cursor_fetch_backward(
test_cursor: Cursor,
) -> None:
"""Test cursor backward fetch."""
must_be_empty = await test_cursor.fetch_backward(backward_count=10)
assert not (must_be_empty.result())

default_fetch_number = 5
await test_cursor.fetch(fetch_number=default_fetch_number)

expected_number_of_results = 3
must_not_be_empty = await test_cursor.fetch_backward(
backward_count=expected_number_of_results,
)
assert len(must_not_be_empty.result()) == expected_number_of_results


@pytest.mark.anyio
async def test_cursor_fetch_backward_all(
test_cursor: Cursor,
) -> None:
"""Test cursor `fetch_backward_all`."""
must_be_empty = await test_cursor.fetch_backward_all()
assert not (must_be_empty.result())

default_fetch_number = 5
await test_cursor.fetch(fetch_number=default_fetch_number)

must_not_be_empty = await test_cursor.fetch_backward_all()
assert len(must_not_be_empty.result()) == default_fetch_number - 1