Exemplo n.º 1
0
def test_delta_math_operations_return_type():
    delta = Delta(days=1, hours=1, minutes=1, seconds=1, microseconds=1)

    assert isinstance(delta + delta, Delta)
    assert isinstance(delta - delta, Delta)
    assert isinstance(delta * 1, Delta)
    assert isinstance(delta / 1, Delta)
    assert isinstance(delta // 1, Delta)
    assert isinstance(abs(delta), Delta)
    assert isinstance(+delta, Delta)
    assert isinstance(-delta, Delta)
    assert isinstance(delta % delta, Delta)
    assert isinstance(divmod(delta, delta)[1], Delta)
Exemplo n.º 2
0
def test_delta_parse_invalid(obj, exception):
    with pytest.raises(exception):
        Delta.parse(obj)
Exemplo n.º 3
0
def test_delta_parse(obj, expected):
    assert Delta.parse(obj) == expected
Exemplo n.º 4
0
 }, Zulu(2000, 1, 2)),
 ("shift", Zulu(2000, 1, 1), timedelta(days=1), Zulu(2000, 1, 2)),
 ("shift", Zulu(2000, 1, 1), timedelta(days=-1), Zulu(1999, 12, 31)),
 ("shift", Zulu(2000, 1, 1), relativedelta(days=1), Zulu(2000, 1, 2)),
 ("add", Zulu(2000, 1, 1), {
     "days": 1
 }, Zulu(2000, 1, 2)),
 ("add", Zulu(2000, 1, 1), timedelta(days=1), Zulu(2000, 1, 2)),
 ("add", Zulu(2000, 1, 1), relativedelta(days=1), Zulu(2000, 1, 2)),
 ("subtract", Zulu(2000, 1, 1), {
     "days": 1
 }, Zulu(1999, 12, 31)),
 ("subtract", Zulu(2000, 1, 1), timedelta(days=1), Zulu(1999, 12, 31)),
 ("subtract", Zulu(2000, 1, 1), relativedelta(days=1), Zulu(
     1999, 12, 31)),
 ("subtract", Zulu(2000, 1, 1), Delta(days=1), Zulu(1999, 12, 31)),
 ("subtract", Zulu(2000, 1, 1), Zulu(1999, 12, 31), Delta(days=1)),
 ("subtract", Zulu(1999, 12, 31), Zulu(2000, 1, 1), Delta(days=-1)),
 ("subtract", Zulu(2000, 1, 1), datetime(1999, 12, 31), Delta(days=1)),
 ("shift", Zulu(2000, 1, 1), {
     "days": -1
 }, Zulu(1999, 12, 31)),
 ("add", Zulu(2000, 1, 1), {
     "days": -1
 }, Zulu(1999, 12, 31)),
 ("subtract", Zulu(2000, 1, 1), {
     "days": -1
 }, Zulu(2000, 1, 2)),
 ("shift", Zulu(2000, 1, 1), {
     "years": 1
 }, Zulu(2001, 1, 1)),
Exemplo n.º 5
0
def test_delta_parse_invalid(obj, exception):
    with pytest.raises(exception):
        Delta.parse(obj)
Exemplo n.º 6
0
def test_delta_as_int():
    secs = 10.1234
    delta = Delta(seconds=secs)
    assert int(delta) == int(secs)
Exemplo n.º 7
0
def test_delta_as_float():
    secs = 10.1234
    delta = Delta(seconds=secs)
    assert float(delta) == secs
Exemplo n.º 8
0
def test_delta_parse(obj, expected):
    assert Delta.parse(obj) == expected
Exemplo n.º 9
0
def test_delta_pickle():
    delta = Delta(hours=1)
    assert pickle.loads(pickle.dumps(delta)) == delta
Exemplo n.º 10
0
def test_delta_format_exception(opts, exception):
    with pytest.raises(exception):
        Delta(1).format(**opts)
Exemplo n.º 11
0
def test_delta_format_default_locale(monkeypatch):
    for var in ("LANGUAGE", "LC_ALL", "LC_CTYPE", "LANG"):
        monkeypatch.setenv(var, "")

    assert Delta(seconds=5).format() == "5 seconds"
Exemplo n.º 12
0
from datetime import timedelta
import pickle

import pytest

from zulu import ParseError, Delta, to_seconds

parametrize = pytest.mark.parametrize


@parametrize(
    "obj,expected",
    [
        (timedelta(seconds=60), Delta(seconds=60)),
        (60, Delta(seconds=60)),
        ("32m", Delta(minutes=32)),
        ("2h32m", Delta(hours=2, minutes=32)),
        ("3d2h32m", Delta(days=3, hours=2, minutes=32)),
        ("1w3d2h32m", Delta(weeks=1, days=3, hours=2, minutes=32)),
        ("1w 3d 2h 32m", Delta(weeks=1, days=3, hours=2, minutes=32)),
        ("1 w 3 d 2 h 32 m", Delta(weeks=1, days=3, hours=2, minutes=32)),
        ("4:13", Delta(minutes=4, seconds=13)),
        ("4:13:02", Delta(hours=4, minutes=13, seconds=2)),
        ("4:13:02.266",
         Delta(hours=4, minutes=13, seconds=2, microseconds=266000)),
        (
            "2:04:13:02.266",
            Delta(days=2, hours=4, minutes=13, seconds=2, microseconds=266000),
        ),
        ("2 days, 4:13:02", Delta(days=2, hours=4, minutes=13, seconds=2)),
        (