Ejemplo n.º 1
0
def test_constructor():
    period_1 = Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2))
    period_2 = Period(unix_dt(2011, 1, 5), unix_dt(2011, 1, 6), False, True)
    period_3 = Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2), True, False)
    period_set = PeriodSet({period_1, period_2, period_3})

    assert len(period_set.periods) == 2
    assert period_set.startPeriod == period_1
    assert period_set.endPeriod == period_2
    assert period_set.period == Period(unix_dt(2011, 1, 1),
                                       unix_dt(2011, 1, 6), True, True)
Ejemplo n.º 2
0
def test_constructor():
    t1 = unix_dt(2011, 1, 1)
    t2 = unix_dt(2011, 1, 5)
    t3 = unix_dt(2011, 1, 1)  # Duplicate!
    tset = TimestampSet({t1, t2, t3})

    assert len(tset.timestamps) == 2
    assert tset.startTimestamp == t1
    assert tset.endTimestamp == t2
    assert tset.timestampN(0) == t1
    assert tset.timestampN(1) == t2

    assert len(tset.periods) == 2
    assert tset.startPeriod == Period(t1, t1, True, True)
    assert tset.endPeriod == Period(t2, t2, True, True)
    assert tset.periodN(0) == Period(t1, t1, True, True)
    assert tset.periodN(1) == Period(t2, t2, True, True)
Ejemplo n.º 3
0
def test_constructor():
    period_1 = Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2))
    period_2 = Period(unix_dt(2011, 1, 5), unix_dt(2011, 1, 6), False, False)
    period_3 = Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2), True, False)
    assert period_1 == period_3
    assert period_2 != period_1
    assert period_2 != period_3

    assert period_1.lower == unix_dt(2011, 1, 1)
    assert period_1.upper == unix_dt(2011, 1, 2)
    assert period_1.lower_inc == True
    assert period_1.upper_inc == False

    assert period_2.lower == unix_dt(2011, 1, 5)
    assert period_2.upper == unix_dt(2011, 1, 6)
    assert period_2.lower_inc == False
    assert period_2.upper_inc == False
Ejemplo n.º 4
0
def test_simple_insert(session):
    period_1 = Period(
        datetime.datetime(2018, 1, 1, tzinfo=datetime.timezone.utc),
        datetime.datetime(2018, 1, 2, tzinfo=datetime.timezone.utc),
    )
    period_2 = Period(
        datetime.datetime(2018, 1, 10, tzinfo=datetime.timezone.utc),
        datetime.datetime(2018, 1, 11, tzinfo=datetime.timezone.utc),
    )
    periodset = PeriodSet({period_1, period_2})

    session.add(PeriodSets(periodset=periodset))
    session.commit()

    sql = session.query(PeriodSets).filter(PeriodSets.id == 1)
    assert sql.count() == 1

    results = sql.all()
    for result in results:
        assert result.id == 1
        assert result.periodset == periodset
        assert result.periodset.periods == {period_1, period_2}
        assert result.periodset.startPeriod == period_1
        assert result.periodset.endPeriod == period_2
Ejemplo n.º 5
0
def get_sample_period():
    return Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2))
Ejemplo n.º 6
0
def test_str():
    p = Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2))
    assert str(p) == "[2011-01-01T00:00:00+0000, 2011-01-02T00:00:00+0000)"
Ejemplo n.º 7
0
def test_functions():
    period_1 = Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2))
    assert period_1.timespan == datetime.timedelta(days=1)
    assert period_1.contains_timestamp(unix_dt(2011, 1, 1, 10))
Ejemplo n.º 8
0
import datetime
import pytest

from pymeos.time import Period

from ..utils import unix_dt


@pytest.mark.parametrize("actual", [
    Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2)),
    Period("2011-01-01", "2011-01-02"),
    Period("[2011-01-01, 2011-01-02T00:00:00+0000)"),
])
def test_different_constructors(actual):
    assert actual.lower == unix_dt(2011, 1, 1)
    assert actual.upper == unix_dt(2011, 1, 2)
    assert actual.lower_inc == True
    assert actual.upper_inc == False


def test_constructor():
    period_1 = Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2))
    period_2 = Period(unix_dt(2011, 1, 5), unix_dt(2011, 1, 6), False, False)
    period_3 = Period(unix_dt(2011, 1, 1), unix_dt(2011, 1, 2), True, False)
    assert period_1 == period_3
    assert period_2 != period_1
    assert period_2 != period_3

    assert period_1.lower == unix_dt(2011, 1, 1)
    assert period_1.upper == unix_dt(2011, 1, 2)
    assert period_1.lower_inc == True