Exemplo n.º 1
0
def test_timedelta(engine, tsh):
    e1 = '(timedelta (date "2020-1-1"))'  # null
    e2 = '(timedelta (date "2020-1-1") #:years 1)'
    e3 = '(timedelta (date "2020-1-1") #:months 1) '
    e4 = '(timedelta (date "2020-1-1") #:weeks 1)'
    e5 = '(timedelta (date "2020-1-1") #:days 1)'
    e6 = '(timedelta (date "2020-1-1") #:hours 1)'
    e7 = '(timedelta (date "2020-1-1") #:minutes 1)'

    i = Interpreter(engine, tsh, {})
    a = lisp.evaluate(e1, i.env)
    b = lisp.evaluate(e2, i.env)
    c = lisp.evaluate(e3, i.env)
    d = lisp.evaluate(e4, i.env)
    e = lisp.evaluate(e5, i.env)
    f = lisp.evaluate(e6, i.env)
    g = lisp.evaluate(e7, i.env)

    assert a == pd.Timestamp('2020-01-01 00:00:00+0000', tz='UTC')
    assert b == pd.Timestamp('2021-01-01 00:00:00+0000', tz='UTC')
    assert c == pd.Timestamp('2020-02-01 00:00:00+0000', tz='UTC')
    assert d == pd.Timestamp('2020-01-08 00:00:00+0000', tz='UTC')
    assert e == pd.Timestamp('2020-01-02 00:00:00+0000', tz='UTC')
    assert f == pd.Timestamp('2020-01-01 01:00:00+0000', tz='UTC')
    assert g == pd.Timestamp('2020-01-01 00:01:00+0000', tz='UTC')
Exemplo n.º 2
0
def test_date(engine, tsh):
    e1 = '(date "2018-1-1")'
    e2 = '(date "2018-1-1" #:naive #t)'
    e3 = '(date "2018-1-1 12:00:00" #:naive #t #:tz "Europe/Moscow")'
    e4 = '(date "2018-1-1" #:naive #f)'
    e5 = '(date "2018-1-1 12:00:00" #:naive #f #:tz "Europe/Moscow")'
    e6 = '(date "2020-1-1 06:42:30")'
    e7 = '(date "2020-1-1" #:tz "Gondwana/Chandrapore")'

    i = Interpreter(engine, tsh, {})
    a = lisp.evaluate(e1, i.env)
    b = lisp.evaluate(e2, i.env)
    with pytest.raises(AssertionError) as err:
        lisp.evaluate(e3, i.env)
    assert err.value.args[0] == 'date cannot be naive and have a tz'
    d = lisp.evaluate(e4, i.env)
    e = lisp.evaluate(e5, i.env)
    f = lisp.evaluate(e6, i.env)
    with pytest.raises(pytz.UnknownTimeZoneError) as err:
        lisp.evaluate(e7, i.env)
    assert err.value.args[0] == 'Gondwana/Chandrapore'

    assert a == pd.Timestamp('2018-01-01 00:00:00+0000', tz='UTC')
    assert b == pd.Timestamp('2018-01-01 00:00:00')
    assert d == pd.Timestamp('2018-01-01 00:00:00+0000', tz='UTC')
    assert e == pd.Timestamp('2018-01-01 12:00:00+0300', tz='Europe/Moscow')
    assert f == pd.Timestamp('2020-01-01 06:42:30+0000', tz='UTC')
Exemplo n.º 3
0
def test_failing_kw(engine, tsh):
    expr = '(+ 1 (series "types-a" #:fill "ffill" #:prune "toto"))'
    i = Interpreter(engine, tsh, {})
    with pytest.raises(TypeError) as err:
        typecheck(lisp.parse(expr), i.env)

    assert err.value.args[0] == "keyword `prune` = 'toto' not of typing.Union[int, NoneType]"
Exemplo n.º 4
0
def test_complex_typecheck(engine, tsh):
    expr = ('(add (series "types-a") '
            '     (priority (series "types-a") '
            '               (* 2 (series "types-b"))))'
    )

    i = Interpreter(engine, tsh, {})
    typecheck(lisp.parse(expr), i.env)
Exemplo n.º 5
0
def test_failing_arg(engine, tsh):
    expr = ('(add (series "types-a") '
            '     (priority (series "types-a") '
            '               (* "toto" (series "types-b"))))'
    )

    i = Interpreter(engine, tsh, {})
    with pytest.raises(TypeError) as err:
        typecheck(lisp.parse(expr), i.env)

    assert err.value.args[0] == "'toto' not of <class 'numbers.Number'>"
Exemplo n.º 6
0
def typecheck_formula(db_uri, pdbshell=False, namespace='tsh'):
    engine = create_engine(find_dburi(db_uri))
    tsh = timeseries(namespace)

    i = Interpreter(engine, tsh, {})
    for name, kind in tsh.list_series(engine).items():
        if kind != 'formula':
            continue

        formula = tsh.formula(engine, name)
        parsed = parse(formula)
        print(name, f'`{parsed[0]}`')
        typecheck(parsed, env=i.env)
Exemplo n.º 7
0
def test_today(engine, tsh):
    e1 = '(today)'
    e2 = '(today #:naive #t)'
    e3 = '(today #:naive #t #:tz "Europe/Moscow")'
    e4 = '(today #:naive #f)'
    e5 = '(today #:naive #f #:tz "Europe/Moscow")'
    e6 = '(today #:tz "Gondwana/Chandrapore")'

    i = Interpreter(engine, tsh, {})
    a = lisp.evaluate(e1, i.env)
    b = lisp.evaluate(e2, i.env)
    with pytest.raises(AssertionError) as err:
        lisp.evaluate(e3, i.env)
    assert err.value.args[0] == 'date cannot be naive and have a tz'
    d = lisp.evaluate(e4, i.env)
    e = lisp.evaluate(e5, i.env)
    with pytest.raises(pytz.UnknownTimeZoneError) as err:
        lisp.evaluate(e6, i.env)
    assert err.value.args[0] == 'Gondwana/Chandrapore'

    assert a.tz == pytz.utc
    assert b.tz is None
    assert d.tz == pytz.utc
    assert e.tz.zone == 'Europe/Moscow'
Exemplo n.º 8
0
def test_kw_subexpr(engine, tsh):
    expr = '(+ 1 (series "types-a" #:prune (+ 1 2)))'
    i = Interpreter(engine, tsh, {})
    typecheck(lisp.parse(expr), i.env)