forked from python-pendulum/pendulum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
3,691 additions
and
3,333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +0,0 @@ | ||
import sys | ||
import pendulum | ||
import struct | ||
|
||
from unittest import TestCase | ||
from contextlib import contextmanager | ||
|
||
from pendulum import DateTime, Date, Time, Duration | ||
from pendulum.tz import timezone, Timezone | ||
|
||
|
||
class AbstractTestCase(TestCase): | ||
|
||
def setUp(self): | ||
pendulum.set_local_timezone(timezone('America/Toronto')) | ||
|
||
super(AbstractTestCase, self).setUp() | ||
|
||
def tearDown(self): | ||
pendulum.set_test_now() | ||
pendulum.set_locale('en') | ||
pendulum.set_local_timezone() | ||
|
||
def assertDateTime(self, d, year, month, day, | ||
hour=None, minute=None, second=None, microsecond=None): | ||
self.assertEqual(year, d.year) | ||
self.assertEqual(month, d.month) | ||
self.assertEqual(day, d.day) | ||
|
||
if hour is not None: | ||
self.assertEqual(hour, d.hour) | ||
|
||
if minute is not None: | ||
self.assertEqual(minute, d.minute) | ||
|
||
if second is not None: | ||
self.assertEqual(second, d.second) | ||
|
||
if microsecond is not None: | ||
self.assertEqual(microsecond, d.microsecond) | ||
|
||
def assertDate(self, d, year, month, day): | ||
self.assertEqual(year, d.year) | ||
self.assertEqual(month, d.month) | ||
self.assertEqual(day, d.day) | ||
|
||
def assertTime(self, t, hour, minute, second, microsecond=None): | ||
self.assertEqual(hour, t.hour) | ||
self.assertEqual(minute, t.minute) | ||
self.assertEqual(second, t.second) | ||
|
||
if microsecond is not None: | ||
self.assertEqual(microsecond, t.microsecond) | ||
|
||
def assertDuration(self, pi, weeks, days=None, | ||
hours=None, minutes=None, seconds=None, | ||
microseconds=None): | ||
expected = {'weeks': pi.weeks} | ||
actual = {'weeks': weeks} | ||
|
||
if days is not None: | ||
expected['days'] = pi.remaining_days | ||
actual['days'] = days | ||
|
||
if hours is not None: | ||
expected['hours'] = pi.hours | ||
actual['hours'] = hours | ||
|
||
if minutes is not None: | ||
expected['minutes'] = pi.minutes | ||
actual['minutes'] = minutes | ||
|
||
if seconds is not None: | ||
expected['seconds'] = pi.remaining_seconds | ||
actual['seconds'] = seconds | ||
|
||
if microseconds is not None: | ||
expected['microseconds'] = pi.microseconds | ||
actual['microseconds'] = microseconds | ||
|
||
self.assertEqual(expected, actual) | ||
|
||
def assertIsInstanceOfDateTime(self, d): | ||
self.assertIsInstance(d, DateTime) | ||
|
||
def assertIsInstanceOfDate(self, d): | ||
self.assertIsInstance(d, Date) | ||
|
||
def assertIsInstanceOfTime(self, t): | ||
self.assertIsInstance(t, Time) | ||
|
||
def assertIsInstanceOfDuration(self, d): | ||
self.assertIsInstance(d, Duration) | ||
|
||
@contextmanager | ||
def wrap_with_test_now(self, dt=None): | ||
pendulum.set_test_now(dt or DateTime.now()) | ||
|
||
yield | ||
|
||
pendulum.set_test_now() | ||
|
||
def skip_if_32bit(self): | ||
if struct.calcsize("P") * 8 == 32: | ||
self.skipTest('Tests only available for 64bit systems') | ||
|
||
def skip_if_windows(self): | ||
if sys.platform == 'win32': | ||
self.skipTest('Tests only available for UNIX systems') | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,38 @@ | ||
from datetime import date | ||
from pendulum import Date | ||
|
||
from .. import AbstractTestCase | ||
from ..conftest import assert_date | ||
|
||
|
||
class ConstructTest(AbstractTestCase): | ||
def test_construct(): | ||
d = Date(2016, 10, 20) | ||
|
||
def test_construct(self): | ||
d = Date(2016, 10, 20) | ||
assert_date(d, 2016, 10, 20) | ||
|
||
self.assertIsInstanceOfDate(d) | ||
self.assertDate(d, 2016, 10, 20) | ||
|
||
def test_today(self): | ||
d = Date.today() | ||
def test_today(): | ||
d = Date.today() | ||
|
||
self.assertIsInstanceOfDate(d) | ||
assert isinstance(d, Date) | ||
|
||
def test_instance(self): | ||
d = Date.instance(date(2016, 10, 20)) | ||
|
||
self.assertIsInstanceOfDate(d) | ||
self.assertDate(d, 2016, 10, 20) | ||
def test_instance(): | ||
d = Date.instance(date(2016, 10, 20)) | ||
|
||
def test_create(self): | ||
d = Date.create(2016, 10, 20) | ||
assert isinstance(d, Date) | ||
assert_date(d, 2016, 10, 20) | ||
|
||
self.assertIsInstanceOfDate(d) | ||
self.assertDate(d, 2016, 10, 20) | ||
|
||
def test_create_empty_values(self): | ||
now = Date.today() | ||
d = Date.create() | ||
def test_create(): | ||
d = Date.create(2016, 10, 20) | ||
|
||
self.assertIsInstanceOfDate(d) | ||
self.assertDate(d, now.year, now.month, now.day) | ||
assert isinstance(d, Date) | ||
assert_date(d, 2016, 10, 20) | ||
|
||
|
||
def test_create_empty_values(): | ||
now = Date.today() | ||
d = Date.create() | ||
|
||
assert isinstance(d, Date) | ||
assert_date(d, now.year, now.month, now.day) |
Oops, something went wrong.