Skip to content
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

[MAINTENANCE] Refactor tests and add tests for private class _Element #85

Merged
merged 2 commits into from
Jun 1, 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
27 changes: 22 additions & 5 deletions symmetria/elements/_base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
from dataclasses import dataclass


@dataclass(init=False, frozen=True, order=False, eq=False)
class _Element:
"""Base class for elements."""

@staticmethod
def name() -> str:
"""Shortcut for the class name."""
return __class__.__name__

def rep(self) -> str:
"""Shortcut for `__repr__()`."""
return self.__repr__()

def typename(self) -> str:
"""Shortcut for the name of the class type.

:return: The name of the class type.
:rtype: str

:example:
>>> from symmetria import Cycle, CycleDecomposition, Permutation
...
>>> Permutation(1, 2, 3).typename()
'Permutation'
>>> Cycle(1, 2).typename()
'Cycle'
>>> CycleDecomposition(Cycle(1, 3, 2)).typename()
'CycleDecomposition'
"""
return self.__class__.__name__
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions tests/tests_elements/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

from symmetria import Cycle, Permutation, CycleDecomposition
from tests.test_utils import _check_values
from symmetria.elements._base import _Element


@pytest.mark.parametrize(
argnames="expression, evaluation, expected",
argvalues=[
("_element.name()", _Element().typename(), "_Element"),
("Permutation(1).name()", Permutation(1).typename(), "Permutation"),
("Cycle(1).name()", Cycle(1).typename(), "Cycle"),
("CycleDecomposition(Cycle(1)).name()", CycleDecomposition(Cycle(1)).typename(), "CycleDecomposition"),
],
)
def test_name(expression, evaluation, expected) -> None:
_check_values(expression=expression, evaluation=evaluation, expected=expected)


@pytest.mark.parametrize(
argnames="expression, evaluation, expected",
argvalues=[
("_element.rep()", _Element().rep(), "_Element()"),
("Permutation(1).rep()", Permutation(1).rep(), Permutation(1).__repr__()),
("Cycle(1).rep()", Cycle(1).rep(), Cycle(1).__repr__()),
(
"CycleDecomposition(Cycle(1)).rep()",
CycleDecomposition(Cycle(1)).rep(),
CycleDecomposition(Cycle(1)).__repr__(),
),
],
)
def test_rep(expression, evaluation, expected) -> None:
_check_values(expression=expression, evaluation=evaluation, expected=expected)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from symmetria import Cycle
from tests.tests_cycle.test_cases import (
from tests.tests_elements.tests_cycle.test_cases import (
TEST_CONSTRUCTOR,
TEST_CONSTRUCTOR_ERROR,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from symmetria import Cycle
from tests.test_factory import _check_values
from tests.tests_cycle.test_cases import (
from tests.test_utils import _check_values
from tests.tests_elements.tests_cycle.test_cases import (
TEST_MAP,
TEST_SGN,
TEST_ORBIT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from tests.test_factory import _check_values
from tests.tests_cycle.test_cases import (
from tests.test_utils import _check_values
from tests.tests_elements.tests_cycle.test_cases import (
TEST_EQ,
TEST_INT,
TEST_LEN,
Expand Down Expand Up @@ -126,4 +126,4 @@ def test_pow_error(cycle, power, error, msg) -> None:
)
def test_repr(cycle, expected_value) -> None:
"""Tests for the method `__repr__()`."""
_check_values(expression=f"{cycle.name}.__repr__()", evaluation=cycle.__repr__(), expected=expected_value)
_check_values(expression=f"{cycle.typename}.__repr__()", evaluation=cycle.__repr__(), expected=expected_value)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from symmetria import CycleDecomposition
from tests.tests_cycle_decomposition.test_cases import (
from tests.tests_elements.tests_cycle_decomposition.test_cases import (
TEST_CONSTRUCTOR,
TEST_CONSTRUCTOR_ERROR,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from tests.test_factory import _check_values
from tests.tests_cycle_decomposition.test_cases import (
from tests.test_utils import _check_values
from tests.tests_elements.tests_cycle_decomposition.test_cases import (
TEST_MAP,
TEST_SGN,
TEST_ORBIT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from symmetria import Cycle, CycleDecomposition
from tests.test_factory import _check_values
from tests.tests_cycle_decomposition.test_cases import (
from tests.test_utils import _check_values
from tests.tests_elements.tests_cycle_decomposition.test_cases import (
TEST_EQ,
TEST_POW,
TEST_BOOL,
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_pow_error(cycle_decomposition, power, error, msg) -> None:
def test_repr(cycle_decomposition, expected_value) -> None:
"""Tests for the method `__repr__()`."""
_check_values(
expression=f"{cycle_decomposition.name}.__repr__()",
expression=f"{cycle_decomposition.typename}.__repr__()",
evaluation=cycle_decomposition.__repr__(),
expected=expected_value,
)
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from symmetria import Permutation
from tests.test_factory import _check_values
from tests.tests_permutation.test_cases import (
from tests.test_utils import _check_values
from tests.tests_elements.tests_permutation.test_cases import (
TEST_CONSTRUCTOR,
TEST_CONSTRUCTOR_ERROR,
TEST_CONSTRUCTOR_FROM_DICT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from tests.test_factory import _check_values
from tests.tests_permutation.test_cases import (
from tests.test_utils import _check_values
from tests.tests_elements.tests_permutation.test_cases import (
TEST_MAP,
TEST_SGN,
TEST_IMAGE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from tests.test_factory import _check_values
from tests.tests_permutation.test_cases import (
from tests.test_utils import _check_values
from tests.tests_elements.tests_permutation.test_cases import (
TEST_EQ,
TEST_INT,
TEST_LEN,
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_pow_error(permutation, power, error, msg) -> None:
def test_repr(permutation, expected_value) -> None:
"""Tests for the method `__repr__()`."""
_check_values(
expression=f"{permutation.name}.__repr__()", evaluation=permutation.__repr__(), expected=expected_value
expression=f"{permutation.typename}.__repr__()", evaluation=permutation.__repr__(), expected=expected_value
)


Expand Down
Loading