-
Notifications
You must be signed in to change notification settings - Fork 51
Do not parse dates as prices. Sort imports. #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
c7948d5
1aadabe
4a81a99
2050433
d759b34
4a512b2
1ede7b5
32ae129
20ac018
737194c
b67f7a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,12 +11,14 @@ | |
| we've found in a wild; PRICE_PARSING_EXAMPLES_NEW is a list of tests for | ||
| new features. New tests should probably go these two lists. | ||
| """ | ||
| from typing import Optional, Union | ||
| from datetime import datetime | ||
| from decimal import Decimal | ||
| from typing import Optional, Union | ||
|
|
||
| import pytest | ||
|
|
||
| from price_parser import Price | ||
| from price_parser.parser import date_format, strip_date | ||
|
|
||
|
|
||
| class Example(Price): | ||
|
|
@@ -1944,6 +1946,21 @@ def __eq__(self, other): | |
| Example(None, '15.08.2017', | ||
| None, None, None), | ||
|
|
||
| Example(None, '0€ until May, 2005, 35€ afterwards', | ||
| '€', '0', 0), | ||
|
|
||
| Example(None, '2019-08-19: 22 USD', | ||
| 'USD', '22', 22), | ||
|
|
||
| Example(None, '2105 EUR at July, 2004', | ||
| 'EUR', '2105', 2105), | ||
|
|
||
| Example(None, '$10 EUR during March, 2016', | ||
| '$', '10', 10), | ||
|
|
||
| Example(None, '$10 EUR at March, 2016 or 2019-08-19', | ||
| '$', '10', 10), | ||
|
||
|
|
||
| # other incorrectly extracted prices | ||
| Example('8.5', '25-09', | ||
| None, None, None), | ||
|
|
@@ -1986,3 +2003,34 @@ def test_parsing(example: Example): | |
| ) | ||
| def test_price_amount_float(amount, amount_float): | ||
| assert Price(amount, None, None).amount_float == amount_float | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "price, result", | ||
| [ | ||
| ('10.04.2004', datetime(2004, 4, 10, 0, 0)), | ||
| ('July, 2004', datetime(2004, 7, 1, 0, 0)), | ||
| ('Jul, 2004', datetime(2004, 7, 1, 0, 0)), | ||
| ('200', None), | ||
| ('2004', None), | ||
| (2004, None), | ||
| (10.2014, None), | ||
| ] | ||
| ) | ||
| def test_date_format(price, result): | ||
| assert date_format(price) == result | ||
bulatbulat48 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "price, result", | ||
| [ | ||
| ('0€ until May, 2005, 35€ afterwards', '0€ until, 35€ afterwards'), | ||
| ('2019-08-19: 22 USD', ': 22 USD'), | ||
| ('105 EUR at July, 2004', '105 EUR at'), | ||
| ('$10 EUR during March, 2016', '$10 EUR during'), | ||
| ('$10 EUR during March, 2016 -- March, 2020', '$10 EUR during --'), | ||
| ('$10', '$10'), | ||
| ] | ||
| ) | ||
| def test_strip_date(price, result): | ||
| assert strip_date(price) == result | ||
Uh oh!
There was an error while loading. Please reload this page.