Skip to content

Commit

Permalink
test: move new method to another file since it's unrelated to test re…
Browse files Browse the repository at this point in the history
…sources
  • Loading branch information
lars-reimann committed May 26, 2023
1 parent cf6abba commit 2a670cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
3 changes: 2 additions & 1 deletion tests/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._assertions import assert_that_tables_are_close
from ._resources import resolve_resource_path

__all__ = ["resolve_resource_path"]
__all__ = ["assert_that_tables_are_close", "resolve_resource_path"]
24 changes: 24 additions & 0 deletions tests/helpers/_assertions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
from safeds.data.tabular.containers import Table


def assert_that_tables_are_close(table1: Table, table2: Table) -> None:
"""
Assert that two tables are almost equal.
Parameters
----------
table1: Table
The first table.
table2: Table
The table to compare the first table to.
"""
assert table1.schema == table2.schema
for column_name in table1.column_names:
assert table1.get_column(column_name).type == table2.get_column(column_name).type
assert table1.get_column(column_name).type.is_numeric()
assert table2.get_column(column_name).type.is_numeric()
for i in range(table1.number_of_rows):
entry_1 = table1.get_column(column_name).get_value(i)
entry_2 = table2.get_column(column_name).get_value(i)
assert entry_1 == pytest.approx(entry_2)
26 changes: 0 additions & 26 deletions tests/helpers/_resources.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from pathlib import Path

from _pytest.python_api import approx

from src.safeds.data.tabular.containers import Table

_resources_root = Path(__file__).parent / ".." / "resources"


Expand All @@ -22,25 +18,3 @@ def resolve_resource_path(resource_path: str | Path) -> str:
The absolute path to the resource.
"""
return str(_resources_root / resource_path)


def check_that_tables_are_close(table1: Table, table2: Table) -> None:
"""
Check that two tables are almost equal.
Parameters
----------
table1: Table
The first table.
table2: Table
The table to compare the first table to.
"""
assert table1.schema == table2.schema
for column_name in table1.column_names:
assert table1.get_column(column_name).type == table2.get_column(column_name).type
assert table1.get_column(column_name).type.is_numeric()
assert table2.get_column(column_name).type.is_numeric()
for i in range(table1.number_of_rows):
entry_1 = table1.get_column(column_name).get_value(i)
entry_2 = table2.get_column(column_name).get_value(i)
assert entry_1 == approx(entry_2)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from safeds.data.tabular.transformation import StandardScaler
from safeds.exceptions import TransformerNotFittedError, UnknownColumnNameError

from tests.helpers._resources import check_that_tables_are_close
from tests.helpers import assert_that_tables_are_close


class TestFit:
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_should_not_change_transformed_table(self) -> None:
},
)

check_that_tables_are_close(transformed_table, expected)
assert_that_tables_are_close(transformed_table, expected)

def test_should_raise_if_not_fitted(self) -> None:
table = Table(
Expand Down

0 comments on commit 2a670cb

Please sign in to comment.