Ejemplo n.º 1
0
 def test_cmp_6(self):
     t0 = Time()
     t1 = Time(123, 123)
     self.assertRaises(Exception, lambda: t0 == t1)
     self.assertRaises(Exception, lambda: t0 != t1)
     self.assertRaises(Exception, lambda: t0 < t1)
     self.assertRaises(Exception, lambda: t0 <= t1)
     self.assertRaises(Exception, lambda: t0 > t1)
     self.assertRaises(Exception, lambda: t0 >= t1)
Ejemplo n.º 2
0
 def test_cmp_5(self):
     t0 = Time(1234567, 123456)
     t1 = Time(123, 123)
     self.assertTrue(not (t0 == t1))
     self.assertTrue(t0 != t1)
     self.assertTrue(not (t0 < t1))
     self.assertTrue(not (t0 <= t1))
     self.assertTrue(t0 > t1)
     self.assertTrue(t0 >= t1)
Ejemplo n.º 3
0
 def testValid(self):
     t0 = Time()
     self.assertTrue(not t0.isValid())
     t0 = Time(123)
     self.assertTrue(t0.isValid())
     t0 = Time(12345, 12345)
     self.assertTrue(t0.isValid())
Ejemplo n.º 4
0
    def test_3(self):
        # test for time specifiers, assume this test runs in US, -0800 timezone

        t0 = Time(0, 0)

        tstr = t0.toString("%H:%M:%S")
        self.assertEqual(tstr, "16:00:00")
        tstr = t0.toString("%T")
        self.assertEqual(tstr, "16:00:00")
        tstr = t0.toString("%T%z")
        self.assertEqual(tstr, "16:00:00-0800")
Ejemplo n.º 5
0
    def test_hash(self):

        d = {}
        d[Time(1)] = 1000
        d[Time(2)] = 10000
        d[Time(1000)] = 3

        self.assertEqual(len(d), 3)
        self.assertEqual(d[Time(1)], 1000)
        self.assertEqual(d[Time(2)], 10000)
        self.assertEqual(d[Time(1000)], 3)
        self.assertEqual(d.get(Time(5), 5), 5)
        self.assertRaises(Exception, lambda: d.get(Time(), None))
Ejemplo n.º 6
0
    def test_2(self):

        # epoch time in different formats
        t0 = Time.parse("1970-01-01 00:00:00Z")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("1970-01-01 00:00:00-00")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("1970-01-01 00:00:00+00:00")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("1970-01-01 00:00:00-0000")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("19700101 000000Z")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("19700101        000000Z")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("19700101T000000Z")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("19700101T010000+01")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("19700101T010000+0100")
        self.assertEqual(t0, Time(0, 0))
        t0 = Time.parse("1970-01-01 01:00:00+01:00")
        self.assertEqual(t0, Time(0, 0))
Ejemplo n.º 7
0
    def test_1(self):
        # test for S<seconds>[.<fractions>] syntax

        # test illegal syntax
        self.assertRaises(Exception, lambda: Time.parse("S 1"))
        self.assertRaises(Exception, lambda: Time.parse(" S1"))
        self.assertRaises(Exception, lambda: Time.parse("S1 "))
        self.assertRaises(Exception, lambda: Time.parse("S12345678900"))
        self.assertRaises(Exception, lambda: Time.parse("S-1"))
        self.assertRaises(Exception, lambda: Time.parse("S1."))
        self.assertRaises(Exception, lambda: Time.parse("S0.1234567890"))

        # test legal syntax, all variations
        t0 = Time.parse("S1234567890")
        self.assertEqual(t0, Time(1234567890, 0))
        t0 = Time.parse("S1234567890.1")
        self.assertEqual(t0, Time(1234567890, 100000000))
        t0 = Time.parse("S1234567890.123456789")
        self.assertEqual(t0, Time(1234567890, 123456789))
        t0 = Time.parse("S0.000000001")
        self.assertEqual(t0, Time(0, 1))
        t0 = Time.parse("S0")
        self.assertEqual(t0, Time(0, 0))
