def test_time_interval_entity_get_value() -> None:
    body = "to 4 am"
    value = {
        "to": {
            "value": "2021-06-03T17:00:00.000+05:30",
            "grain": "hour"
        },
        "from": {
            "value": "2021-06-03T15:00:00.000+05:30",
            "grain": "hour"
        },
        "type": "interval",
    }
    entity = TimeIntervalEntity(
        range={
            "from": 0,
            "to": len(body)
        },
        body=body,
        entity_type="time",
        grain="hour",
        values=[value],
        value=value,
    )
    value = "2021-06-03T15:00:00+05:30"
    assert entity.get_value() == datetime.fromisoformat(value)
Exemple #2
0
def test_interval_entity_value_none() -> None:
    body = "between 2 to 4 am"
    entity = TimeIntervalEntity(
        range={"from": 0, "to": len(body)},
        body=body,
        type="time",
        grain="hour",
    )
    with pytest.raises(TypeError):
        entity.set_value()
Exemple #3
0
def test_interval_entity_set_value_values_present() -> None:
    body = "between 2 to 4 am"
    value = {
        "to": {"value": "2021-01-22T05:00:00.000+05:30", "grain": "hour"},
        "from": {"value": "2021-01-22T02:00:00.000+05:30", "grain": "hour"},
    }
    entity = TimeIntervalEntity(
        range={"from": 0, "to": len(body)},
        body=body,
        type="time",
        grain="hour",
    )
    entity.set_value(value)
    assert entity.value == value
def test_bad_interval_entity_neither_from_nor_to() -> None:
    body = "to 4 am"
    value = {"type": "interval"}
    entity = TimeIntervalEntity(
        range={
            "from": 0,
            "to": len(body)
        },
        body=body,
        entity_type="time",
        grain="hour",
        values=[value],
    )
    with pytest.raises(KeyError):
        entity.get_value(value)
def test_time_interval_entity_value_not_dict_error():
    body = "from 4 pm to 12 am"
    with pytest.raises(TypeError):
        _ = TimeIntervalEntity(range={
            "from": 0,
            "to": len(body)
        },
                               body=body,
                               entity_type="time",
                               grain=0)
def test_interval_entity_only_to() -> None:
    body = "to 4 am"
    value = {
        "to": {
            "value": "2021-01-22T04:00:00.000+05:30",
            "grain": "hour"
        },
    }
    entity = TimeIntervalEntity(
        range={
            "from": 0,
            "to": len(body)
        },
        body=body,
        entity_type="time",
        grain="hour",
        values=[value],
    )
    entity.set_value(value=value)
    assert entity.value == value
def test_time_interval_entity_no_value() -> None:
    body = "to 4 am"
    value = {
        "to": {
            "value": "2021-04-17T04:00:00.000+05:30",
            "grain": "hour"
        },
        "type": "interval",
    }
    entity = TimeIntervalEntity(
        range={
            "from": 0,
            "to": len(body)
        },
        body=body,
        entity_type="time",
        grain="hour",
        values=[value],
        value=value,
    )
    entity.values = entity.value
    with pytest.raises(TypeError):
        entity.set_value()
Exemple #8
0
def test_entity_grain_to_type() -> None:
    body = "between 2 to 4 am"
    value = {
        "to": {"value": "2021-01-22T05:00:00.000+05:30", "grain": "hour"},
        "from": {"value": "2021-01-22T02:00:00.000+05:30", "grain": "hour"},
    }
    entity = TimeIntervalEntity(
        range={"from": 0, "to": len(body)},
        body=body,
        type="time",
        grain="hour",
        values=[value],
    )
    assert entity.entity_type == "hour"
    assert entity.type == "hour"