async def test_tboolinst_constructors(connection, expected_tboolinst): params = TBoolInst(expected_tboolinst) await connection.execute('INSERT INTO tbl_tboolinst (temp) VALUES ($1)', params) result = await connection.fetchval( 'SELECT temp FROM tbl_tboolinst WHERE temp=$1', params, column=0) assert result == TBoolInst(expected_tboolinst)
def test_tboolseq_accessors(cursor, expected_tboolseq): assert TBoolSeq(expected_tboolseq).tempSubtype() == 'Sequence' assert TBoolSeq(expected_tboolseq).getValues == [True, False] assert TBoolSeq(expected_tboolseq).startValue == True assert TBoolSeq(expected_tboolseq).endValue == True assert TBoolSeq(expected_tboolseq).getTime == PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]}') assert TBoolSeq(expected_tboolseq).duration == timedelta(2) assert TBoolSeq(expected_tboolseq).timespan == timedelta(2) assert TBoolSeq(expected_tboolseq).period == Period( '[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]') assert TBoolSeq(expected_tboolseq).numInstants == 3 assert TBoolSeq(expected_tboolseq).startInstant == TBoolInst( 'true@2019-09-01 00:00:00+01') assert TBoolSeq(expected_tboolseq).endInstant == TBoolInst( 'true@2019-09-03 00:00:00+01') assert TBoolSeq(expected_tboolseq).instantN(2) == TBoolInst( 'false@2019-09-02 00:00:00+01') assert TBoolSeq(expected_tboolseq).instants == \ [TBoolInst('true@2019-09-01 00:00:00+01'), TBoolInst('false@2019-09-02 00:00:00+01'), TBoolInst('true@2019-09-03 00:00:00+01')] assert TBoolSeq(expected_tboolseq).numTimestamps == 3 assert TBoolSeq(expected_tboolseq).startTimestamp == parse( '2019-09-01 00:00:00+01') assert TBoolSeq(expected_tboolseq).endTimestamp == parse( '2019-09-03 00:00:00+01') assert TBoolSeq(expected_tboolseq).timestampN(2) == parse( '2019-09-02 00:00:00+01') assert TBoolSeq(expected_tboolseq).timestamps == [ parse('2019-09-01 00:00:00+01'), parse('2019-09-02 00:00:00+01'), parse('2019-09-03 00:00:00+01') ] assert TBoolSeq(expected_tboolseq).intersectsTimestamp( parse('2019-09-01 00:00:00+01')) == True assert TBoolSeq(expected_tboolseq).intersectsTimestamp( parse('2019-09-04 00:00:00+01')) == False assert TBoolSeq(expected_tboolseq).intersectsTimestampSet( TimestampSet( '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True assert TBoolSeq(expected_tboolseq).intersectsTimestampSet( TimestampSet( '{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False assert TBoolSeq(expected_tboolseq).intersectsPeriod( Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True assert TBoolSeq(expected_tboolseq).intersectsPeriod( Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False assert TBoolSeq(expected_tboolseq).intersectsPeriodSet( PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TBoolSeq(expected_tboolseq).intersectsPeriodSet( PeriodSet( '{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
def test_tbooli_accessors(cursor, expected_tbooli): assert TBoolI(expected_tbooli).duration() == 'InstantSet' assert TBoolI(expected_tbooli).getValues == [True, False] assert TBoolI(expected_tbooli).startValue == True assert TBoolI(expected_tbooli).endValue == True assert TBoolI(expected_tbooli).getTime == \ PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01], [2019-09-02 00:00:00+01, 2019-09-02 00:00:00+01], ' '[2019-09-03 00:00:00+01, 2019-09-03 00:00:00+01]}') assert TBoolI(expected_tbooli).timespan == timedelta(0) assert TBoolI(expected_tbooli).period == Period('[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]') assert TBoolI(expected_tbooli).numInstants == 3 assert TBoolI(expected_tbooli).startInstant == TBoolInst('true@2019-09-01 00:00:00+01') assert TBoolI(expected_tbooli).endInstant == TBoolInst('true@2019-09-03 00:00:00+01') assert TBoolI(expected_tbooli).instantN(2) == TBoolInst('false@2019-09-02 00:00:00+01') assert TBoolI(expected_tbooli).instants == [TBoolInst('true@2019-09-01 00:00:00+01'), TBoolInst('false@2019-09-02 00:00:00+01'), TBoolInst('true@2019-09-03 00:00:00+01')] assert TBoolI(expected_tbooli).numTimestamps == 3 assert TBoolI(expected_tbooli).startTimestamp == parse('2019-09-01 00:00:00+01') assert TBoolI(expected_tbooli).endTimestamp == parse('2019-09-03 00:00:00+01') assert TBoolI(expected_tbooli).timestampN(2) == parse('2019-09-02 00:00:00+01') assert TBoolI(expected_tbooli).timestamps == [parse('2019-09-01 00:00:00+01'), parse('2019-09-02 00:00:00+01'), parse('2019-09-03 00:00:00+01')] assert TBoolI(expected_tbooli).intersectsTimestamp(parse('2019-09-01 00:00:00+01')) == True assert TBoolI(expected_tbooli).intersectsTimestamp(parse('2019-09-04 00:00:00+01')) == False assert TBoolI(expected_tbooli).intersectsTimestampset( TimestampSet('{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True assert TBoolI(expected_tbooli).intersectsTimestampset( TimestampSet('{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False assert TBoolI(expected_tbooli).intersectsPeriod(Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True assert TBoolI(expected_tbooli).intersectsPeriod(Period('(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01)')) == False assert TBoolI(expected_tbooli).intersectsPeriod(Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False assert TBoolI(expected_tbooli).intersectsPeriodset( PeriodSet('{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TBoolI(expected_tbooli).intersectsPeriodset( PeriodSet('{(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01)}')) == False assert TBoolI(expected_tbooli).intersectsPeriodset( PeriodSet('{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
def test_tboolinst_accessors(cursor, expected_tboolinst): assert TBoolInst(expected_tboolinst).tempSubtype() == 'Instant' assert TBoolInst(expected_tboolinst).getValue == True assert TBoolInst(expected_tboolinst).getValues == [True] assert TBoolInst(expected_tboolinst).startValue == True assert TBoolInst(expected_tboolinst).endValue == True assert TBoolInst(expected_tboolinst).getTimestamp == parse( '2019-09-01 00:00:00+01') assert TBoolInst(expected_tboolinst).getTime == PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01]}') assert TBoolInst(expected_tboolinst).duration == timedelta(0) assert TBoolInst(expected_tboolinst).timespan == timedelta(0) assert TBoolInst(expected_tboolinst).period == Period( '[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01]') assert TBoolInst(expected_tboolinst).numInstants == 1 assert TBoolInst(expected_tboolinst).startInstant == TBoolInst( 'true@2019-09-01 00:00:00+01') assert TBoolInst(expected_tboolinst).endInstant == TBoolInst( 'true@2019-09-01 00:00:00+01') assert TBoolInst(expected_tboolinst).instantN(1) == TBoolInst( 'true@2019-09-01 00:00:00+01') assert TBoolInst(expected_tboolinst).instants == [ TBoolInst('true@2019-09-01 00:00:00+01') ] assert TBoolInst(expected_tboolinst).numTimestamps == 1 assert TBoolInst(expected_tboolinst).startTimestamp == parse( '2019-09-01 00:00:00+01') assert TBoolInst(expected_tboolinst).endTimestamp == parse( '2019-09-01 00:00:00+01') assert TBoolInst(expected_tboolinst).timestampN(1) == parse( '2019-09-01 00:00:00+01') assert TBoolInst(expected_tboolinst).timestamps == [ parse('2019-09-01 00:00:00+01') ] assert TBoolInst(expected_tboolinst).intersectsTimestamp( parse('2019-09-01 00:00:00+01')) == True assert TBoolInst(expected_tboolinst).intersectsTimestamp( parse('2019-09-02 00:00:00+01')) == False assert TBoolInst(expected_tboolinst).intersectsTimestampSet( TimestampSet( '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True assert TBoolInst(expected_tboolinst).intersectsTimestampSet( TimestampSet( '{2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01}')) == False assert TBoolInst(expected_tboolinst).intersectsPeriod( Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True assert TBoolInst(expected_tboolinst).intersectsPeriod( Period('(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == False assert TBoolInst(expected_tboolinst).intersectsPeriod( Period('[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]')) == False assert TBoolInst(expected_tboolinst).intersectsPeriodSet( PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TBoolInst(expected_tboolinst).intersectsPeriodSet( PeriodSet( '{(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == False assert TBoolInst(expected_tboolinst).intersectsPeriodSet( PeriodSet( '{[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]}')) == False
def test_tboolinst_constructors(cursor, expected_tboolinst): params = [TBoolInst(expected_tboolinst)] cursor.execute('INSERT INTO tbl_tboolinst (temp) VALUES (%s)', params) cursor.execute('SELECT temp FROM tbl_tboolinst WHERE temp=%s', params) result = cursor.fetchone()[0] assert result == TBoolInst(expected_tboolinst)
assert TBoolInst(expected_tboolinst).intersectsPeriodSet( PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TBoolInst(expected_tboolinst).intersectsPeriodSet( PeriodSet( '{(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == False assert TBoolInst(expected_tboolinst).intersectsPeriodSet( PeriodSet( '{[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]}')) == False @pytest.mark.parametrize('expected_tboolinstset', [ '{true@2019-09-01 00:00:00+01, false@2019-09-02 00:00:00+01, true@2019-09-03 00:00:00+01}', ('true@2019-09-01 00:00:00+01', 'false@2019-09-02 00:00:00+01', 'true@2019-09-03 00:00:00+01'), (TBoolInst('true@2019-09-01 00:00:00+01'), TBoolInst('false@2019-09-02 00:00:00+01'), TBoolInst('true@2019-09-03 00:00:00+01')), [ 'true@2019-09-01 00:00:00+01', 'false@2019-09-02 00:00:00+01', 'true@2019-09-03 00:00:00+01' ], [ TBoolInst('true@2019-09-01 00:00:00+01'), TBoolInst('false@2019-09-02 00:00:00+01'), TBoolInst('true@2019-09-03 00:00:00+01') ], ]) def test_tboolinstset_constructor(cursor, expected_tboolinstset): if isinstance(expected_tboolinstset, tuple): params = [TBoolInstSet(*expected_tboolinstset)]
from datetime import datetime, timedelta from dateutil.parser import parse from mobilitydb.time import TimestampSet, Period, PeriodSet from mobilitydb.main import TBoolInst, TBoolInstSet, TBoolSeq, TBoolSeqSet print("\nConstructors for TBoolInst") inst = TBoolInst('True@2019-09-08') print(inst) inst = TBoolInst('True', '2019-09-08') print(inst) t = parse('2019-09-08') inst = TBoolInst('True', t) print(inst) print("\nConstructors for TBoolInstSet") ti = TBoolInstSet('{True@2019-09-08, False@2019-09-09, False@2019-09-10}') print(tinstset) ti = TBoolInstSet('True@2019-09-08', 'False@2019-09-09', 'False@2019-09-10') print(tinstset) ti = TBoolInstSet(['True@2019-09-08', 'False@2019-09-09', 'False@2019-09-10']) print(tinstset) t1 = TBoolInst('True@2019-09-08') t2 = TBoolInst('False@2019-09-09') t3 = TBoolInst('False@2019-09-10') ti = TBoolInstSet(t1, t2, t3) print(tinstset) ti = TBoolInstSet([t1, t2, t3]) print(tinstset) print("\nConstructors for TBoolSeq") seq = TBoolSeq('[True@2019-09-08, False@2019-09-09, False@2019-09-10]')
Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True assert TBoolInst(expected_tboolinst).intersectsPeriod( Period('(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == False assert TBoolInst(expected_tboolinst).intersectsPeriod( Period('[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]')) == False assert TBoolInst(expected_tboolinst).intersectsPeriodset( PeriodSet('{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TBoolInst(expected_tboolinst).intersectsPeriodset( PeriodSet('{(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == False assert TBoolInst(expected_tboolinst).intersectsPeriodset( PeriodSet('{[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]}')) == False @pytest.mark.parametrize('expected_tbooli', [ '{true@2019-09-01 00:00:00+01, false@2019-09-02 00:00:00+01, true@2019-09-03 00:00:00+01}', ('true@2019-09-01 00:00:00+01', 'false@2019-09-02 00:00:00+01', 'true@2019-09-03 00:00:00+01'), (TBoolInst('true@2019-09-01 00:00:00+01'), TBoolInst('false@2019-09-02 00:00:00+01'), TBoolInst('true@2019-09-03 00:00:00+01')), ['true@2019-09-01 00:00:00+01', 'false@2019-09-02 00:00:00+01', 'true@2019-09-03 00:00:00+01'], [TBoolInst('true@2019-09-01 00:00:00+01'), TBoolInst('false@2019-09-02 00:00:00+01'), TBoolInst('true@2019-09-03 00:00:00+01')], ]) def test_tbooli_constructor(cursor, expected_tbooli): if isinstance(expected_tbooli, tuple): params = [TBoolI(*expected_tbooli)] else: params = [TBoolI(expected_tbooli)] cursor.execute('INSERT INTO tbl_tbooli (temp) VALUES (%s)', params) cursor.execute('SELECT temp FROM tbl_tbooli WHERE temp=%s', params) result = cursor.fetchone()[0] if isinstance(expected_tbooli, tuple): assert result == TBoolI(*expected_tbooli)