Ejemplo n.º 8
0
    def test_2(self):

        # test for date specifiers, assume this test runs in US, -0800 timezone

        t0 = Time(0, 0)

        tstr = t0.toString("%Y")
        self.assertEqual(tstr, "1969")
        tstr = t0.toString("%Y-%m")
        self.assertEqual(tstr, "1969-12")
        tstr = t0.toString("%Y-%m-%d")
        self.assertEqual(tstr, "1969-12-31")
        tstr = t0.toString("%F")
        self.assertEqual(tstr, "1969-12-31")
        tstr = t0.toString("%Y-%j")
        self.assertEqual(tstr, "1969-365")
Ejemplo n.º 9
0
    def test_4(self):
        # test for default time formatting, assume this test runs in US, -0800 timezone

        t0 = Time(0, 0)

        tstr = t0.toString()
        self.assertEqual(tstr, "1969-12-31 16:00:00.000000000-0800")
        tstr = str(t0)
        self.assertEqual(tstr, "1969-12-31 16:00:00.000000000-0800")

        t1 = Time(1234567890, 123456789)

        tstr = t1.toString()
        self.assertEqual(tstr, "2009-02-13 15:31:30.123456789-0800")
        tstr = str(t1)
        self.assertEqual(tstr, "2009-02-13 15:31:30.123456789-0800")
Ejemplo n.º 10
0
 def testFieldValues(self):
     t0 = Time(1234567, 123456)
     self.assertTrue(t0.isValid())
     self.assertEqual(t0.sec(), 1234567)
     self.assertEqual(t0.nsec(), 123456)
Ejemplo n.º 11
0
    def test_1(self):
        # test for %f specifier

        t0 = Time(0, 123456789)

        tstr = t0.toString("%f")
        self.assertEqual(tstr, ".123456789")

        tstr = t0.toString("%.1f")
        self.assertEqual(tstr, ".1")
        tstr = t0.toString("%.2f")
        self.assertEqual(tstr, ".12")
        tstr = t0.toString("%.3f")
        self.assertEqual(tstr, ".123")
        tstr = t0.toString("%.4f")
        self.assertEqual(tstr, ".1234")
        tstr = t0.toString("%.5f")
        self.assertEqual(tstr, ".12345")
        tstr = t0.toString("%.6f")
        self.assertEqual(tstr, ".123456")
        tstr = t0.toString("%.7f")
        self.assertEqual(tstr, ".1234567")
        tstr = t0.toString("%.8f")
        self.assertEqual(tstr, ".12345678")
        tstr = t0.toString("%.9f")
        self.assertEqual(tstr, ".123456789")

        tstr = t0.toString("%.0f")
        self.assertEqual(tstr, ".1")
        tstr = t0.toString("%.10f")
        self.assertEqual(tstr, ".123456789")
        tstr = t0.toString("%.128f")
        self.assertEqual(tstr, ".123456789")
Ejemplo n.º 12
0
    def test_4(self):
        # test for timezones

        t0 = Time.parse("197002 Z")
        self.assertEqual(t0, Time(31 * 24 * 3600, 0))
        t0 = Time.parse("19700102 Z")
        self.assertEqual(t0, Time(24 * 3600, 0))
        t0 = Time.parse("1970-01-01 -08")
        self.assertEqual(t0, Time(8 * 3600, 0))
        t0 = Time.parse("19700102T000000Z")
        self.assertEqual(t0, Time(24 * 3600, 0))
        t0 = Time.parse("19700102T000000+0100")
        self.assertEqual(t0, Time(23 * 3600, 0))
        t0 = Time.parse("19700102T000000+1000")
        self.assertEqual(t0, Time(14 * 3600, 0))
        t0 = Time.parse("19700102T000000-1000")
        self.assertEqual(t0, Time(34 * 3600, 0))
        t0 = Time.parse("19700102T000000-0140")
        self.assertEqual(t0, Time(24 * 3600 + 100 * 60, 0))
        t0 = Time.parse("19700102T000000+0140")
        self.assertEqual(t0, Time(24 * 3600 - 100 * 60, 0))
        t0 = Time.parse("19700102T000000-01:40")
        self.assertEqual(t0, Time(24 * 3600 + 100 * 60, 0))
        t0 = Time.parse("19700102T000000+01:40")
        self.assertEqual(t0, Time(24 * 3600 - 100 * 60, 0))