Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
test: test Titanic example more thoroughly (#22)
Browse files Browse the repository at this point in the history
Closes #16.

### Summary of Changes

Now we also check
* number of rows
* schema
* which columns have missing values.

---------

Co-authored-by: lars-reimann <[email protected]>
  • Loading branch information
lars-reimann and lars-reimann authored Mar 15, 2023
1 parent d8e8a1b commit 54c568f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ mkdocs-jupyter = "^0.23.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
addopts = "--strict-markers"
markers = [
"smoke: quickly testing core functionality",
]

[tool.black]
line-length = 120
45 changes: 41 additions & 4 deletions tests/safeds_examples/tabular/titanic/test_load_titanic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
import pytest
from safeds.data.tabular import Table
from safeds.data.tabular.typing import (
FloatColumnType,
IntColumnType,
StringColumnType,
TableSchema,
)
from safeds_examples.tabular import load_titanic


def test_load_titanic() -> None:
titanic = load_titanic()
class TestLoadTitanic:
@pytest.fixture
def titanic(self) -> Table:
return load_titanic()

assert isinstance(titanic, Table)
assert titanic.count_rows() > 0
@pytest.mark.smoke
def test_returns_table(self) -> None:
titanic = load_titanic()

assert isinstance(titanic, Table)

def test_row_count(self, titanic: Table) -> None:
assert titanic.count_rows() == 1309

def test_schema(self, titanic: Table) -> None:
assert titanic.schema == TableSchema(
{
"Age": FloatColumnType(),
"Cabin Number": StringColumnType(),
"Fare": FloatColumnType(),
"Name": StringColumnType(),
"Number of Parents or Children Aboard": IntColumnType(),
"Number of Siblings or Spouses Aboard": IntColumnType(),
"Port of Embarkation": StringColumnType(),
"Sex": StringColumnType(),
"Survived": IntColumnType(),
"Ticket Number": StringColumnType(),
"Travel Class": IntColumnType(),
}
)

def test_columns_with_missing_values(self, titanic: Table) -> None:
actual_column_names = {column.name for column in titanic.list_columns_with_missing_values()}

assert actual_column_names == {"Age", "Port of Embarkation", "Fare", "Cabin Number"}

0 comments on commit 54c568f

Please sign in to comment.