From 1de4d2c594ee64c82de845364c97524b632c6873 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 23 Feb 2010 23:46:37 -0500 Subject: [PATCH] test_util.py: improve coverage of util.time_format --- src/allmydata/test/test_util.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index 68746554..0a326b36 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -855,6 +855,32 @@ class TimeFormat(unittest.TestCase): self.failUnlessEqual(thatmomentinmarch, 1237585742.226536) self.failUnlessEqual(origtzname, time.tzname) + def test_iso_utc(self): + when = 1266760143.7841301 + out = time_format.iso_utc_date(when) + self.failUnlessEqual(out, "2010-02-21") + out = time_format.iso_utc_date(t=lambda: when) + self.failUnlessEqual(out, "2010-02-21") + out = time_format.iso_utc(when) + self.failUnlessEqual(out, "2010-02-21_13:49:03.784130") + out = time_format.iso_utc(when, sep="-") + self.failUnlessEqual(out, "2010-02-21-13:49:03.784130") + + def test_parse_duration(self): + p = time_format.parse_duration + DAY = 24*60*60 + self.failUnlessEqual(p("1 day"), DAY) + self.failUnlessEqual(p("2 days"), 2*DAY) + self.failUnlessEqual(p("3 months"), 3*31*DAY) + self.failUnlessEqual(p("4 mo"), 4*31*DAY) + self.failUnlessEqual(p("5 years"), 5*365*DAY) + e = self.failUnlessRaises(ValueError, p, "123") + self.failUnlessIn("no unit (like day, month, or year) in '123'", + str(e)) + + def test_parse_date(self): + self.failUnlessEqual(time_format.parse_date("2010-02-21"), 1266710400) + class CacheDir(unittest.TestCase): def test_basic(self): basedir = "test_util/CacheDir/test_basic" -- 2.45.2