File: test_timezone.py

package info (click to toggle)
suds 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,836 kB
  • sloc: python: 18,367; makefile: 198; sh: 41
file content (79 lines) | stat: -rw-r--r-- 2,741 bytes parent folder | download | duplicates (6)
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
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or modify it under
# the terms of the (LGPL) GNU Lesser General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Library Lesser General Public License
# for more details at ( http://www.gnu.org/licenses/lgpl.html ).
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# written by: Jurko Gospodnetić ( jurko.gospodnetic@pke.hr )

"""
Unit tests for Timezone modeling classes implemented in suds.

Implemented using the 'pytest' testing framework.

"""

if __name__ == "__main__":
    import testutils
    testutils.run_using_pytest(globals())

from suds.sax.date import FixedOffsetTimezone, UtcTimezone

import pytest

import datetime


class TestFixedOffsetTimezone:
    """Tests for the suds.sax.date.FixedOffsetTimezone class."""

    @pytest.mark.parametrize(("h", "m", "name"), (
        (-13, 0, "-13:00"),
        (-5, 0, "-05:00"),
        (0, 0, "+00:00"),
        (5, 0, "+05:00"),
        (13, 0, "+13:00"),
        (5, 50, "+05:50"),
        (-4, 31, "-04:31")))
    def test(self, h, m, name):
        tz_delta = datetime.timedelta(hours=h, minutes=m)
        tz = FixedOffsetTimezone(tz_delta)
        assert tz.utcoffset(None) is tz_delta
        assert tz.dst(None) == datetime.timedelta(0)
        assert tz.tzname(None) == name
        assert str(tz) == "FixedOffsetTimezone " + name

    @pytest.mark.parametrize(("h", "m", "s", "us"), (
        (-22, 10, 1, 0),
        (-5, 0, 59, 0),
        (0, 0, 0, 1),
        (12, 12, 0, 120120),
        (12, 12, 0, 999999)))
    def testTooPreciseOffset(self, h, m, s, us):
        o = datetime.timedelta(hours=h, minutes=m, seconds=s, microseconds=us)
        pytest.raises(ValueError, FixedOffsetTimezone, o)

    @pytest.mark.parametrize("hours", (-5, 0, 5))
    def testConstructFromInteger(self, hours):
        tz = FixedOffsetTimezone(hours)
        assert tz.utcoffset(None) == datetime.timedelta(hours=hours)


class TestUtcTimezone:
    """Tests for the suds.sax.date.UtcTimezone class."""

    def test(self):
        tz = UtcTimezone()
        assert tz.utcoffset(None) == datetime.timedelta(0)
        assert tz.dst(None) == datetime.timedelta(0)
        assert tz.tzname(None) == "UTC"
        assert str(tz) == "UtcTimezone"