wrote a failing test case to prove that my most recent counter removal commit

caused a hidden functional bug.  Next commit should alter ago.py to make this te
st pass.

test_zero_day_is_skipped_display_hour()
This commit is contained in:
RussellBallestrini 2013-05-23 09:27:41 -04:00
parent 49ff995130
commit 76847a986a

View file

@ -7,16 +7,22 @@ from types import DictType
from ago import human
from ago import delta2dict
# datetime objects
PRESENT = datetime.now()
PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, ms
FUTURE = PRESENT + timedelta( 2, 12447, 963 ) # days, secs, ms
# timedelta objects
PAST_DELTA = PRESENT - PAST
FUTURE_DELTA = PRESENT - FUTURE
ONE_YEAR_FOUR_HOURS_DELTA = timedelta( 365, 14400, 0 )
def test_human_is_string():
def test_human_passed_datetime_is_string():
assert type(human( PAST )) is StringType
def test_human_passed_timedelta_is_string():
assert type(human( PAST_DELTA )) is StringType
def test_delta2dict_is_dict():
assert type(delta2dict( PAST_DELTA )) is DictType
@ -34,6 +40,16 @@ def test_coma_in_three_precision():
assert ',' in human( PAST, precision = 3 )
assert ',' in human( FUTURE, precision = 3 )
def test_coma_in_out_of_bounds_precision():
assert ',' in human( PAST, precision = 10 )
assert ',' in human( FUTURE, precision = 10 )
def test_zero_day_is_skipped_display_hour():
_result = human( ONE_YEAR_FOUR_HOURS_DELTA, precision = 2 )
assert 'year' in _result
# day is 0 so it is skipped, so we should show hours ...
assert 'hour' in _result
def test_one_day_singular():
assert 's' not in human( timedelta(1) )
@ -70,6 +86,7 @@ def test_valid_future_dict():
assert past_dict['minute'] == 27
assert past_dict['microsecond'] == 963
def example_usage():
"""Test and example usage"""
@ -78,9 +95,13 @@ def example_usage():
print 'Commented ' + human( PAST_DELTA, 1 )
print human( PAST, past_tense = "Commented {} ago" )
print human( ONE_YEAR_FOUR_HOURS_DELTA, past_tense = "Posted {} ago" )
print '\nTest future tense:\n'
print delta2dict( FUTURE_DELTA )
print 'Shutdown ' + human( FUTURE_DELTA, 5 )
print human( FUTURE, future_tense = 'Shutdown in {} from now' )
print ''
if __name__ == '__main__':
example_usage()