Skip to content

Commit

Permalink
Some typing and docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtarzia committed Mar 7, 2024
1 parent a23f210 commit 8acb9ad
Show file tree
Hide file tree
Showing 22 changed files with 506 additions and 435 deletions.
19 changes: 9 additions & 10 deletions tests/molecular/molecules/building_block/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def case_data(request) -> CaseData:


@pytest.fixture
def building_block(case_data):
def building_block(case_data: CaseData) -> stk.BuildingBlock:
"""
A :class:`.BuildingBlock` instance.
Expand All @@ -50,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
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
def test_get_num_functional_groups(case_data):
from .case_data import CaseData


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

Expand Down
40 changes: 21 additions & 19 deletions tests/molecular/molecules/building_block/test_get_placer_ids.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import itertools as it
from .case_data import CaseData

import stk

def test_get_placer_ids(case_data):

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

Expand All @@ -23,21 +24,22 @@ def test_get_placer_ids(case_data):
)


def _test_get_placer_ids(building_block, placer_ids):
def _test_get_placer_ids(
building_block: stk.BuildingBlock,
placer_ids: tuple[int, ...],
) -> None:
"""
Test :meth:`.BuildingBlock.get_placer_ids`.
Parameters
----------
building_block : :class:`.BuildingBlock`
The building block to test.
Parameters:
building_block:
The building block to test.
placer_ids : :class:`tuple` of :class:`int`
The correct placer ids.
placer_ids:
The correct placer ids.
Returns
-------
None : :class:`NoneType`
Returns:
:class:`NoneType`
"""

Expand Down
Loading

0 comments on commit 8acb9ad

Please sign in to comment.