-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_e2e.py
More file actions
36 lines (29 loc) · 1.39 KB
/
test_e2e.py
File metadata and controls
36 lines (29 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pytest
from datasets.cases.short import CUSTOM_CONFIG_CASES, DEFAULT_CASES, MATCHED_TEXT_CASES, NO_INFERENCE_CASES
from timefhuman import timefhuman
from timefhuman.main import tfhConfig
def case_text(case):
if len(case) == 2:
return case[0]
return case[1]
@pytest.mark.parametrize("case", DEFAULT_CASES, ids=case_text)
def test_default(now, case):
"""Default behavior should be to infer datetimes and times."""
test_input, expected = case
actual = timefhuman(test_input, config=tfhConfig(now=now))
assert actual == expected, f"Expected: {expected}\nGot: {actual}"
@pytest.mark.parametrize("case", NO_INFERENCE_CASES, ids=case_text)
def test_no_inference(now, case):
"""Return exactly the date or time, without inferring the other."""
test_input, expected = case
config = tfhConfig(infer_datetimes=False, now=now)
assert timefhuman(test_input, config=config) == expected
@pytest.mark.parametrize("case", CUSTOM_CONFIG_CASES, ids=case_text)
def test_custom_config(now, case):
config_kwargs, test_input, expected = case
config = tfhConfig(now=now, **config_kwargs)
assert timefhuman(test_input, config=config) == expected
@pytest.mark.parametrize("case", MATCHED_TEXT_CASES, ids=case_text)
def test_matched_text(now, case): # gh#9
test_input, expected = case
assert timefhuman(test_input, tfhConfig(now=now, return_matched_text=True)) == expected