-
-
Save kiorky/3799064 to your computer and use it in GitHub Desktop.
test datetime monkey patch
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__docformat__ = 'restructuredtext en' | |
from datetime import datetime | |
class Foo(object): | |
def test(self): | |
print repr(datetime) | |
# vim:set et sts=4 ts=4 tw=80: |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__docformat__ = 'restructuredtext en' | |
import datetime | |
class Foo(object): | |
def test(self): | |
print repr(datetime.datetime) | |
# vim:set et sts=4 ts=4 tw=80: |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__docformat__ = 'restructuredtext en' | |
import datetime | |
def monkey(): | |
class _datetime(datetime.datetime): | |
def __repr__(self): | |
return 'overiden' | |
datetime.old_datetime = datetime.datetime | |
datetime.datetime = _datetime | |
import a, b | |
# if the monkey patch happen after the loading of croniter, we are dead | |
# if we really on import cache (from datetime import datetime instead of | |
# datetime.datetime) | |
monkey() | |
a.Foo().test() | |
b.Foo().test() | |
# a.py | |
#from datetime import datetime | |
#class Foo(object): | |
# def test(self): | |
# print repr(datetime) | |
#b.py | |
#import datetime | |
#class Foo(object): | |
# def test(self): | |
# print repr(datetime.datetime) | |
# execution should return: | |
""" | |
<type 'datetime.datetime'> | |
<class '__main__._datetime'> | |
""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment