Added 4 tests, more test coverage needed
This commit is contained in:
parent
9406a387a2
commit
846593e20b
1 changed files with 26 additions and 16 deletions
42
test_ago.py
42
test_ago.py
|
|
@ -1,27 +1,37 @@
|
|||
from ago import human
|
||||
from ago import delta2dict
|
||||
from ago import delta2human
|
||||
from ago import delta2dict
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
PRESENT = datetime.now()
|
||||
PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, ms
|
||||
FUTURE = PRESENT + timedelta( 2, 12447, 963 ) # days, secs, ms
|
||||
|
||||
PAST_DELTA = PRESENT - PAST
|
||||
FUTURE_DELTA = FUTURE - PRESENT
|
||||
|
||||
def test_human_is_string():
|
||||
assert 'str' in str(type(human( PAST )))
|
||||
|
||||
def test_delta2human_is_string():
|
||||
assert 'str' in str(type(delta2human( PAST_DELTA )))
|
||||
|
||||
def test_delta2dict_is_dict():
|
||||
assert 'dict' in str(type(delta2dict( PAST_DELTA )))
|
||||
|
||||
def test_output():
|
||||
"""Test and example usage"""
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
present = datetime.now()
|
||||
past = present - timedelta( 492, 58711, 45 ) # days, secs, ms
|
||||
future = present + timedelta( 2, 12447, 963 ) # days, secs, ms
|
||||
|
||||
pdelta = present - past
|
||||
fdelta = future - present
|
||||
|
||||
print '\nTesting past:\n'
|
||||
print delta2dict( pdelta )
|
||||
print 'Commented ' + delta2human( pdelta, 3 ) + ' ago'
|
||||
print 'Commented ' + human( past ) + ' ago'
|
||||
print delta2dict( PAST_DELTA )
|
||||
print 'Commented ' + delta2human( PAST_DELTA, 3 ) + ' ago'
|
||||
print 'Commented ' + human( PAST ) + ' ago'
|
||||
|
||||
print '\nTesting future:\n'
|
||||
print delta2dict( fdelta )
|
||||
print 'Shutdown in ' + delta2human( fdelta, 3 )
|
||||
print 'Shutdown in ' + human( future )
|
||||
print delta2dict( FUTURE_DELTA )
|
||||
print 'Shutdown in ' + delta2human( FUTURE_DELTA, 3 )
|
||||
print 'Shutdown in ' + human( FUTURE )
|
||||
print ''
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue