summaryrefslogtreecommitdiffstats
path: root/tests/time/test_behavior.py
blob: 0071c944b3d56af133d01391dab78d90f236de3b (plain)
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
from __future__ import annotations

import pickle

from datetime import time

import pytest

import pendulum

from pendulum import Time


@pytest.fixture()
def p():
    return pendulum.Time(12, 34, 56, 123456, tzinfo=pendulum.timezone("Europe/Paris"))


@pytest.fixture()
def d():
    return time(12, 34, 56, 123456, tzinfo=pendulum.timezone("Europe/Paris"))


def test_hash(p, d):
    assert hash(d) == hash(p)
    dt1 = Time(12, 34, 57, 123456)

    assert hash(p) != hash(dt1)


def test_pickle():
    dt1 = Time(12, 34, 56, 123456)
    s = pickle.dumps(dt1)
    dt2 = pickle.loads(s)

    assert dt2 == dt1


def test_utcoffset(p, d):
    assert d.utcoffset() == p.utcoffset()


def test_dst(p, d):
    assert d.dst() == p.dst()


def test_tzname(p, d):
    assert d.tzname() == p.tzname()
    assert Time(12, 34, 56, 123456).tzname() == time(12, 34, 56, 123456).tzname()