async def test_tintseq_constructor(connection, expected_tintseq): if isinstance(expected_tintseq, tuple): params = TIntSeq(*expected_tintseq) else: params = TIntSeq(expected_tintseq) await connection.execute('INSERT INTO tbl_tintseq (temp) VALUES ($1)', params) result = await connection.fetchval('SELECT temp FROM tbl_tintseq WHERE temp=$1', params) if isinstance(expected_tintseq, tuple): assert result == TIntSeq(*expected_tintseq) else: assert result == TIntSeq(expected_tintseq)
def test_tintseq_constructor(cursor, expected_tintseq): if isinstance(expected_tintseq, tuple): params = [TIntSeq(*expected_tintseq)] else: params = [TIntSeq(expected_tintseq)] cursor.execute('INSERT INTO tbl_tintseq (temp) VALUES (%s)', params) cursor.execute('SELECT temp FROM tbl_tintseq WHERE temp=%s', params) result = cursor.fetchone()[0] if isinstance(expected_tintseq, tuple): assert result == TIntSeq(*expected_tintseq) else: assert result == TIntSeq(expected_tintseq)
def test_tintseqset_accessors(cursor, expected_tintseqset): assert TIntSeqSet(expected_tintseqset).tempSubtype() == 'SequenceSet' assert TIntSeqSet(expected_tintseqset).getValues == [10, 20, 30] assert TIntSeqSet(expected_tintseqset).startValue == 10 assert TIntSeqSet(expected_tintseqset).endValue == 30 assert TIntSeqSet(expected_tintseqset).minValue == 10 assert TIntSeqSet(expected_tintseqset).maxValue == 30 assert TIntSeqSet(expected_tintseqset).valueRange == intrange(10, 30, upper_inc=True) assert TIntSeqSet(expected_tintseqset).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 TIntSeqSet(expected_tintseqset).duration == timedelta(1) assert TIntSeqSet(expected_tintseqset).timespan == timedelta(2) assert TIntSeqSet(expected_tintseqset).period == Period('[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]') assert TIntSeqSet(expected_tintseqset).numInstants == 3 assert TIntSeqSet(expected_tintseqset).startInstant == TIntInst('10@2019-09-01 00:00:00+01') assert TIntSeqSet(expected_tintseqset).endInstant == TIntInst('30@2019-09-03 00:00:00+01') assert TIntSeqSet(expected_tintseqset).instantN(2) == TIntInst('20@2019-09-02 00:00:00+01') assert TIntSeqSet(expected_tintseqset).instants == [TIntInst('10@2019-09-01 00:00:00+01'), TIntInst('20@2019-09-02 00:00:00+01'), TIntInst('30@2019-09-03 00:00:00+01')] assert TIntSeqSet(expected_tintseqset).numTimestamps == 3 assert TIntSeqSet(expected_tintseqset).startTimestamp == parse('2019-09-01 00:00:00+01') assert TIntSeqSet(expected_tintseqset).endTimestamp == parse('2019-09-03 00:00:00+01') assert TIntSeqSet(expected_tintseqset).timestampN(2) == parse('2019-09-02 00:00:00+01') assert TIntSeqSet(expected_tintseqset).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 TIntSeqSet(expected_tintseqset).numSequences == 2 assert TIntSeqSet(expected_tintseqset).startSequence == TIntSeq('[10@2019-09-01 00:00:00+01]') assert TIntSeqSet(expected_tintseqset).endSequence == TIntSeq( '[20@2019-09-02 00:00:00+01, 30@2019-09-03 00:00:00+01]') assert TIntSeqSet(expected_tintseqset).sequenceN(2) == TIntSeq( '[20@2019-09-02 00:00:00+01, 30@2019-09-03 00:00:00+01]') assert TIntSeqSet(expected_tintseqset).sequences == [TIntSeq('[10@2019-09-01 00:00:00+01]'), TIntSeq( '[20@2019-09-02 00:00:00+01, 30@2019-09-03 00:00:00+01]')] assert TIntSeqSet(expected_tintseqset).intersectsTimestamp(parse('2019-09-01 00:00:00+01')) == True assert TIntSeqSet(expected_tintseqset).intersectsTimestamp(parse('2019-09-04 00:00:00+01')) == False assert TIntSeqSet(expected_tintseqset).intersectsTimestampSet( TimestampSet('{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True assert TIntSeqSet(expected_tintseqset).intersectsTimestampSet( TimestampSet('{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False assert TIntSeqSet(expected_tintseqset).intersectsPeriod( Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True assert TIntSeqSet(expected_tintseqset).intersectsPeriod( Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False assert TIntSeqSet(expected_tintseqset).intersectsPeriodSet( PeriodSet('{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True assert TIntSeqSet(expected_tintseqset).intersectsPeriodSet( PeriodSet('{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
ti = TIntI('{10@2019-09-08, 20@2019-09-09, 20@2019-09-10}') print(ti) ti = TIntI('10@2019-09-08', '20@2019-09-09', '20@2019-09-10') print(ti) ti = TIntI(['10@2019-09-08', '20@2019-09-09', '20@2019-09-10']) print(ti) t1 = TIntInst('10@2019-09-08') t2 = TIntInst('20@2019-09-09') t3 = TIntInst('20@2019-09-10') ti = TIntI(t1, t2, t3) print(ti) ti = TIntI([t1, t2, t3]) print(ti) print("\nConstructors for TIntSeq") seq = TIntSeq('[10@2019-09-08, 20@2019-09-09, 20@2019-09-10]') print(seq) seq = TIntSeq(['10@2019-09-08', '20@2019-09-09', '20@2019-09-10']) print(seq) seq = TIntSeq([t1, t2, t3]) print(seq) seq = TIntSeq([t1, t2, t3], False, True) print(seq) print("\nConstructors for TIntS") ts = TIntS('{[10@2019-09-08, 20@2019-09-09, 20@2019-09-10],[15@2019-09-11, 30@2019-09-12]}') print(ts) ts = TIntS(['[10@2019-09-08, 20@2019-09-09, 20@2019-09-10]', '[15@2019-09-11, 30@2019-09-12]']) print(ts) seq1 = TIntSeq('[10@2019-09-08, 20@2019-09-09, 20@2019-09-10]') seq2 = TIntSeq('[15@2019-09-11, 30@2019-09-12]')
result = await connection.fetchval( 'SELECT temp FROM tbl_tintseq WHERE temp=$1', params) if isinstance(expected_tintseq, tuple): assert result == TIntSeq(*expected_tintseq) else: assert result == TIntSeq(expected_tintseq) @pytest.mark.parametrize('expected_tintseqset', [ '{[10@2019-09-01 00:00:00+01], [20@2019-09-02 00:00:00+01, 10@2019-09-03 00:00:00+01]}', [ '[10@2019-09-01 00:00:00+01]', '[20@2019-09-02 00:00:00+01, 10@2019-09-03 00:00:00+01]' ], [ TIntSeq('[10@2019-09-01 00:00:00+01]'), TIntSeq('[20@2019-09-02 00:00:00+01, 10@2019-09-03 00:00:00+01]') ], ]) async def test_tintseqset_constructor(connection, expected_tintseqset): if isinstance(expected_tintseqset, tuple): params = TIntSeqSet(*expected_tintseqset) else: params = TIntSeqSet(expected_tintseqset) await connection.execute('INSERT INTO tbl_tintseqset (temp) VALUES ($1)', params) result = await connection.fetchval( 'SELECT temp FROM tbl_tintseqset WHERE temp=$1', params) if isinstance(expected_tintseqset, tuple): assert result == TIntSeqSet(*expected_tintseqset) else: