File: test_time.py

package info (click to toggle)
python-check-jsonschema 0.34.1-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 3,796 kB
  • sloc: python: 5,529; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 926 bytes parent folder | download
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
import random

import pytest

from check_jsonschema.formats.implementations.iso8601_time import validate


@pytest.mark.parametrize(
    "timestr",
    (
        "12:34:56Z",
        "23:59:59z",
        "23:59:59+00:00",
        "01:59:59-00:00",
    ),
)
def test_simple_positive_cases(timestr):
    assert validate(timestr)


@pytest.mark.parametrize(
    "timestr",
    (
        object(),
        "12:34:56",
        "23:59:60Z",
        "23:59:59+24:00",
        "01:59:59-00:60",
        "01:01:00:00:60",
    ),
)
def test_simple_negative_cases(timestr):
    assert not validate(timestr)


@pytest.mark.parametrize("precision", list(range(20)))
@pytest.mark.parametrize(
    "offsetstr",
    (
        "Z",
        "+00:00",
        "-00:00",
        "+23:59",
    ),
)
def test_allows_fracsec(precision, offsetstr):
    fracsec = random.randint(0, 10**precision)
    assert validate(f"23:59:59.{fracsec}{offsetstr}")