Ejemplo n.º 1
0
async def test_tboolseq_constructor(connection, expected_tboolseq):
    if isinstance(expected_tboolseq, tuple):
        params = TBoolSeq(*expected_tboolseq)
    else:
        params = TBoolSeq(expected_tboolseq)
    await connection.execute('INSERT INTO tbl_tboolseq (temp) VALUES ($1)', params)
    result = await connection.fetchval('SELECT temp FROM tbl_tboolseq WHERE temp=$1', params)
    if isinstance(expected_tboolseq, tuple):
        assert result == TBoolSeq(*expected_tboolseq)
    else:
        assert result == TBoolSeq(expected_tboolseq)
Ejemplo n.º 2
0
def test_tboolseq_constructor(cursor, expected_tboolseq):
    if isinstance(expected_tboolseq, tuple):
        params = [TBoolSeq(*expected_tboolseq)]
    else:
        params = [TBoolSeq(expected_tboolseq)]
    cursor.execute('INSERT INTO tbl_tboolseq (temp) VALUES (%s)', params)
    cursor.execute('SELECT temp FROM tbl_tboolseq WHERE temp=%s', params)
    result = cursor.fetchone()[0]
    if isinstance(expected_tboolseq, tuple):
        assert result == TBoolSeq(*expected_tboolseq)
    else:
        assert result == TBoolSeq(expected_tboolseq)
Ejemplo n.º 3
0
def test_tbools_accessors(cursor, expected_tbools):
    assert TBoolS(expected_tbools).duration() == 'SequenceSet'
    assert TBoolS(expected_tbools).getValues == [True, False]
    assert TBoolS(expected_tbools).startValue == True
    assert TBoolS(expected_tbools).endValue == True
    assert TBoolS(expected_tbools).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 TBoolS(expected_tbools).timespan == timedelta(1)
    assert TBoolS(expected_tbools).period == Period('[2019-09-01 00:00:00+01, 2019-09-03 00:00:00+01]')
    assert TBoolS(expected_tbools).numInstants == 3
    assert TBoolS(expected_tbools).startInstant == TBoolInst('true@2019-09-01 00:00:00+01')
    assert TBoolS(expected_tbools).endInstant == TBoolInst('true@2019-09-03 00:00:00+01')
    assert TBoolS(expected_tbools).instantN(2) == TBoolInst('false@2019-09-02 00:00:00+01')
    assert TBoolS(expected_tbools).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 TBoolS(expected_tbools).numTimestamps == 3
    assert TBoolS(expected_tbools).startTimestamp == parse('2019-09-01 00:00:00+01')
    assert TBoolS(expected_tbools).endTimestamp == parse('2019-09-03 00:00:00+01')
    assert TBoolS(expected_tbools).timestampN(2) == parse('2019-09-02 00:00:00+01')
    assert TBoolS(expected_tbools).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 TBoolS(expected_tbools).numSequences == 2
    assert TBoolS(expected_tbools).startSequence == TBoolSeq('[true@2019-09-01 00:00:00+01]')
    assert TBoolS(expected_tbools).endSequence == TBoolSeq(
        '[false@2019-09-02 00:00:00+01, true@2019-09-03 00:00:00+01]')
    assert TBoolS(expected_tbools).sequenceN(2) == TBoolSeq(
        '[false@2019-09-02 00:00:00+01, true@2019-09-03 00:00:00+01]')
    assert TBoolS(expected_tbools).sequences == [TBoolSeq('[true@2019-09-01 00:00:00+01]'),
                                                 TBoolSeq(
                                                     '[false@2019-09-02 00:00:00+01, true@2019-09-03 00:00:00+01]')]
    assert TBoolS(expected_tbools).intersectsTimestamp(parse('2019-09-01 00:00:00+01')) == True
    assert TBoolS(expected_tbools).intersectsTimestamp(parse('2019-09-04 00:00:00+01')) == False
    assert TBoolS(expected_tbools).intersectsTimestampset(
        TimestampSet('{2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01}')) == True
    assert TBoolS(expected_tbools).intersectsTimestampset(
        TimestampSet('{2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01}')) == False
    assert TBoolS(expected_tbools).intersectsPeriod(
        Period('[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]')) == True
    assert TBoolS(expected_tbools).intersectsPeriod(
        Period('[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]')) == False
    assert TBoolS(expected_tbools).intersectsPeriodset(
        PeriodSet('{[2019-09-01 00:00:00+01, 2019-09-02 00:00:00+01]}')) == True
    assert TBoolS(expected_tbools).intersectsPeriodset(
        PeriodSet('{[2019-09-04 00:00:00+01, 2019-09-05 00:00:00+01]}')) == False
Ejemplo n.º 4
0
        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


@pytest.mark.parametrize('expected_tboolseqset', [
    '{[true@2019-09-01 00:00:00+01], [false@2019-09-02 00:00:00+01, true@2019-09-03 00:00:00+01]}',
    'Interp=Stepwise;{[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]'
    ],
    [
        TBoolSeq('[true@2019-09-01 00:00:00+01]'),
        TBoolSeq('[false@2019-09-02 00:00:00+01, true@2019-09-03 00:00:00+01]')
    ],
])
def test_tboolseqset_constructor(cursor, expected_tboolseqset):
    if isinstance(expected_tboolseqset, tuple):
        params = [TBoolSeqSet(*expected_tboolseqset)]
    else:
        params = [TBoolSeqSet(expected_tboolseqset)]
    cursor.execute('INSERT INTO tbl_tboolseqset (temp) VALUES (%s)', params)
    cursor.execute('SELECT temp FROM tbl_tboolseqset WHERE temp=%s', params)
    result = cursor.fetchone()[0]
    if isinstance(expected_tboolseqset, tuple):
        assert result == TBoolSeqSet(*expected_tboolseqset)
    else:
        assert result == TBoolSeqSet(expected_tboolseqset)
Ejemplo n.º 5
0
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]')
print(seq)
seq = TBoolSeq(['True@2019-09-08', 'False@2019-09-09', 'False@2019-09-10'])
print(seq)
seq = TBoolSeq([t1, t2, t3])
print(seq)
seq = TBoolSeq([t1, t2, t3], False, True)
print(seq)

print("\nConstructors for TBoolSeqSet")
ts = TBoolSeqSet(
    '{[True@2019-09-08, False@2019-09-09, False@2019-09-10],[False@2019-09-11, True@2019-09-12]}'
)
print(ts)
ts = TBoolSeqSet([
    '[True@2019-09-08, False@2019-09-09, False@2019-09-10]',