Skip to content

Commit

Permalink
Make timing tests less sensitive to slow test execution*
Browse files Browse the repository at this point in the history
* See https://travis-ci.org/xolox/python-humanfriendly/jobs/28706938 but
  the same thing can happen anywhere. When looked at from that perspective
  the fix I'm committing here really isn't a fix, but I suspect it will be
  fine :-)
  • Loading branch information
xolox committed Jun 29, 2014
1 parent dad593c commit 32330ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion humanfriendly.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# URL: https://humanfriendly.readthedocs.org

# Semi-standard module versioning.
__version__ = '1.9.4'
__version__ = '1.9.5'

# Standard library modules.
import math
Expand Down
9 changes: 5 additions & 4 deletions humanfriendly_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ def test_timer(self):
# Test automatic timer.
automatic_timer = humanfriendly.Timer()
time.sleep(1)
self.assertEqual(humanfriendly.round_number(automatic_timer.elapsed_time, keep_width=True), '1.00')
self.assertEqual(str(automatic_timer), '1.00 second')
self.assertEqual(normalize_timestamp(humanfriendly.round_number(automatic_timer.elapsed_time, keep_width=True)), '1.00')
# Test resumable timer.
resumable_timer = humanfriendly.Timer(resumable=True)
for i in range(2):
with resumable_timer:
time.sleep(1)
self.assertEqual(humanfriendly.round_number(resumable_timer.elapsed_time, keep_width=True), '2.00')
self.assertEqual(str(resumable_timer), '2.00 seconds')
self.assertEqual(normalize_timestamp(humanfriendly.round_number(resumable_timer.elapsed_time, keep_width=True)), '2.00')

def test_spinner(self):
stream = StringIO()
Expand Down Expand Up @@ -159,5 +157,8 @@ def test_prompt_for_choice(self):
finally:
humanfriendly.interactive_prompt = interactive_prompt

def normalize_timestamp(value, ndigits=1):
return '%.2f' % round(float(value), ndigits=ndigits)

if __name__ == '__main__':
unittest.main()

0 comments on commit 32330ad

Please sign in to comment.