-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from ecatkins/strict_fix
Improve strict=True
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
import datefinder | ||
from datetime import datetime | ||
import pytz | ||
import sys | ||
import logging | ||
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) | ||
logger = logging.getLogger(__name__) | ||
|
||
today = datetime.today() | ||
|
||
|
||
@pytest.mark.parametrize('input_text, expected_date', [ | ||
('June 2018', []), | ||
('09/06/18', datetime(2018, 9, 6)), | ||
('09/06/2018', datetime(2018, 9, 6)), | ||
('recorded: 03/14/2008', datetime(2008, 3, 14)), | ||
('19th day of May, 2015', datetime(2015, 5, 19)), | ||
('19th day of May', []) | ||
]) | ||
def test_find_date_strings_strict(input_text, expected_date): | ||
if isinstance(expected_date,list): | ||
matches = list(datefinder.find_dates(input_text, strict=True)) | ||
assert matches == expected_date | ||
|
||
else: | ||
return_date = None | ||
for return_date in datefinder.find_dates(input_text, strict=True): | ||
assert return_date == expected_date | ||
assert return_date is not None, 'Did not find date for test line: "{}"'.format(input_text) # handles dates |