Skip to content

Commit

Permalink
Typehint tests/molecules/building_blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtarzia committed Feb 13, 2024
1 parent 04b7a33 commit bbd72c5
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 194 deletions.
66 changes: 35 additions & 31 deletions tests/molecular/molecules/building_block/case_data.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
import stk


class CaseData:
"""
A test case.
Attributes
----------
building_block : :class:`.BuildingBlock`
The building block to test.
Attributes:
building_block:
The building block, which will be written to a file, so
that it can be initialized from it.
functional_groups : :class:`tuple` of :class:`.FunctionalGroup`
The functional groups :attr:`.building_block` should be
holding.
functional_groups:
The functional groups :attr:`.building_block` should be
holding.
known_repr : str
The representation of the building block.
known_repr:
The representation of the building block.
core_atom_ids : :class:`tuple` of :class:`int`
The correct core atom ids for :attr:`.building_block`.
core_atom_ids:
The correct core atom ids for :attr:`.building_block`.
placer_ids : :class:`tuple` of :class:`int`
The correct *placer* ids for :attr:`.building_block`.
placer_ids:
The correct *placer* ids for :attr:`.building_block`.
"""

def __init__(
self,
building_block,
functional_groups,
known_repr,
core_atom_ids,
placer_ids,
):
building_block: stk.BuildingBlock,
functional_groups: tuple,
known_repr: str,
core_atom_ids: tuple[int, ...],
placer_ids: tuple[int, ...],
) -> None:
"""
Initialize a :class:`.CaseData` instance.
Parameters
----------
building_block : :class:`.BuildingBlock`
The building block to test.
Parameters:
building_block:
The building block, which will be written to a file, so
that it can be initialized from it.
functional_groups : :class:`tuple` of :class:`.FunctionalGroup`
The functional groups `building_block` should be holding.
functional_groups:
The functional groups :attr:`.building_block` should be
holding.
known_repr : str
The representation of the building block.
known_repr:
The representation of the building block.
core_atom_ids : :class:`tuple` of :class:`int`
The correct core atom ids for `building_block`.
core_atom_ids:
The correct core atom ids for :attr:`.building_block`.
placer_ids : :class:`tuple` of :class:`int`
The correct *placer* ids for `building_block`.
placer_ids:
The correct *placer* ids for :attr:`.building_block`.
"""

Expand Down
23 changes: 12 additions & 11 deletions tests/molecular/molecules/building_block/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Fixtures need be visible for lazy_fixture() calls.
from .fixtures import * # noqa

from .case_data import CaseData


@pytest.fixture(
params=(
Expand All @@ -17,7 +19,7 @@
lazy_fixture("init_from_rdkit_mol"),
),
)
def case_data(request):
def case_data(request) -> CaseData:
"""
A :class:`.CaseData` instance.
Expand All @@ -27,7 +29,7 @@ def case_data(request):


@pytest.fixture
def building_block(case_data):
def building_block(case_data: CaseData) -> stk.BuildingBlock:
"""
A :class:`.BuildingBlock` instance.
Expand All @@ -48,18 +50,17 @@ def building_block(case_data):
),
)
)
def get_functional_groups(request):
def get_functional_groups(
request: pytest.FixtureRequest,
) -> stk.FunctionalGroup:
"""
Yield the functional groups of a `molecule`.
Get the functional groups of a `molecule`.
Parameters
----------
molecule : :class:`.Molecule`
The molecule whose functional groups should be gotten.
Parameters:
molecule:
The molecule whose functional groups should be gotten.
Yields
------
:class:`.FunctionalGroup`
Returns:
A functional group of `molecule`.
"""
Expand Down
108 changes: 52 additions & 56 deletions tests/molecular/molecules/building_block/fixtures/init_from_file.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import pytest
import stk

from collections.abc import Iterable
from ..case_data import CaseData


@pytest.fixture(
params=[
"building_block.mol",
],
params=["building_block.mol"],
)
def path(tmpdir, request):
return tmpdir / request.param
Expand All @@ -17,78 +15,76 @@ class InitFromFileData:
"""
Stores data for the :meth:`.BuildingBlock.init_from_file`.
Attributes
----------
building_block : :class:`.BuildingBlock`
The building block, which will be written to a file, so that it
can be initialized from it.
Attributes:
building_block:
The building block, which will be written to a file, so
that it can be initialized from it.
init_functional_groups : :class:`iterable`
Passed to the `functional_groups` parameter of
:meth:`.BuildingBlock.init_from_file`.
init_functional_groups:
Passed to the `functional_groups` parameter of
:meth:`.BuildingBlock.init_from_file`.
init_placer_ids : :class:`tuple` or :class:`NoneType`
Passed to the `placer_ids` parameter of
:meth:`.BuildingBlock.init_from_file`.
init_placer_ids:
Passed to the `placer_ids` parameter of
:meth:`.BuildingBlock.init_from_file`.
case_data_functional_groups : :class:`tuple`
The functional groups the initialized building block should
have.
case_data_functional_groups:
The functional groups the initialized building block should
have.
case_data_core_atom_ids : :class:`tuple` of :class:`int`
The ids of core atoms the initialized building block should
have.
case_data_core_atom_ids:
The ids of core atoms the initialized building block should
have.
case_data_placer_ids : :class:`tuple` of :class:`int`
The ids of *placer* atoms the initialized building block should
have.
case_data_placer_ids: : :class:`tuple` of :class:`int`
The ids of *placer* atoms the initialized building block
should have.
known_repr : str
The representation of the building block.
known_repr:
The representation of the building block.
"""

