예제 #1
0
def test_date_range():
    min_date = date(1709, 1, 1)
    max_date = date(2290, 12, 31)
    one_day = timedelta(1)
    result = q('-0W 1709.01.01 1709.01.02 2290.12.30 2290.12.31 0Wd')
    assert eq(
        D([
            min_date - one_day, min_date, min_date + one_day,
            max_date - one_day, max_date, max_date + one_day
        ]), result)
    # Demonstrate that q bails on the out of range dates
    with pytest.raises(_k.error):
        d1 = min_date - one_day
        # We cannot use strftime here because in Python 2.7 it only
        # works for dates after 1900.
        q("%d.%d.%d" % (d1.year, d1.month, d1.day))
    with pytest.raises(_k.error):
        d2 = max_date + one_day
        q(d2.strftime('%Y.%m.%d'))

    # Test scalar conversions
    assert eq(_k.K(d1), q('-0Wd'))
    assert eq(_k.K(d2), q('0Wd'))
    assert eq(_k.K(min_date), q('1709.01.01'))
    assert eq(_k.K(max_date), q('2290.12.31'))
예제 #2
0
파일: test_k.py 프로젝트: xbsd/pyq
def test_constructor(k, py):
    x = _k.K(py)
    assert eq(q(k), x)
예제 #3
0
파일: test_k.py 프로젝트: xbsd/pyq
def test_errors_K():
    with pytest.raises(TypeError):
        _k.K()
예제 #4
0
def test_constructor_long():
    x = eval('42L')
    assert eq(_k.K(x), q('42'))