File: apfs_time.py

package info (click to toggle)
dfdatetime 20190116-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 652 kB
  • sloc: python: 5,155; sh: 119; makefile: 30
file content (56 lines) | stat: -rw-r--r-- 1,711 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the APFS timestamp implementation."""

from __future__ import unicode_literals

import decimal
import unittest

from dfdatetime import apfs_time


class APFSTimeTest(unittest.TestCase):
  """Tests for the APFS timestamp."""

  # pylint: disable=protected-access

  def testGetNormalizedTimestamp(self):
    """Tests the _GetNormalizedTimestamp function."""
    apfs_time_object = apfs_time.APFSTime(timestamp=1281643591987654321)

    normalized_timestamp = apfs_time_object._GetNormalizedTimestamp()
    self.assertEqual(
        normalized_timestamp, decimal.Decimal('1281643591.987654321'))

    apfs_time_object = apfs_time.APFSTime()

    normalized_timestamp = apfs_time_object._GetNormalizedTimestamp()
    self.assertIsNone(normalized_timestamp)

    apfs_time_object = apfs_time.APFSTime(timestamp=9223372036854775810)

    date_time_string = apfs_time_object._GetNormalizedTimestamp()
    self.assertIsNone(date_time_string)

  def testCopyFromDateTimeString(self):
    """Tests the CopyFromDateTimeString function."""
    apfs_time_object = apfs_time.APFSTime()
    with self.assertRaises(ValueError):
      apfs_time_object.CopyFromDateTimeString('2554-07-21 23:34:34.000000')

  def testCopyToDateTimeString(self):
    """Tests the CopyToDateTimeString function."""
    apfs_time_object = apfs_time.APFSTime(timestamp=9223372036854775810)

    date_time_string = apfs_time_object.CopyToDateTimeString()
    self.assertIsNone(date_time_string)

    apfs_time_object = apfs_time.APFSTime()

    date_time_string = apfs_time_object.CopyToDateTimeString()
    self.assertIsNone(date_time_string)


if __name__ == '__main__':
  unittest.main()