Beispiel #1
0
 def test_as_string(self):
     self.assertEqual(str(Duration.fromstring('P3Y1D')), 'P3Y1D')
     self.assertEqual(str(Duration.fromstring('PT2M10.4S')), 'PT2M10.4S')
     self.assertEqual(str(Duration.fromstring('PT2400H')), 'P100D')
     self.assertEqual(str(Duration.fromstring('-P15M')), '-P1Y3M')
     self.assertEqual(str(Duration.fromstring('-P809YT3H5M5S')),
                      '-P809YT3H5M5S')
 def test_le(self):
     self.assertTrue(Duration(months=15) <= Duration(months=16))
     self.assertTrue(Duration(months=16) <= Duration(16))
     self.assertTrue(Duration(months=16) <= Duration.fromstring('P16M1D'))
     self.assertTrue(Duration(months=16) <= Duration.fromstring('P16MT1H'))
     self.assertTrue(Duration(months=16) <= Duration.fromstring('P16MT1M'))
     self.assertTrue(Duration(months=16) <= Duration.fromstring('P16MT1S'))
     self.assertTrue(Duration(months=16) <= Duration.fromstring('P16MT0S'))
    def test_init_fromstring(self):
        self.assertIsInstance(Duration.fromstring('P1Y'), Duration)
        self.assertIsInstance(Duration.fromstring('P1M'), Duration)
        self.assertIsInstance(Duration.fromstring('P1D'), Duration)
        self.assertIsInstance(Duration.fromstring('PT0H'), Duration)
        self.assertIsInstance(Duration.fromstring('PT1M'), Duration)
        self.assertIsInstance(Duration.fromstring('PT0.0S'), Duration)

        self.assertRaises(ValueError, Duration.fromstring, 'P')
        self.assertRaises(ValueError, Duration.fromstring, 'PT')
        self.assertRaises(ValueError, Duration.fromstring, '1Y')
        self.assertRaises(ValueError, Duration.fromstring, 'P1W1DT5H3M23.9S')
        self.assertRaises(ValueError, Duration.fromstring, 'P1.5Y')
        self.assertRaises(ValueError, Duration.fromstring, 'PT1.1H')
        self.assertRaises(ValueError, Duration.fromstring, 'P1.0DT5H3M23.9S')
 def test_incomparable_values(self):
     self.assertFalse(Duration(1) < Duration.fromstring('P30D'))
     self.assertFalse(Duration(1) <= Duration.fromstring('P30D'))
     self.assertFalse(Duration(1) > Duration.fromstring('P30D'))
     self.assertFalse(Duration(1) >= Duration.fromstring('P30D'))
 def test_ge(self):
     self.assertTrue(Duration(16) >= Duration(15))
     self.assertTrue(Duration(16) >= Duration(16))
     self.assertTrue(Duration.fromstring('P1Y1DT1S') >= Duration.fromstring('P1Y1D'))
 def test_ne(self):
     self.assertNotEqual(Duration.fromstring('PT147.3S'), None)
     self.assertNotEqual(Duration.fromstring('PT147.3S'), (0, 147.3))
     self.assertNotEqual(Duration.fromstring('P3Y1D'), (36, 3600 * 2))
     self.assertNotEqual(Duration.fromstring('P3Y1D'), (36, 3600 * 24, 0))
     self.assertNotEqual(Duration.fromstring('P3Y1D'), None)
    def test_eq(self):
        self.assertEqual(Duration.fromstring('PT147.5S'), (0, 147.5))
        self.assertEqual(Duration.fromstring('PT147.3S'), (0, Decimal("147.3")))

        self.assertEqual(Duration.fromstring('PT2M10.4S'), (0, Decimal("130.4")))
        self.assertEqual(Duration.fromstring('PT5H3M23.9S'), (0, Decimal("18203.9")))
        self.assertEqual(Duration.fromstring('P1DT5H3M23.9S'), (0, Decimal("104603.9")))
        self.assertEqual(Duration.fromstring('P31DT5H3M23.9S'), (0, Decimal("2696603.9")))
        self.assertEqual(Duration.fromstring('P1Y1DT5H3M23.9S'), (12, Decimal("104603.9")))

        self.assertEqual(Duration.fromstring('-P809YT3H5M5S'), (-9708, -11105))
        self.assertEqual(Duration.fromstring('P15M'), (15, 0))
        self.assertEqual(Duration.fromstring('P1Y'), (12, 0))
        self.assertEqual(Duration.fromstring('P3Y1D'), (36, 3600 * 24))
        self.assertEqual(Duration.fromstring('PT2400H'), (0, 8640000))
        self.assertEqual(Duration.fromstring('PT4500M'), (0, 4500 * 60))
        self.assertEqual(Duration.fromstring('PT4500M70S'), (0, 4500 * 60 + 70))
        self.assertEqual(Duration.fromstring('PT5529615.3S'), (0, Decimal('5529615.3')))
Beispiel #8
0
 def test_numeric_type_proxy(self):
     self.assertIsInstance(10, NumericTypeProxy)
     self.assertIsInstance(17.8, NumericTypeProxy)
     self.assertIsInstance(Decimal('18.12'), NumericTypeProxy)
     self.assertNotIsInstance(True, NumericTypeProxy)
     self.assertNotIsInstance(Duration.fromstring('P1Y'), NumericTypeProxy)