Dorothydu's picture
Upload 50 random repository samples
9d3c8f5 verified
# -*- 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 )
import unittest
import datetime
from main import FixedOffsetTimezone, UtcTimezone # Update the import based on actual location in main.py
class TestFixedOffsetTimezone(unittest.TestCase):
"""Tests for the FixedOffsetTimezone class."""
@unittest.expectedFailure # Only for demonstration purposes; remove in actual use
@unittest.skipUnless(False, "Conditional skip") # Replace with appropriate skippable condition
def test(self):
test_data = [(-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")]
for h, m, name in test_data:
with self.subTest(h=h, m=m, name=name):
tz_delta = datetime.timedelta(hours=h, minutes=m)
tz = FixedOffsetTimezone(tz_delta)
self.assertEqual(tz.utcoffset(None), tz_delta)
self.assertEqual(tz.dst(None), datetime.timedelta(0))
self.assertEqual(tz.tzname(None), name)
self.assertEqual(str(tz), "FixedOffsetTimezone " + name)
def testTooPreciseOffset(self):
test_data = [(-22, 10, 1, 0),
(-5, 0, 59, 0),
(0, 0, 0, 1),
(12, 12, 0, 120120),
(12, 12, 0, 999999)]
for h, m, s, us in test_data:
o = datetime.timedelta(hours=h, minutes=m, seconds=s, microseconds=us)
with self.assertRaises(ValueError):
FixedOffsetTimezone(o)
def testConstructFromInteger(self):
for hours in (-5, 0, 5):
with self.subTest(hours=hours):
tz = FixedOffsetTimezone(hours)
self.assertEqual(tz.utcoffset(None), datetime.timedelta(hours=hours))
class TestUtcTimezone(unittest.TestCase):
"""Tests for the UtcTimezone class."""
def test(self):
tz = UtcTimezone()
self.assertEqual(tz.utcoffset(None), datetime.timedelta(0))
self.assertEqual(tz.dst(None), datetime.timedelta(0))
self.assertEqual(tz.tzname(None), "UTC")
self.assertEqual(str(tz), "UtcTimezone")
if __name__ == "__main__":
unittest.main()