Last active
December 15, 2015 16:49
-
-
Save uranusjr/5292314 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from dateutil.relativedelta import relativedelta | |
def three_months_from(date): | |
return date + relativedelta(months=3) |
This file contains hidden or 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
import unittest | |
import datetime | |
from dm import three_months_from | |
class ThreeMonthsFromDateTest(unittest.TestCase): | |
def _test_date(self, input_params, output_params): | |
target = datetime.date(*input_params) | |
self.assertEqual(three_months_from(target), datetime.date(*output_params)) | |
def test_20130331(self): | |
self._test_date((2013, 3, 31), (2013, 6, 30)) | |
def test_20130401(self): | |
self._test_date((2013, 4, 1), (2013, 7, 1)) | |
def test_20131129(self): | |
self._test_date((2013, 11, 29), (2014, 2, 28)) | |
def test_20131130(self): | |
self._test_date((2013, 11, 30), (2014, 2, 28)) | |
def test_20151129(self): | |
self._test_date((2015, 11, 29), (2016, 2, 29)) | |
def test_20151130(self): | |
self._test_date((2015, 11, 30), (2016, 2, 29)) | |
if __name__ == '__main__': | |
unittest.main() | |
# Result: | |
# ...... | |
# ---------------------------------------------------------------------- | |
# Ran 6 tests in 0.001s | |
# | |
# OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment