File: factory.py

package info (click to toggle)
dfdatetime 20240504-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: python: 7,898; sh: 22; makefile: 15
file content (85 lines) | stat: -rw-r--r-- 2,646 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the date and time values factory."""

import unittest

from dfdatetime import interface
from dfdatetime import factory


class TestDateTimeValues(interface.DateTimeValues):
  """Date and time values for testing."""

  # pylint: disable=redundant-returns-doc

  def _GetNormalizedTimestamp(self):
    """Retrieves the normalized timestamp.

    Returns:
      decimal.Decimal: normalized timestamp, which contains the number of
          seconds since January 1, 1970 00:00:00 and a fraction of second used
          for increased precision, or None if the normalized timestamp cannot be
          determined.
    """
    return None

  def CopyFromDateTimeString(self, time_string):
    """Copies a date time value from a date and time string.

    Args:
      time_string (str): date and time value formatted as:
          YYYY-MM-DD hh:mm:ss.######[+-]##:##

          Where # are numeric digits ranging from 0 to 9 and the seconds
          fraction can be either 3 or 6 digits. The time of day, seconds
          fraction and time zone offset are optional. The default time zone
          is UTC.

    Raises:
      ValueError: if the time string is invalid or not supported.
    """
    return

  def CopyToDateTimeString(self):
    """Copies the date time value to a date and time string.

    Returns:
      str: date and time value formatted as: "YYYY-MM-DD hh:mm:ss.######" or
          None if the timestamp cannot be copied to a date and time string.
    """
    return None


class FactoryTest(unittest.TestCase):
  """Tests the date and time values factory."""

  def testDateTimeValuesRegistration(self):
    """Tests the Register and DeregisterDateTimeValues functions."""
    # pylint: disable=protected-access
    number_of_date_time_values_types = len(
        factory.Factory._date_time_values_types)

    factory.Factory.RegisterDateTimeValues(TestDateTimeValues)
    self.assertEqual(
        len(factory.Factory._date_time_values_types),
        number_of_date_time_values_types + 1)

    with self.assertRaises(KeyError):
      factory.Factory.RegisterDateTimeValues(TestDateTimeValues)

    factory.Factory.DeregisterDateTimeValues(TestDateTimeValues)
    self.assertEqual(
        len(factory.Factory._date_time_values_types),
        number_of_date_time_values_types)

  def testNewDateTimeValues(self):
    """Tests the NewDateTimeValues function."""
    test_date_time_values = factory.Factory.NewDateTimeValues(
        'Filetime', timestamp=0x01cb3a623d0a17ce)

    self.assertIsNotNone(test_date_time_values)


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