forked from fgaudin/aemanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatetimestub.py
47 lines (39 loc) · 1.29 KB
/
datetimestub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import datetime as datetime_orig
class DatetimeStub(object):
"""
A datetimestub object to replace methods and classes from
the datetime module.
Usage:
import sys
sys.modules['datetime'] = DatetimeStub()
"""
class datetime(datetime_orig.datetime):
mock_year = 2010
mock_month = 10
mock_day = 25
@classmethod
def now(cls):
"""
Override the datetime.now() method to return a
datetime one year in the future
"""
result = datetime_orig.datetime.now()
return result.replace(year=cls.mock_year, month=cls.mock_month, day=cls.mock_day)
class date(datetime_orig.date):
mock_year = 2010
mock_month = 10
mock_day = 25
@classmethod
def today(cls):
"""
Override the date.today() method to return a
date one year in the future
"""
result = datetime_orig.date.today()
return result.replace(year=cls.mock_year, month=cls.mock_month, day=cls.mock_day)
def __getattr__(self, attr):
"""
Get the default implementation for the classes and methods
from datetime that are not replaced
"""
return getattr(datetime_orig, attr)