Exemplo n.º 1
0
def test_time_interval_parse(text, tests):
    reset_options()
    interval = DisjunctiveIntervals.parse_time(text)
    for test in tests:
        datetime = testdata.str_to_datetime(test["datetime"])
        expected_match = test["expected"]
        default = TimeMatchDescription.TIME_MATCHING
        result = interval.is_satisfied(datetime, default)
        assert str(testdata.md2bool(result)) == expected_match
Exemplo n.º 2
0
def test_weekday_interval_parse(text, tests):
    reset_options()
    testdata.apply_language_configurations("lang_en")
    interval = DisjunctiveIntervals.parse_weekday(text)
    for test in tests:
        datetime = testdata.str_to_date(test["date"])
        expected_match = test["expected"]
        default = TimeMatchDescription.WEEKDAY_MATCHING
        result = interval.is_satisfied(datetime, default)
        assert str(testdata.md2bool(result)) == expected_match
Exemplo n.º 3
0
def test_time_delta(spec, config, tests):
    reset_options()
    interval = DisjunctiveIntervals.parse_time(spec)
    TimeInterval.set_options(config)
    for test in tests:
        test_time = test["test_time"]
        expected = test["expected"]
        test_time = testdata.str_to_time(test_time)
        test_date = datetime.combine(datetime.today(), test_time)
        default = TimeMatchDescription.DATE_MATCHING
        mdesc = interval.is_satisfied(test_date, default)
        assert str(testdata.md2bool(mdesc)) == expected
Exemplo n.º 4
0
def _test_match(prefer, tests):
    """Compare cleaned dicts of loaded meetings with expected dicts."""
    for test in tests:
        date = test["date"]
        date = testdata.str_to_datetime(date)
        expected = test["expected"]
        if isinstance(prefer, dict):
            pref = TimePreference.from_dict(prefer)
        elif isinstance(prefer, str):
            pref = TimePreference.from_str(prefer)
        mdesc = pref.match(date)
        assert str(testdata.md2bool(mdesc)) == expected