From 9406a387a2d618c3d9528d53ba4c61b5e0f1b6f7 Mon Sep 17 00:00:00 2001 From: RussellBallestrini Date: Mon, 7 Jan 2013 21:57:22 -0500 Subject: [PATCH] moved test to its own file --- ago.py | 28 +++------------------------- test_ago.py | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 test_ago.py diff --git a/ago.py b/ago.py index 16a0284..14f93b9 100644 --- a/ago.py +++ b/ago.py @@ -30,29 +30,7 @@ def human( d1, precision = 2 ): delta = d2 - d1 if d2 < d1: delta = d1 - d2 return delta2human( delta, precision ) - -def test(): - """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 '\nTesting future:\n' - print delta2dict( fdelta ) - print 'Shutdown in ' + delta2human( fdelta, 3 ) - print 'Shutdown in ' + human( future ) - print '' - -if __name__ == "__main__": test() +if __name__ == "__main__": + from test_ago import test_output + test_output() diff --git a/test_ago.py b/test_ago.py new file mode 100644 index 0000000..152a36c --- /dev/null +++ b/test_ago.py @@ -0,0 +1,27 @@ +from ago import human +from ago import delta2dict +from ago import delta2human + +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 '\nTesting future:\n' + print delta2dict( fdelta ) + print 'Shutdown in ' + delta2human( fdelta, 3 ) + print 'Shutdown in ' + human( future ) + print '' +