def __init__(
self,
building_block,
init_functional_groups,
init_placer_ids,
case_data_functional_groups,
case_data_core_atom_ids,
case_data_placer_ids,
known_repr,
):
building_block: stk.BuildingBlock,
init_functional_groups: Iterable,
init_placer_ids: tuple | None,
case_data_functional_groups: tuple,
case_data_core_atom_ids: tuple[int, ...],
case_data_placer_ids: tuple[int, ...],
known_repr: str,
) -> None:
"""
Initialize a :class:`.InitFromData` instance.
Parameters
----------
building_block : :class:`.BuildingBlock`
The building block, which will be written to a file, so
that it can be initialized from it.
Parameters:
building_block:
The building block, which will be written to a file, so
that it can be initialized from it.
init_functional_groups : :class:`iterable`
Passed to the `functional_groups` parameter of
:meth:`.BuildingBlock.init_from_file`.
init_functional_groups:
Passed to the `functional_groups` parameter of
:meth:`.BuildingBlock.init_from_file`.
init_placer_ids : :class:`tuple` or :class:`NoneType`
Passed to the `placer_ids` parameter of
:meth:`.BuildingBlock.init_from_file`.
init_placer_ids:
Passed to the `placer_ids` parameter of
:meth:`.BuildingBlock.init_from_file`.
case_data_functional_groups : :class:`tuple`
The functional groups the initialized building block should
have.
case_data_functional_groups:
The functional groups the initialized building block should
have.
case_data_core_atom_ids : :class:`tuple` of :class:`int`
The ids of core atoms the initialized building block should
have.
case_data_core_atom_ids:
The ids of core atoms the initialized building block should
have.
case_data_placer_ids : :class:`tuple` of :class:`int`
The ids of *placer* atoms the initialized building block
should have.
case_data_placer_ids: : :class:`tuple` of :class:`int`
The ids of *placer* atoms the initialized building block
should have.
known_repr : str
The representation of the building block.
known_repr:
The representation of the building block.
"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import itertools as it

from .case_data import CaseData

def test_get_core_atom_ids(case_data):

def test_get_core_atom_ids(case_data: CaseData) -> None:
"""
Test :meth:`.BuildingBlock.get_core_atom_ids`.
Parameters
----------
case_data : :class:`.CaseData`
A test case. Holds the building block to test and the correct
core atom ids.
Parameters:
case_data:
A test case. Holds the building block to test and the correct
core atom ids.
Returns
-------
None : :class:`NoneType`
Returns:
:class:`NoneType`
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

from ..utilities import is_equivalent_functional_group

import stk
from .case_data import CaseData

def test_get_functional_groups(case_data):

def test_get_functional_groups(case_data: CaseData) -> None:
"""
Test :meth:`.BuildingBlock.get_functional_groups`.
Parameters
----------
case_data : :class:`.CaseData`
A test case. Holds the building block to test and the correct
functional groups.
Parameters:
case_data:
A test case. Holds the building block to test and the correct
functional groups.
Returns
-------
None : :class:`NoneType`
Returns:
:class:`NoneType`
"""

Expand All @@ -25,21 +26,22 @@ def test_get_functional_groups(case_data):
)


def _test_get_functional_groups(building_block, functional_groups):
def _test_get_functional_groups(
building_block: stk.BuildingBlock,
functional_groups: tuple[stk.FunctionalGroup],
) -> None:
"""
Test :meth:`.BuildingBlock.get_functional_groups`.
Parameters
----------
building_block : :class:`.BuildingBlock`
The building block to test.
Parameters:
building_block:
The building block to test.
functional_groups : :class:`tuple` of :class:`.FunctionalGroup`
The correct functional groups.
functional_groups:
The correct functional groups.
Returns
-------
None : :class:`NoneType`
Returns:
:class:`NoneType`
"""

Expand Down
Loading

0 comments on commit bbd72c5

Please sign in to comment.