Skip to content

Commit

Permalink
fix(statement): coerce amount with comma to float
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-awd committed Oct 8, 2023
1 parent 2fbaca4 commit c9eed95
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
7 changes: 7 additions & 0 deletions monopoly/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from functools import cached_property

from pandas import DataFrame
from pydantic import validator
from pydantic.dataclasses import dataclass

from monopoly.config import StatementConfig, arbitrary_config
Expand All @@ -19,6 +20,12 @@ class Transaction:
description: str
amount: float

@validator("amount", pre=True)
def adjust_number_format(cls, value: object) -> object:
if isinstance(value, str):
return value.replace(",", "")
return value


@dataclass(config=arbitrary_config)
class Statement:
Expand Down
31 changes: 30 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 @@ -28,6 +28,7 @@ pytest = "^7.4.1"
pytest-xdist = "^3.3.1"
pysnooper = "^1.2.0"
google-api-python-client-stubs = "^1.17.0"
pylint-pydantic = "^0.3.0"


[tool.taskipy.tasks]
Expand All @@ -46,6 +47,7 @@ disable = [
"no-member"
]
ignore-paths = ["tests"]
load-plugins = "pylint_pydantic"

[tool.black]
line-length = 88
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_transaction_comma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from monopoly.statement import Transaction


def test_transaction_handles_comma():
transaction = Transaction("2099-09-10", "foo", "123,123.12")
assert transaction.amount == 123123.12

0 comments on commit c9eed95

Please sign in to comment.