Beispiel #1
0
    def test_iso8601(self):
        """
        Test get_cool_off_iso8601 correctly translates datetime.timdelta to ISO 8601 formatted duration.
        """

        expected = {
            timedelta(days=1, hours=25, minutes=42, seconds=8):
                'P2DT1H42M8S',
            timedelta(days=7, seconds=342):
                'P7DT5M42S',
            timedelta(days=0, hours=2, minutes=42):
                'PT2H42M',
            timedelta(hours=20, seconds=42):
                'PT20H42S',
            timedelta(seconds=300):
                'PT5M',
            timedelta(seconds=9005):
                'PT2H30M5S',
            timedelta(minutes=9005):
                'P6DT6H5M',
            timedelta(days=15):
                'P15D'
        }

        for delta, iso_duration in expected.items():
            with self.subTest(iso_duration):
                self.assertEqual(get_cool_off_iso8601(delta), iso_duration)
Beispiel #2
0
    def test_iso8601(self):
        """
        Test get_cool_off_iso8601 correctly translates datetime.timedelta to ISO 8601 formatted duration.
        """

        expected = {
            timedelta(days=1, hours=25, minutes=42, seconds=8): "P2DT1H42M8S",
            timedelta(days=7, seconds=342): "P7DT5M42S",
            timedelta(days=0, hours=2, minutes=42): "PT2H42M",
            timedelta(hours=20, seconds=42): "PT20H42S",
            timedelta(seconds=300): "PT5M",
            timedelta(seconds=9005): "PT2H30M5S",
            timedelta(minutes=9005): "P6DT6H5M",
            timedelta(days=15): "P15D",
        }

        for delta, iso_duration in expected.items():
            with self.subTest(iso_duration):
                self.assertEqual(get_cool_off_iso8601(delta), iso_duration)