async def test_ttextinst_constructors(connection, expected_ttextinst): params = TTextInst(expected_ttextinst) await connection.execute('INSERT INTO tbl_ttextinst (temp) VALUES ($1)', params) result = await connection.fetchval( 'SELECT temp FROM tbl_ttextinst WHERE temp=$1', params, column=0) assert result == TTextInst(expected_ttextinst)
def test_ttextseq_accessors(cursor, expected_ttextseqseteq): assert TTextSeq(expected_ttextseqseteq).tempSubtype() == 'Sequence' assert TTextSeq(expected_ttextseqseteq).getValues == ['AA', 'BB', 'CC'] assert TTextSeq(expected_ttextseqseteq).startValue == 'AA' assert TTextSeq(expected_ttextseqseteq).endValue == 'CC' assert TTextSeq(expected_ttextseqseteq).minValue == 'AA' assert TTextSeq(expected_ttextseqseteq).maxValue == 'CC' assert TTextSeq(expected_ttextseqseteq).getTime == PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]}') assert TTextSeq(expected_ttextseqseteq).duration == timedelta(2) assert TTextSeq(expected_ttextseqseteq).timespan == timedelta(2) assert TTextSeq(expected_ttextseqseteq).period == Period( '[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]') assert TTextSeq(expected_ttextseqseteq).numInstants == 3 assert TTextSeq(expected_ttextseqseteq).startInstant == TTextInst( 'AA@2019-09-01 00:00:00+01') assert TTextSeq(expected_ttextseqseteq).endInstant == TTextInst( 'CC@2019-09-03 00:00:00+01') assert TTextSeq(expected_ttextseqseteq).instantN(2) == TTextInst( 'BB@2019-09-02 00:00:00+01') assert TTextSeq(expected_ttextseqseteq).instants == \ [TTextInst('AA@2019-09-01 00:00:00+01'), TTextInst('BB@2019-09-02 00:00:00+01'), TTextInst('CC@2019-09-03 00:00:00+01')] assert TTextSeq(expected_ttextseqseteq).numTimestamps == 3 assert TTextSeq(expected_ttextseqseteq).startTimestamp == parse( '2019-09-01 00:00:00+01') assert TTextSeq(expected_ttextseqseteq).endTimestamp == parse( '2019-09-03 00:00:00+01') assert TTextSeq(expected_ttextseqseteq).timestampN(2) == parse( '2019-09-02 00:00:00+01') assert TTextSeq(expected_ttextseqseteq).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 TTextSeq(expected_ttextseqseteq).intersectsTimestamp( parse('2019-09-01 00:00:00+01')) == True assert TTextSeq(expected_ttextseqseteq).intersectsTimestamp( parse('2019-09-04 00:00:00+01')) == False assert TTextSeq(expected_ttextseqseteq).intersectsTimestampSet( TimestampSet( '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True assert TTextSeq(expected_ttextseqseteq).intersectsTimestampSet( TimestampSet( '{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False assert TTextSeq(expected_ttextseqseteq).intersectsPeriod( Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True assert TTextSeq(expected_ttextseqseteq).intersectsPeriod( Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False assert TTextSeq(expected_ttextseqseteq).intersectsPeriodSet( PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TTextSeq(expected_ttextseqseteq).intersectsPeriodSet( PeriodSet( '{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
from datetime import datetime, timedelta from dateutil.parser import parse from mobilitydb.time import TimestampSet, Period, PeriodSet from mobilitydb.main import TTextInst, TTextI, TTextSeq, TTextS print("\nConstructors for TTextInst") inst = TTextInst('A@2019-09-08') print(inst) inst = TTextInst('A', '2019-09-08') print(inst) t = parse('2019-09-08') inst = TTextInst('A', t) print(inst) print("\nConstructors for TText") ti = TTextI('{A@2019-09-08, B@2019-09-09, B@2019-09-10}') print(ti) ti = TTextI('A@2019-09-08', 'B@2019-09-09', 'B@2019-09-10') print(ti) ti = TTextI(['A@2019-09-08', 'B@2019-09-09', 'B@2019-09-10']) print(ti) t1 = TTextInst('A@2019-09-08') t2 = TTextInst('B@2019-09-09') t3 = TTextInst('B@2019-09-10') ti = TTextI(t1, t2, t3) print(ti) ti = TTextI([t1, t2, t3]) print(ti) print("\nConstructors for TTextSeq") seq = TTextSeq('[A@2019-09-08, B@2019-09-09, B@2019-09-10]')
'AA@2019-09-01 00:00:00+01', ('AA', '2019-09-08 00:00:00+01'), ['AA', '2019-09-08 00:00:00+01'], ('AA', parse('2019-09-08 00:00:00+01')), ['AA', parse('2019-09-08 00:00:00+01')], ]) async def test_ttextinst_constructors(connection, expected_ttextinst): params = TTextInst(expected_ttextinst) await connection.execute('INSERT INTO tbl_ttextinst (temp) VALUES ($1)', params) result = await connection.fetchval('SELECT temp FROM tbl_ttextinst WHERE temp=$1', params, column=0) assert result == TTextInst(expected_ttextinst) @pytest.mark.parametrize('expected_ttextinstset', [ '{AA@2019-09-01 00:00:00+01, BB@2019-09-02 00:00:00+01, AA@2019-09-03 00:00:00+01}', ('AA@2019-09-01 00:00:00+01', 'BB@2019-09-02 00:00:00+01', 'AA@2019-09-03 00:00:00+01'), (TTextInst('AA@2019-09-01 00:00:00+01'), TTextInst('BB@2019-09-02 00:00:00+01'), TTextInst('AA@2019-09-03 00:00:00+01')), ['AA@2019-09-01 00:00:00+01', 'BB@2019-09-02 00:00:00+01', 'AA@2019-09-03 00:00:00+01'], [TTextInst('AA@2019-09-01 00:00:00+01'), TTextInst('BB@2019-09-02 00:00:00+01'), TTextInst('AA@2019-09-03 00:00:00+01')], ]) async def test_ttextinstset_constructor(connection, expected_ttextinstset): if isinstance(expected_ttextinstset, tuple): params = TTextInstSet(*expected_ttextinstset) else: params = TTextInstSet(expected_ttextinstset) await connection.execute('INSERT INTO tbl_ttextinstset (temp) VALUES ($1)', params) result = await connection.fetchval('SELECT temp FROM tbl_ttextinstset WHERE temp=$1', params) if isinstance(expected_ttextinstset, tuple): assert result == TTextInstSet(*expected_ttextinstset) else:
def test_ttextinst_accessors(cursor, expected_ttextinst): assert TTextInst(expected_ttextinst).duration() == 'Instant' assert TTextInst(expected_ttextinst).getValue == 'AA' assert TTextInst(expected_ttextinst).getValues == ['AA'] assert TTextInst(expected_ttextinst).startValue == 'AA' assert TTextInst(expected_ttextinst).endValue == 'AA' assert TTextInst(expected_ttextinst).minValue == 'AA' assert TTextInst(expected_ttextinst).maxValue == 'AA' assert TTextInst(expected_ttextinst).getTimestamp == parse( '2019-09-01 00:00:00+01') assert TTextInst(expected_ttextinst).getTime == PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01]}') assert TTextInst(expected_ttextinst).timespan == timedelta(0) assert TTextInst(expected_ttextinst).period == Period( '[2019-09-01 00:00:00+01, 2019-09-01 00:00:00+01]') assert TTextInst(expected_ttextinst).numInstants == 1 assert TTextInst(expected_ttextinst).startInstant == TTextInst( 'AA@2019-09-01 00:00:00+01') assert TTextInst(expected_ttextinst).endInstant == TTextInst( 'AA@2019-09-01 00:00:00+01') assert TTextInst(expected_ttextinst).instantN(1) == TTextInst( 'AA@2019-09-01 00:00:00+01') assert TTextInst(expected_ttextinst).instants == [ TTextInst('AA@2019-09-01 00:00:00+01') ] assert TTextInst(expected_ttextinst).numTimestamps == 1 assert TTextInst(expected_ttextinst).startTimestamp == parse( '2019-09-01 00:00:00+01') assert TTextInst(expected_ttextinst).endTimestamp == parse( '2019-09-01 00:00:00+01') assert TTextInst(expected_ttextinst).timestampN(1) == parse( '2019-09-01 00:00:00+01') assert TTextInst(expected_ttextinst).timestamps == [ parse('2019-09-01 00:00:00+01') ] assert TTextInst(expected_ttextinst).intersectsTimestamp( parse('2019-09-01 00:00:00+01')) == True assert TTextInst(expected_ttextinst).intersectsTimestamp( parse('2019-09-02 00:00:00+01')) == False assert TTextInst(expected_ttextinst).intersectsTimestampset( TimestampSet( '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True assert TTextInst(expected_ttextinst).intersectsTimestampset( TimestampSet( '{2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01}')) == False assert TTextInst(expected_ttextinst).intersectsPeriod( Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True assert TTextInst(expected_ttextinst).intersectsPeriod( Period('(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == False assert TTextInst(expected_ttextinst).intersectsPeriod( Period('[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]')) == False assert TTextInst(expected_ttextinst).intersectsPeriodset( PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TTextInst(expected_ttextinst).intersectsPeriodset( PeriodSet( '{(2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == False assert TTextInst(expected_ttextinst).intersectsPeriodset( PeriodSet( '{[2019-09-02 00:00:00+01, 2019-09-03 00:00:00+01]}')) == False
def test_ttextinst_constructors(cursor, expected_ttextinst): params = [TTextInst(expected_ttextinst)] cursor.execute('INSERT INTO tbl_ttextinst (temp) VALUES (%s)', params) cursor.execute('SELECT temp FROM tbl_ttextinst WHERE temp=%s', params) result = cursor.fetchone()[0] assert result == TTextInst(expected_ttextinst)