Created
April 18, 2012 14:00
-
-
Save kipanshi/2413788 to your computer and use it in GitHub Desktop.
Mock datetime.now() for testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FakeDatetimeFactory(object): | |
| """Factory to help testing logic depending on ``datetime.now()``. | |
| """ | |
| @classmethod | |
| def now(self, *args, **kwargs): | |
| class FakeDatetime(datetime): | |
| """Datetime class with overriden ``now()`` method.""" | |
| @classmethod | |
| def now(cls): | |
| return cls(*args, **kwargs) | |
| return FakeDatetime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment