Ejemplo n.º 1
0
def test_td_init(args, kw, exp):
    """
    Tests for td.__init__()
    """
    pytest.dbgfunc()
    if isinstance(exp, Exception):
        with pytest.raises(type(exp)) as err:
            actual = td(*args, **kw)
        assert str(exp) in str(err.value)
    else:
        actual = td(*args, **kw)
        assert actual == exp, ("exp - act = {}".format(exp._secs() -
                                                       actual._secs()))
Ejemplo n.º 2
0
def test_td_dhms(inp, exp):
    """
    test td.dhhmmss()
    """
    pytest.dbgfunc()
    obj = td(inp)
    assert obj.dhms() == exp
Ejemplo n.º 3
0
def dtm_rtd(**kw):
    """
    Generate a random td
    """
    if kw['d']:  # pragma: no cover
        pdb.set_trace()
    ssec = kw['SECONDS'] or random.randint(0, 5 * 24 * 3600)
    sec = int(ssec)
    obj = td(sec)
    print("{} (seconds = {})".format(dhhmmss(obj._duration), obj._duration))
Ejemplo n.º 4
0
def test_rtd(capsys):
    """
    Test dtm_rtd
    """
    inp = 28299
    kw = {'SECONDS': inp, 'd': False}
    nub = td(inp)
    dtmain.dtm_rtd(**kw)
    (out, err) = capsys.readouterr()
    exp = "{} (seconds = {})".format(str(nub), nub._duration)
    assert exp in out
Ejemplo n.º 5
0
def test_td_minutes(inp, exp):
    """
    Test td.minutes()
    """
    obj = td(inp)
    assert obj.minutes() == exp
Ejemplo n.º 6
0
def test_td_hours(inp, exp):
    """
    Test td.hours()
    """
    obj = td(inp)
    assert obj.hours() == exp
Ejemplo n.º 7
0
def test_td_days(inp, exp):
    """
    Test td.days()
    """
    obj = td(inp)
    assert obj.days() == exp
Ejemplo n.º 8
0
def test_td_attrs():
    """
    Check that a new td object has all the right attributes
    """
    a = td()
    assert hasattr(a, '_duration')
Ejemplo n.º 9
0
def test_td_seconds(inp, exp):
    """
    Test td.minutes()
    """
    obj = td(*inp)
    assert obj.seconds() == exp
Ejemplo n.º 10
0
import pytest


# -----------------------------------------------------------------------------
def test_td_attrs():
    """
    Check that a new td object has all the right attributes
    """
    a = td()
    assert hasattr(a, '_duration')


# -----------------------------------------------------------------------------
# test_td_init()
@pytest.mark.parametrize("args, kw, exp", [
    dtu.pp((15, ), {}, td(secs=15), id=ppf("args: (s < 60,)", "T", w=47)),
    dtu.pp(
        (90, ), {}, td(mins=1, secs=30), id=ppf("args: (60 < s,)", "T", w=47)),
    dtu.pp((1, 1), {}, td(secs=61), id=ppf("args: (m, s)", "T", w=47)),
    dtu.pp((1, 1, 1), {}, td(secs=3661), id=ppf("args: (h, m, s)", "T", w=47)),
    dtu.pp((1, 1, 1, 1), {},
           td(secs=90061),
           id=ppf("args: (d, h, m, s)", "T", w=47)),
    dtu.pp((-1, ), {}, td(secs=-1), id=ppf("negative td okay", "T", w=47)),
    dtu.pp(
        (-3, 10, 7), {}, td(secs=-10193), id=ppf("net negative", "T", w=47)),
    dtu.pp((), {'s': 95}, td(1, 35), id=ppf("kw: {s}", "T", w=47)),
    dtu.pp((), {'m': 75}, td(4500), id=ppf("kw: {m}", "T", w=47)),
    dtu.pp((), {
        'm': 5,
        's': 105