Skip to content

Commit

Permalink
import some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bfontaine committed Mar 4, 2024
1 parent 9abcaaa commit 0687d01
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 5 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ jobs:
- name: Lint with Mypy
run: |
poetry run mypy *.py bixomix
#- name: Run Tests
# run: |
# poetry run pytest --cov=bixomix
- name: Run Tests
run: |
poetry run pytest --cov=bixomix
- name: Test build
run: |
poetry build
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Thank you for taking the time to contribute to Bixomix.

We don’t accept new mixins because we only want to have code that we actually use, but you can contribute in fixing bugs
or adding tests. These mixins are extracted from our production code, which is heavily tested, but we haven’t taken the
time to add the tests in this repository yet.
time to add all the tests in this repository yet.
199 changes: 198 additions & 1 deletion poetry.lock

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

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ sqlalchemy = "^2.0"

[tool.poetry.group.dev.dependencies]
mypy = "^1"
pytest = "^8.1.0"
pytest-coverage = "^0.0"

[build-system]
requires = ["poetry-core"]
Expand Down
45 changes: 45 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from dataclasses import dataclass
from datetime import datetime

import pytest
from sqlalchemy.sql.functions import now as sql_now

from bixomix import UpdateFromDictMixin


@dataclass
class FakeModel(UpdateFromDictMixin):
foo: str = "foo"
bar: str = "bar"


def test_update_from_dict():
m = FakeModel()
m.update_from_dict({"foo": "bar"})
assert m.foo == "bar"


@pytest.mark.filterwarnings("ignore:.*non-existant attribute.*")
def test_update_from_dict_unknown_field():
m = FakeModel()
m.update_from_dict({"qux": 42})
assert not hasattr(m, "qux")


def test_update_from_dict_last_update():
@dataclass
class MyFakeModel(UpdateFromDictMixin):
foo: int
foo_last_update: datetime

before = datetime(2010, 1, 1, 0, 0, 0)

m = MyFakeModel(foo=42, foo_last_update=before)
m.update_from_dict({})
assert m.foo_last_update == before

m.update_from_dict({"foo": 42})
assert m.foo_last_update == before

m.update_from_dict({"foo": 43})
assert isinstance(m.foo_last_update, sql_now)

0 comments on commit 0687d01

Please sign in to comment.