File: test_checker_datetime.py

package info (click to toggle)
python-typepy 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 600 kB
  • sloc: python: 2,787; makefile: 75; sh: 7
file content (77 lines) | stat: -rw-r--r-- 2,321 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
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

import itertools
from datetime import date, datetime

import pytest
from dateutil.tz import tzoffset
from tcolorpy import tcolor

from typepy import DateTime, StrictLevel, Typecode


dateutil = pytest.importorskip("dateutil", minversion="2.7")

class_under_test = DateTime
nan = float("nan")
inf = float("inf")


class Test_DateTime_is_type:
    @pytest.mark.parametrize(
        ["value", "strict_level", "expected"],
        list(
            itertools.product(
                [datetime(2017, 3, 22, 10, 0, tzinfo=tzoffset(None, 32400)), date(2017, 3, 22)],
                [StrictLevel.MIN, StrictLevel.MIN + 1, StrictLevel.MAX],
                [True],
            )
        )
        + list(
            itertools.product(
                [
                    None,
                    "invalid time string",
                    9223372036854775807,
                    "100-0004",
                    "ใƒ†ใ‚นใƒˆ".encode(),
                ],
                [StrictLevel.MIN, StrictLevel.MIN + 1, StrictLevel.MAX],
                [False],
            )
        )
        + list(
            itertools.product(
                ["2017-03-22T10:00:00+0900", 1485685623, "1485685623", "1524930937.003555"],
                [StrictLevel.MIN],
                [True],
            )
        )
        + list(
            itertools.product(
                ["2017-03-22T10:00:00+0900", 1485685623, "1485685623"],
                [StrictLevel.MAX],
                [False],
            )
        ),
    )
    def test_normal(self, value, strict_level, expected):
        type_object = class_under_test(value, strict_level)

        assert type_object.is_type() == expected
        assert type_object.typecode == Typecode.DATETIME

    @pytest.mark.parametrize(
        ["value", "strip_ansi_escape", "expected"],
        [
            [tcolor("2017-03-22T10:00:00", "red"), False, False],
            [tcolor("2017-03-22T10:00:00", "red"), True, True],
        ],
    )
    def test_normal_ansi(self, value, strip_ansi_escape, expected):
        type_checker = class_under_test(value, StrictLevel.MIN, strip_ansi_escape=strip_ansi_escape)

        assert type_checker.is_type() == expected
        assert type_checker.typecode == Typecode.DATETIME