Skip to content

Commit

Permalink
[MAINTENANCE] Refactor tests and add tests for private class `_Elemen…
Browse files Browse the repository at this point in the history
…t` (#85)
  • Loading branch information
VascoSch92 authored Jun 1, 2024
1 parent 74c8592 commit 9e10713
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 24 deletions.
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)
File renamed without changes.
File renamed without changes.
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)
File renamed without changes.
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.
File renamed without changes.
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

0 comments on commit 9e10713

Please sign in to comment.