Skip to content

Commit

Permalink
chore: separate some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekMaggio committed May 1, 2024
1 parent 1f996ae commit 949cfd0
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Test data generation for deck configuration tests."""
from hypothesis import assume, strategies as st
from test_data_generation.deck_configuration.datashapes import (
Column,
DeckConfiguration,
Slot,
PossibleSlotContents as PSC,
)

from test_data_generation.deck_configuration.strategy.helper_strategies import a_column


def _above_or_below_is_module_or_trash(col: Column, slot: Slot) -> bool:
"""Return True if the deck has a module above or below the specified slot."""
above = col.slot_above(slot)
below = col.slot_below(slot)

return (above is not None and above.contents.is_module_or_trash_bin()) or (
below is not None and below.contents.is_module_or_trash_bin()
)


@st.composite
def a_deck_configuration_with_a_module_or_trash_slot_above_or_below_a_heater_shaker(
draw: st.DrawFn,
) -> DeckConfiguration:
"""Generate a deck with a module or trash bin fixture above or below a heater shaker."""
deck = draw(
st.builds(
DeckConfiguration.from_cols,
col1=a_column("1"),
col2=a_column(
"2", content_options=[PSC.LABWARE_SLOT, PSC.MAGNETIC_BLOCK_MODULE]
),
col3=a_column("3"),
)
)
column = deck.column_by_number(draw(st.sampled_from(["1", "3"])))

assume(column.number_of(PSC.HEATER_SHAKER_MODULE) in [1, 2])
for slot in column.slots:
if slot.contents is PSC.HEATER_SHAKER_MODULE:
assume(_above_or_below_is_module_or_trash(column, slot))
deck.override_with_column(column)

return deck


@st.composite
def a_deck_configuration_with_invalid_fixture_in_col_2(
draw: st.DrawFn,
) -> DeckConfiguration:
"""Generate a deck with an invalid fixture in column 2."""
POSSIBLE_FIXTURES = [
PSC.LABWARE_SLOT,
PSC.TEMPERATURE_MODULE,
PSC.HEATER_SHAKER_MODULE,
PSC.TRASH_BIN,
PSC.MAGNETIC_BLOCK_MODULE,
]
INVALID_FIXTURES = [
PSC.HEATER_SHAKER_MODULE,
PSC.TRASH_BIN,
PSC.TEMPERATURE_MODULE,
]
column2 = draw(a_column("2", content_options=POSSIBLE_FIXTURES))
num_invalid_fixtures = len(
[True for slot in column2.slots if slot.contents.is_one_of(INVALID_FIXTURES)]
)
assume(num_invalid_fixtures > 0)

deck = draw(
st.builds(
DeckConfiguration.from_cols,
col1=a_column("1"),
col2=st.just(column2),
col3=a_column("3"),
)
)

return deck
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
"""Test data generation for deck configuration tests."""
from typing import List
from hypothesis import assume, strategies as st
from hypothesis import strategies as st
from test_data_generation.deck_configuration.datashapes import (
Column,
DeckConfiguration,
Row,
Slot,
PossibleSlotContents as PSC,
)

from test_data_generation.deck_configuration.deck_evaluation import (
above_or_below_is_module_or_trash,
)


@st.composite
def a_slot(
Expand Down Expand Up @@ -120,75 +115,3 @@ def a_column(
d=a_slot(row="d", col=col, content_options=content_options),
)
)


def _above_or_below_is_module_or_trash(col: Column, slot: Slot) -> bool:
"""Return True if the deck has a module above or below the specified slot."""
above = col.slot_above(slot)
below = col.slot_below(slot)

return (above is not None and above.contents.is_module_or_trash_bin()) or (
below is not None and below.contents.is_module_or_trash_bin()
)



@st.composite
def a_deck_configuration_with_a_module_or_trash_slot_above_or_below_a_heater_shaker(
draw: st.DrawFn,
) -> DeckConfiguration:
"""Generate a deck with a module or trash bin fixture above or below a heater shaker."""
deck = draw(
st.builds(
DeckConfiguration.from_cols,
col1=a_column("1"),
col2=a_column(
"2", content_options=[PSC.LABWARE_SLOT, PSC.MAGNETIC_BLOCK_MODULE]
),
col3=a_column("3"),
)
)
column = deck.column_by_number(draw(st.sampled_from(["1", "3"])))

assume(column.number_of(PSC.HEATER_SHAKER_MODULE) in [1, 2])
for slot in column.slots:
if slot.contents is PSC.HEATER_SHAKER_MODULE:
assume(_above_or_below_is_module_or_trash(column, slot))
deck.override_with_column(column)

return deck


@st.composite
def a_deck_configuration_with_invalid_fixture_in_col_2(
draw: st.DrawFn,
) -> DeckConfiguration:
"""Generate a deck with an invalid fixture in column 2."""
POSSIBLE_FIXTURES = [
PSC.LABWARE_SLOT,
PSC.TEMPERATURE_MODULE,
PSC.HEATER_SHAKER_MODULE,
PSC.TRASH_BIN,
PSC.MAGNETIC_BLOCK_MODULE,
]
INVALID_FIXTURES = [
PSC.HEATER_SHAKER_MODULE,
PSC.TRASH_BIN,
PSC.TEMPERATURE_MODULE,
]
column2 = draw(a_column("2", content_options=POSSIBLE_FIXTURES))
num_invalid_fixtures = len(
[True for slot in column2.slots if slot.contents.is_one_of(INVALID_FIXTURES)]
)
assume(num_invalid_fixtures > 0)

deck = draw(
st.builds(
DeckConfiguration.from_cols,
col1=a_column("1"),
col2=st.just(column2),
col3=a_column("3"),
)
)

return deck
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from hypothesis import given, settings, HealthCheck
from test_data_generation.deck_configuration.datashapes import DeckConfiguration
from test_data_generation.deck_configuration.strategies import (
from test_data_generation.deck_configuration.strategy.final_strategies import (
a_deck_configuration_with_a_module_or_trash_slot_above_or_below_a_heater_shaker,
a_deck_configuration_with_invalid_fixture_in_col_2,
)
Expand All @@ -18,7 +18,7 @@
suppress_health_check=[HealthCheck.filter_too_much, HealthCheck.too_slow],
)
def test_above_below_heater_shaker(deck_config: DeckConfiguration) -> None:
"""I hypothesize, that every deck configuration with a non-labware slot fixture above or below a heater-shaker is invalid."""
"""I hypothesize, that any deck configuration with a non-labware slot fixture above or below a heater-shaker is invalid."""
print(deck_config)

# TODO: create protocol and run analysis
Expand All @@ -35,7 +35,7 @@ def test_above_below_heater_shaker(deck_config: DeckConfiguration) -> None:
suppress_health_check=[HealthCheck.filter_too_much, HealthCheck.too_slow],
)
def test_invalid_fixture_in_col_2(deck_config: DeckConfiguration) -> None:
"""I hypothesize, that every deck configuration that contains at least one, Heater-Shaker, Trash Bin, or Temperature module, in column 2 is invalid."""
"""I hypothesize, that any deck configuration that contains at least one, Heater-Shaker, Trash Bin, or Temperature module, in column 2 is invalid."""
print(deck_config)

# TODO: Same as above

0 comments on commit 949cfd0

Please sign in to comment.