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()))
def test_td_dhms(inp, exp): """ test td.dhhmmss() """ pytest.dbgfunc() obj = td(inp) assert obj.dhms() == exp
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))
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
def test_td_minutes(inp, exp): """ Test td.minutes() """ obj = td(inp) assert obj.minutes() == exp
def test_td_hours(inp, exp): """ Test td.hours() """ obj = td(inp) assert obj.hours() == exp
def test_td_days(inp, exp): """ Test td.days() """ obj = td(inp) assert obj.days() == exp
def test_td_attrs(): """ Check that a new td object has all the right attributes """ a = td() assert hasattr(a, '_duration')
def test_td_seconds(inp, exp): """ Test td.minutes() """ obj = td(*inp) assert obj.seconds() == exp
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