Exemple #1
0
async def test_ttextseq_constructor(connection, expected_ttextseq):
    if isinstance(expected_ttextseq, tuple):
        params = TTextSeq(*expected_ttextseq)
    else:
        params = TTextSeq(expected_ttextseq)
    await connection.execute('INSERT INTO tbl_ttextseq (temp) VALUES ($1)', params)
    result = await connection.fetchval('SELECT temp FROM tbl_ttextseq WHERE temp=$1', params)
    if isinstance(expected_ttextseq, tuple):
        assert result == TTextSeq(*expected_ttextseq)
    else:
        assert result == TTextSeq(expected_ttextseq)
Exemple #2
0
def test_ttextseq_constructor(cursor, expected_ttextseq):
    if isinstance(expected_ttextseq, tuple):
        params = [TTextSeq(*expected_ttextseq)]
    else:
        params = [TTextSeq(expected_ttextseq)]
    cursor.execute('INSERT INTO tbl_ttextseq (temp) VALUES (%s)', params)
    cursor.execute('SELECT temp FROM tbl_ttextseq WHERE temp=%s', params)
    result = cursor.fetchone()[0]
    if isinstance(expected_ttextseq, tuple):
        assert result == TTextSeq(*expected_ttextseq)
    else:
        assert result == TTextSeq(expected_ttextseq)
Exemple #3
0
def test_ttextseqset_accessors(cursor, expected_ttextseqset):
    assert TTextSeqSet(expected_ttextseqset).tempSubtype() == 'SequenceSet'
    assert TTextSeqSet(expected_ttextseqset).getValues == ['AA', 'BB', 'CC']
    assert TTextSeqSet(expected_ttextseqset).startValue == 'AA'
    assert TTextSeqSet(expected_ttextseqset).endValue == 'CC'
    assert TTextSeqSet(expected_ttextseqset).minValue == 'AA'
    assert TTextSeqSet(expected_ttextseqset).maxValue == 'CC'
    assert TTextSeqSet(expected_ttextseqset).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 TTextSeqSet(expected_ttextseqset).duration == timedelta(1)
    assert TTextSeqSet(expected_ttextseqset).timespan == timedelta(2)
    assert TTextSeqSet(expected_ttextseqset).period == Period('[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]')
    assert TTextSeqSet(expected_ttextseqset).numInstants == 3
    assert TTextSeqSet(expected_ttextseqset).startInstant == TTextInst('AA@2019-09-01 00:00:00+01')
    assert TTextSeqSet(expected_ttextseqset).endInstant == TTextInst('CC@2019-09-03 00:00:00+01')
    assert TTextSeqSet(expected_ttextseqset).instantN(2) == TTextInst('BB@2019-09-02 00:00:00+01')
    assert TTextSeqSet(expected_ttextseqset).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 TTextSeqSet(expected_ttextseqset).numTimestamps == 3
    assert TTextSeqSet(expected_ttextseqset).startTimestamp == parse('2019-09-01 00:00:00+01')
    assert TTextSeqSet(expected_ttextseqset).endTimestamp == parse('2019-09-03 00:00:00+01')
    assert TTextSeqSet(expected_ttextseqset).timestampN(2) == parse('2019-09-02 00:00:00+01')
    assert TTextSeqSet(expected_ttextseqset).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 TTextSeqSet(expected_ttextseqset).numSequences == 2
    assert TTextSeqSet(expected_ttextseqset).startSequence == TTextSeq('[AA@2019-09-01 00:00:00+01]')
    assert TTextSeqSet(expected_ttextseqset).endSequence == TTextSeq(
        '[BB@2019-09-02 00:00:00+01, CC@2019-09-03 00:00:00+01]')
    assert TTextSeqSet(expected_ttextseqset).sequenceN(2) == TTextSeq(
        '[BB@2019-09-02 00:00:00+01, CC@2019-09-03 00:00:00+01]')
    assert TTextSeqSet(expected_ttextseqset).sequences == [TTextSeq('[AA@2019-09-01 00:00:00+01]'),
                                                 TTextSeq(
                                                     '[BB@2019-09-02 00:00:00+01, CC@2019-09-03 00:00:00+01]')]
    assert TTextSeqSet(expected_ttextseqset).intersectsTimestamp(parse('2019-09-01 00:00:00+01')) == True
    assert TTextSeqSet(expected_ttextseqset).intersectsTimestamp(parse('2019-09-04 00:00:00+01')) == False
    assert TTextSeqSet(expected_ttextseqset).intersectsTimestampSet(
        TimestampSet('{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True
    assert TTextSeqSet(expected_ttextseqset).intersectsTimestampSet(
        TimestampSet('{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False
    assert TTextSeqSet(expected_ttextseqset).intersectsPeriod(
        Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True
    assert TTextSeqSet(expected_ttextseqset).intersectsPeriod(
        Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False
    assert TTextSeqSet(expected_ttextseqset).intersectsPeriodSet(
        PeriodSet('{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True
    assert TTextSeqSet(expected_ttextseqset).intersectsPeriodSet(
        PeriodSet('{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
Exemple #4
0
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]')
print(seq)
seq = TTextSeq(['A@2019-09-08', 'B@2019-09-09', 'B@2019-09-10'])
print(seq)
seq = TTextSeq([t1, t2, t3])
print(seq)
seq = TTextSeq([t1, t2, t3], False, True)
print(seq)

print("\nConstructors for TTextS")
ts = TTextS(
    '{[A@2019-09-08, B@2019-09-09, B@2019-09-10],[B@2019-09-11, C@2019-09-12]}'
)
print(ts)
ts = TTextS([
    '[A@2019-09-08, B@2019-09-09, B@2019-09-10]',
Exemple #5
0
])
async def test_ttextseq_constructor(connection, expected_ttextseq):
    if isinstance(expected_ttextseq, tuple):
        params = TTextSeq(*expected_ttextseq)
    else:
        params = TTextSeq(expected_ttextseq)
    await connection.execute('INSERT INTO tbl_ttextseq (temp) VALUES ($1)', params)
    result = await connection.fetchval('SELECT temp FROM tbl_ttextseq WHERE temp=$1', params)
    if isinstance(expected_ttextseq, tuple):
        assert result == TTextSeq(*expected_ttextseq)
    else:
        assert result == TTextSeq(expected_ttextseq)

@pytest.mark.parametrize('expected_ttextseqset', [
    '{[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]'],
    [TTextSeq('[AA@2019-09-01 00:00:00+01]'),
     TTextSeq('[BB@2019-09-02 00:00:00+01, AA@2019-09-03 00:00:00+01]')],
])
async def test_ttextseqset_constructor(connection, expected_ttextseqset):
    if isinstance(expected_ttextseqset, tuple):
        params = TTextSeqSet(*expected_ttextseqset)
    else:
        params = TTextSeqSet(expected_ttextseqset)
    await connection.execute('INSERT INTO tbl_ttextseqset (temp) VALUES ($1)', params)
    result = await connection.fetchval('SELECT temp FROM tbl_ttextseqset WHERE temp=$1', params)
    if isinstance(expected_ttextseqset, tuple):
        assert result == TTextSeqSet(*expected_ttextseqset)
    else:
        assert result == TTextSeqSet(expected_ttextseqset)