From e95b5d8c103abc06953c5a7e190260dd0610960e Mon Sep 17 00:00:00 2001 From: RussellBallestrini Date: Tue, 25 Feb 2014 11:55:43 -0500 Subject: [PATCH] python3.x merge caused issues with python2.x compat instead of importing division from future we simply use int() to cast floats to integers. nosetests: on python2.7 passes python2 test_ago.py: passes python3 test_ago.py: passes TODO: Does nosetests work with python3.x? branch 'default' changed ago.py changed test_ago.py --- ago.py | 11 +++++------ test_ago.py | 14 +++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ago.py b/ago.py index 4ba3615..d85caff 100644 --- a/ago.py +++ b/ago.py @@ -1,4 +1,3 @@ -from __future__ import division from datetime import datetime from datetime import timedelta @@ -6,11 +5,11 @@ def delta2dict( delta ): """Accepts a delta, returns a dictionary of units""" delta = abs( delta ) return { - 'year' : delta.days // 365 , - 'day' : delta.days % 365 , - 'hour' : delta.seconds // 3600 , - 'minute' : (delta.seconds // 60) % 60 , - 'second' : delta.seconds % 60 , + 'year' : int(delta.days / 365), + 'day' : int(delta.days % 365), + 'hour' : int(delta.seconds / 3600), + 'minute' : int(delta.seconds / 60) % 60, + 'second' : delta.seconds % 60, 'microsecond' : delta.microseconds } diff --git a/test_ago.py b/test_ago.py index a564ef4..31972ce 100644 --- a/test_ago.py +++ b/test_ago.py @@ -4,6 +4,14 @@ from datetime import timedelta from ago import human from ago import delta2dict +try: + from types import StringType as STRING + from types import DictType as DICT +except ImportError: + import builtins + STRING = builtins.str + DICT = builtins.dict + # datetime objects PRESENT = datetime.now() PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, ms @@ -15,13 +23,13 @@ FUTURE_DELTA = PRESENT - FUTURE ONE_YEAR_FOUR_HOURS_DELTA = timedelta( 365, 14400, 0 ) def test_human_passed_datetime_is_string(): - assert type(human( PAST )) is builtins.str + assert type(human( PAST )) is STRING def test_human_passed_timedelta_is_string(): - assert type(human( PAST_DELTA )) is builtins.str + assert type(human( PAST_DELTA )) is STRING def test_delta2dict_is_dict(): - assert type(delta2dict( PAST_DELTA )) is builtins.dict + assert type(delta2dict( PAST_DELTA )) is DICT def test_ago_in_past_human(): assert 'ago' in human( PAST )