async def test_tfloatseq_constructor(connection, expected_tfloatseq): if isinstance(expected_tfloatseq, tuple): params = TFloatSeq(*expected_tfloatseq) else: params = TFloatSeq(expected_tfloatseq) await connection.execute('INSERT INTO tbl_tfloatseq (temp) VALUES ($1)', params) result = await connection.fetchval('SELECT temp FROM tbl_tfloatseq WHERE temp=$1', params) if isinstance(expected_tfloatseq, tuple): assert result == TFloatSeq(*expected_tfloatseq) else: assert result == TFloatSeq(expected_tfloatseq)
def test_tfloatseq_constructor(cursor, expected_tfloatseq): if isinstance(expected_tfloatseq, tuple): params = [TFloatSeq(*expected_tfloatseq)] else: params = [TFloatSeq(expected_tfloatseq)] cursor.execute('INSERT INTO tbl_tfloatseq (temp) VALUES (%s)', params) cursor.execute('SELECT temp FROM tbl_tfloatseq WHERE temp=%s', params) result = cursor.fetchone()[0] if isinstance(expected_tfloatseq, tuple): assert result == TFloatSeq(*expected_tfloatseq) else: assert result == TFloatSeq(expected_tfloatseq)
'{[10.0@2019-09-01 00:00:00+01], [20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]}', 'Interp=Stepwise;{[10.0@2019-09-01 00:00:00+01], [20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]}', [ '[10.0@2019-09-01 00:00:00+01]', '[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]' ], ([ '[10.0@2019-09-01 00:00:00+01]', '[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]' ], 'Linear'), ([ 'Interp=Stepwise;[10.0@2019-09-01 00:00:00+01]', 'Interp=Stepwise;[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]' ], 'Stepwise'), [ TFloatSeq('[10.0@2019-09-01 00:00:00+01]'), TFloatSeq('[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]') ], ([ TFloatSeq('[10.0@2019-09-01 00:00:00+01]'), TFloatSeq('[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]') ], 'Linear'), ([ TFloatSeq('Interp=Stepwise;[10.0@2019-09-01 00:00:00+01]'), TFloatSeq( 'Interp=Stepwise;[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]' ) ], 'Stepwise'), ]) async def test_tfloatseqset_constructor(connection, expected_tfloatseqset): if isinstance(expected_tfloatseqset, tuple):
params = TFloatSeq(expected_tfloatseq) await connection.execute('INSERT INTO tbl_tfloatseq (temp) VALUES ($1)', params) result = await connection.fetchval('SELECT temp FROM tbl_tfloatseq WHERE temp=$1', params) if isinstance(expected_tfloatseq, tuple): assert result == TFloatSeq(*expected_tfloatseq) else: assert result == TFloatSeq(expected_tfloatseq) @pytest.mark.parametrize('expected_tfloats', [ '{[10.0@2019-09-01 00:00:00+01], [20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]}', 'Interp=Stepwise;{[10.0@2019-09-01 00:00:00+01], [20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]}', ['[10.0@2019-09-01 00:00:00+01]', '[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]'], (['[10.0@2019-09-01 00:00:00+01]', '[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]'], 'Linear'), (['Interp=Stepwise;[10.0@2019-09-01 00:00:00+01]', 'Interp=Stepwise;[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]'], 'Stepwise'), [TFloatSeq('[10.0@2019-09-01 00:00:00+01]'), TFloatSeq('[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]')], ([TFloatSeq('[10.0@2019-09-01 00:00:00+01]'), TFloatSeq('[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]')], 'Linear'), ([TFloatSeq('Interp=Stepwise;[10.0@2019-09-01 00:00:00+01]'), TFloatSeq('Interp=Stepwise;[20.0@2019-09-02 00:00:00+01, 10.0@2019-09-03 00:00:00+01]')], 'Stepwise'), ]) async def test_tfloats_constructor(connection, expected_tfloats): if isinstance(expected_tfloats, tuple): params = TFloatS(*expected_tfloats) else: params = TFloatS(expected_tfloats) await connection.execute('INSERT INTO tbl_tfloats (temp) VALUES ($1)', params) result = await connection.fetchval('SELECT temp FROM tbl_tfloats WHERE temp=$1', params) if isinstance(expected_tfloats, tuple): assert result == TFloatS(*expected_tfloats)
def test_tfloats_accessors(cursor, expected_tfloats): assert TFloatS(expected_tfloats).duration() == 'SequenceSet' #assert TFloatS(expected_tfloats).getValues == [floatrange(10.0, 10.0, upper_inc=True),floatrange(20.0, 30.0, 30.0, upper_inc=True)] assert TFloatS(expected_tfloats).startValue == 10.0 assert TFloatS(expected_tfloats).endValue == 30.0 assert TFloatS(expected_tfloats).minValue == 10.0 assert TFloatS(expected_tfloats).maxValue == 30.0 assert TFloatS(expected_tfloats).valueRange == floatrange(10.0, 30.0, upper_inc=True) assert TFloatS(expected_tfloats).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-03 00:00:00+01]}' ) assert TFloatS(expected_tfloats).timespan == timedelta(1) assert TFloatS(expected_tfloats).period == Period( '[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]') assert TFloatS(expected_tfloats).numInstants == 3 assert TFloatS(expected_tfloats).startInstant == TFloatInst( '10.0@2019-09-01 00:00:00+01') assert TFloatS(expected_tfloats).endInstant == TFloatInst( '30.0@2019-09-03 00:00:00+01') assert TFloatS(expected_tfloats).instantN(2) == TFloatInst( '20.0@2019-09-02 00:00:00+01') assert TFloatS(expected_tfloats).instants == [ TFloatInst('10.0@2019-09-01 00:00:00+01'), TFloatInst('20.0@2019-09-02 00:00:00+01'), TFloatInst('30.0@2019-09-03 00:00:00+01') ] assert TFloatS(expected_tfloats).numTimestamps == 3 assert TFloatS(expected_tfloats).startTimestamp == parse( '2019-09-01 00:00:00+01') assert TFloatS(expected_tfloats).endTimestamp == parse( '2019-09-03 00:00:00+01') assert TFloatS(expected_tfloats).timestampN(2) == parse( '2019-09-02 00:00:00+01') assert TFloatS(expected_tfloats).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 TFloatS(expected_tfloats).numSequences == 2 assert TFloatS(expected_tfloats).startSequence == TFloatSeq( '[10.0@2019-09-01 00:00:00+01]') assert TFloatS(expected_tfloats).endSequence == TFloatSeq( '[20.0@2019-09-02 00:00:00+01, 30.0@2019-09-03 00:00:00+01]') assert TFloatS(expected_tfloats).sequenceN(2) == TFloatSeq( '[20.0@2019-09-02 00:00:00+01, 30.0@2019-09-03 00:00:00+01]') assert TFloatS(expected_tfloats).sequences == [ TFloatSeq('[10.0@2019-09-01 00:00:00+01]'), TFloatSeq('[20.0@2019-09-02 00:00:00+01, 30.0@2019-09-03 00:00:00+01]') ] assert TFloatS(expected_tfloats).intersectsTimestamp( parse('2019-09-01 00:00:00+01')) == True assert TFloatS(expected_tfloats).intersectsTimestamp( parse('2019-09-04 00:00:00+01')) == False assert TFloatS(expected_tfloats).intersectsTimestampset( TimestampSet( '{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True assert TFloatS(expected_tfloats).intersectsTimestampset( TimestampSet( '{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False assert TFloatS(expected_tfloats).intersectsPeriod( Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True assert TFloatS(expected_tfloats).intersectsPeriod( Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False assert TFloatS(expected_tfloats).intersectsPeriodset( PeriodSet( '{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TFloatS(expected_tfloats).intersectsPeriodset( PeriodSet( '{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
ti = TFloatI('{10@2019-09-08, 20@2019-09-09, 20@2019-09-10}') print(ti) ti = TFloatI('10@2019-09-08', '20@2019-09-09', '20@2019-09-10') print(ti) ti = TFloatI(['10@2019-09-08', '20@2019-09-09', '20@2019-09-10']) print(ti) t1 = TFloatInst('10@2019-09-08') t2 = TFloatInst('20@2019-09-09') t3 = TFloatInst('20@2019-09-10') ti = TFloatI(t1, t2, t3) print(ti) ti = TFloatI([t1, t2, t3]) print(ti) print("\nConstructors for TFloatSeq") seq = TFloatSeq('[10@2019-09-08, 20@2019-09-09, 20@2019-09-10]') print(seq) seq = TFloatSeq(['10@2019-09-08', '20@2019-09-09', '20@2019-09-10']) print(seq) seq = TFloatSeq([t1, t2, t3]) print(seq) seq = TFloatSeq([t1, t2, t3], False, True) print(seq) print("\nConstructors for TFloatS") ts = TFloatS( '{[10@2019-09-08, 20@2019-09-09, 20@2019-09-10],[15@2019-09-11, 30@2019-09-12]}' ) print(ts) ts = TFloatS([ '[10@2019-09-08, 20@2019-09-09, 20@2019-09-10]',