ago 0.0.5 version
* consolidated human and delta2human * fixed docs and tests to reflect consolidation
This commit is contained in:
parent
1e4fe16b72
commit
a2574a05d8
4 changed files with 48 additions and 45 deletions
29
test_ago.py
29
test_ago.py
|
|
@ -1,10 +1,10 @@
|
|||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from types import *
|
||||
from types import StringType
|
||||
from types import DictType
|
||||
|
||||
from ago import human
|
||||
from ago import delta2human
|
||||
from ago import delta2dict
|
||||
|
||||
PRESENT = datetime.now()
|
||||
|
|
@ -17,9 +17,6 @@ FUTURE_DELTA = PRESENT - FUTURE
|
|||
def test_human_is_string():
|
||||
assert type(human( PAST )) is StringType
|
||||
|
||||
def test_delta2human_is_string():
|
||||
assert type(delta2human( PAST_DELTA )) is StringType
|
||||
|
||||
def test_delta2dict_is_dict():
|
||||
assert type(delta2dict( PAST_DELTA )) is DictType
|
||||
|
||||
|
|
@ -38,10 +35,10 @@ def test_coma_in_three_precision():
|
|||
assert ',' in human( FUTURE, precision = 3 )
|
||||
|
||||
def test_one_day_singular():
|
||||
assert 's' not in delta2human( timedelta(1) )
|
||||
assert 's' not in human( timedelta(1) )
|
||||
|
||||
def test_two_day_plural():
|
||||
assert 's' in delta2human( timedelta(2) )
|
||||
assert 's' in human( timedelta(2) )
|
||||
|
||||
def test_past_tense():
|
||||
output = human( PAST,
|
||||
|
|
@ -57,25 +54,33 @@ def test_future_tense():
|
|||
)
|
||||
assert 'titanic will sink in' in output
|
||||
|
||||
def test_valid_dict():
|
||||
def test_valid_past_dict():
|
||||
past_dict = delta2dict( PAST_DELTA )
|
||||
assert past_dict['year'] == 1
|
||||
assert past_dict['day'] == 127
|
||||
assert past_dict['hour'] == 16
|
||||
assert past_dict['minute'] == 18
|
||||
assert past_dict['microsecond'] == 45
|
||||
|
||||
def test_valid_future_dict():
|
||||
past_dict = delta2dict( FUTURE_DELTA )
|
||||
assert past_dict['year'] == 0
|
||||
assert past_dict['day'] == 2
|
||||
assert past_dict['hour'] == 3
|
||||
assert past_dict['minute'] == 27
|
||||
assert past_dict['microsecond'] == 963
|
||||
|
||||
def test_output():
|
||||
"""Test and example usage"""
|
||||
|
||||
print '\nTesting past:\n'
|
||||
print '\nTest past tense:\n'
|
||||
print delta2dict( PAST_DELTA )
|
||||
print 'Commented ' + delta2human( PAST_DELTA, 3 )
|
||||
print 'Commented ' + human( PAST_DELTA, 1 )
|
||||
print human( PAST, past_tense = "Commented {} ago" )
|
||||
|
||||
print '\nTesting future:\n'
|
||||
print '\nTest future tense:\n'
|
||||
print delta2dict( FUTURE_DELTA )
|
||||
print 'Shutdown ' + delta2human( FUTURE_DELTA, 3 )
|
||||
print 'Shutdown ' + human( FUTURE_DELTA, 5 )
|
||||
print human( FUTURE, future_tense = 'Shutdown in {} from now' )
|
||||
print ''
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue