File: test_clock.py

package info (click to toggle)
python-aiortc 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,052 kB
  • sloc: python: 20,294; javascript: 321; makefile: 21; sh: 1
file content (31 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import datetime
from unittest import TestCase
from unittest.mock import patch

from aiortc import clock


class ClockTest(TestCase):
    @patch("aiortc.clock.current_datetime")
    def test_current_ms(self, mock_now):
        mock_now.return_value = datetime.datetime(
            2018, 9, 11, tzinfo=datetime.timezone.utc
        )
        self.assertEqual(clock.current_ms(), 3745612800000)

        mock_now.return_value = datetime.datetime(
            2018, 9, 11, 0, 0, 1, tzinfo=datetime.timezone.utc
        )
        self.assertEqual(clock.current_ms(), 3745612801000)

    def test_datetime_from_ntp(self):
        dt = datetime.datetime(
            2018, 6, 28, 9, 3, 5, 423998, tzinfo=datetime.timezone.utc
        )
        self.assertEqual(clock.datetime_from_ntp(16059593044731306503), dt)

    def test_datetime_to_ntp(self):
        dt = datetime.datetime(
            2018, 6, 28, 9, 3, 5, 423998, tzinfo=datetime.timezone.utc
        )
        self.assertEqual(clock.datetime_to_ntp(dt), 16059593044731306503)