Skip to content

Commit

Permalink
Merge pull request #199 from simonsobs/dev
Browse files Browse the repository at this point in the history
Reduce sample sizes in Hypothesis tests
  • Loading branch information
TaiSakuma authored Feb 20, 2025
2 parents 9461a10 + 2b25977 commit 8a4e2e8
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# pstats files
*.prof

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from asyncio import to_thread

from alembic import command
from hypothesis import given, note
from hypothesis import Phase, given, note, settings
from sqlalchemy import select

from nextline_rdb.alembic.models import rev_5a08750d6760 as models_old
Expand All @@ -15,6 +15,7 @@
REVISION_NEW = 'f9a742bb2297'


@settings(max_examples=20, phases=(Phase.generate,)) # Avoid shrinking
@given(runs=st_model_run_list(generate_traces=True))
async def test_migration(
alembic_config_factory: AlembicConfigFactory, runs: list[models_old.Run]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from asyncio import to_thread

from alembic import command
from hypothesis import given, note
from hypothesis import Phase, given, note, settings
from hypothesis import strategies as st
from sqlalchemy import select

Expand All @@ -15,6 +15,7 @@
REVISION_NEW = 'c72fa3ee6a1a'


@settings(max_examples=20, phases=(Phase.generate,)) # Avoid shrinking
@given(scripts=st.lists(st_model_script(), min_size=0, max_size=5))
async def test_migration(
alembic_config_factory: AlembicConfigFactory, scripts: list[models_old.Script]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from asyncio import to_thread

from alembic import command
from hypothesis import given, note
from hypothesis import Phase, given, note, settings
from hypothesis import strategies as st

from nextline_rdb.alembic.models import rev_f9a742bb2297 as models_old
Expand All @@ -16,6 +16,7 @@
REVISION_NEW = '4dc6a93dfed8'


@settings(max_examples=20, phases=(Phase.generate,)) # Avoid shrinking
@given(scripts=st.lists(st_model_script(), min_size=0, max_size=5))
async def test_migration(
alembic_config_factory: AlembicConfigFactory, scripts: list[models_old.Script]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
REVISION_NEW = '8d24d9c2e9ba'


@settings(phases=(Phase.generate,)) # Avoid shrinking
@settings(max_examples=20, phases=(Phase.generate,)) # Avoid shrinking
@given(instances=st_model_instance_list(min_size=0, max_size=5))
async def test_migration(
alembic_config_factory: AlembicConfigFactory, instances: list[models_old.Model]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
REVISION_NEW = '2cf3fc3d3dc5'


@settings(phases=(Phase.generate,)) # Avoid shrinking
@settings(max_examples=20, phases=(Phase.generate,)) # Avoid shrinking
@given(instances=st_model_instance_list(min_size=0, max_size=5))
async def test_migration(
alembic_config_factory: AlembicConfigFactory, instances: list[models_old.Model]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
REVISION_NEW = 'f3edea6dbde2'


@settings(phases=(Phase.generate,)) # Avoid shrinking
@settings(max_examples=20, phases=(Phase.generate,)) # Avoid shrinking
@given(instances=st_model_instance_list(min_size=0, max_size=5))
async def test_migration(
alembic_config_factory: AlembicConfigFactory, instances: list[models_old.Model]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
REVISION_NEW = '15003e123b98'


@settings(phases=(Phase.generate,)) # Avoid shrinking
@settings(max_examples=20, phases=(Phase.generate,)) # Avoid shrinking
@given(instances=st_model_instance_list(min_size=0, max_size=5))
async def test_migration(
alembic_config_factory: AlembicConfigFactory, instances: list[models_old.Model]
Expand Down
3 changes: 2 additions & 1 deletion tests/schema/mutations/test_delete_runs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import strawberry
from hypothesis import given, note
from hypothesis import Phase, given, note, settings
from hypothesis import strategies as st
from sqlalchemy import select
from strawberry.types import ExecutionResult
Expand Down Expand Up @@ -41,6 +41,7 @@ def st_query_variables(
return variables, to_keep, to_delete


@settings(max_examples=10, phases=(Phase.generate,)) # Avoid shrinking
@given(st.data())
async def test_delete_runs(data: st.DataObject) -> None:
schema = strawberry.Schema(query=Query, mutation=Mutation)
Expand Down
6 changes: 5 additions & 1 deletion tests/schema/queries/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
import strawberry
from hypothesis import given, note
from hypothesis import given, note, settings
from hypothesis import strategies as st
from strawberry.types import ExecutionResult

Expand Down Expand Up @@ -43,6 +43,7 @@ class Edge(TypedDict):
node: Node


@settings(max_examples=20)
@given(runs=st_model_run_list(generate_traces=False, min_size=0, max_size=12))
async def test_all(runs: list[Run]) -> None:
schema = strawberry.Schema(query=Query)
Expand Down Expand Up @@ -76,6 +77,7 @@ async def test_all(runs: list[Run]) -> None:
assert nodes == list(reversed(nodes_saved))


@settings(max_examples=20)
@given(
runs=st_model_run_list(generate_traces=False, min_size=0, max_size=12),
first=st.integers(min_value=1, max_value=15),
Expand Down Expand Up @@ -129,6 +131,7 @@ async def test_forward(runs: list[Run], first: int) -> None:
assert nodes == list(reversed(nodes_saved))


@settings(max_examples=20)
@given(
runs=st_model_run_list(generate_traces=False, min_size=0, max_size=12),
last=st.integers(min_value=1, max_value=15),
Expand Down Expand Up @@ -182,6 +185,7 @@ async def test_backward(runs: list[Run], last: int) -> None:
assert nodes == nodes_saved


@settings(max_examples=20)
@given(runs=st_model_run_list(generate_traces=False, min_size=0, max_size=12))
async def test_cursor(runs: list[Run]) -> None:
schema = strawberry.Schema(query=Query)
Expand Down
2 changes: 1 addition & 1 deletion tests/schema/queries/test_rdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tests.schema.graphql import QUERY_RDB_CONNECTIONS


@settings(phases=(Phase.generate,)) # Avoid shrinking
@settings(max_examples=10, phases=(Phase.generate,)) # Avoid shrinking
@given(runs=st_model_run_list(generate_traces=True, min_size=0, max_size=3))
async def test_history(runs: list[Run]) -> None:
note(f'runs: {runs}')
Expand Down
2 changes: 1 addition & 1 deletion tests/schema/queries/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def st_query_variables(
return variables


@settings(phases=(Phase.generate,)) # Avoid shrinking
@settings(max_examples=10, phases=(Phase.generate,)) # Avoid shrinking
@given(st.data())
async def test_run(data: st.DataObject) -> None:
schema = strawberry.Schema(query=Query)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hypothesis import given
from hypothesis import given, settings

from nextline import Nextline
from nextline_rdb.db import DB
Expand All @@ -8,6 +8,7 @@
from nextline_test_utils.strategies import st_python_scripts


@settings(max_examples=20)
@given(
runs=st_model_run_list(generate_traces=False, min_size=0, max_size=2),
default_statement=st_python_scripts(),
Expand Down
2 changes: 1 addition & 1 deletion tests/write/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def mock_nextline(hook: PluginManager) -> Nextline:
return nextline


@settings(phases=(Phase.generate,)) # Avoid shrinking
@settings(max_examples=20, phases=(Phase.generate,)) # Avoid shrinking
@given(
instances=st_model_instance_list(
min_size=0, max_size=5, allow_run_started_at_none=False
Expand Down

0 comments on commit 8a4e2e8

Please sign in to comment.