Skip to content

Instantly share code, notes, and snippets.

@eswald
Created April 30, 2015 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eswald/098120b5aca16d01a080 to your computer and use it in GitHub Desktop.
Save eswald/098120b5aca16d01a080 to your computer and use it in GitHub Desktop.
TimestampMixin
from datetime import datetime, timedelta
class TimestampMixin(object):
r'''Adds assertTimestamped to TestCase classes.
Checks that the given field contains a time between the beginning of
the test run and the assertion.
'''#"""#'''
def setUp(self):
super(TimestampMixin, self).setUp()
self.started = datetime.now()
def assertTimestamped(self, when, delta=timedelta()):
self.assertIsNotNone(when)
self.assertLessEqual(self.started + delta, when)
self.assertLessEqual(when, datetime.now() + delta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment