MCPcopy
hub / github.com/celery/celery / test_now

Method test_now

t/unit/app/test_app.py:90–119  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

88 self.app.add_defaults(deepcopy(self.CELERY_TEST_CONFIG))
89
90 def test_now(self):
91 timezone_setting_value = 'US/Eastern'
92 tz_utc = timezone.get_timezone('UTC')
93 tz_us_eastern = timezone.get_timezone(timezone_setting_value)
94
95 now = to_utc(datetime.now(datetime_timezone.utc))
96 app_now = self.app.now()
97
98 assert app_now.tzinfo is tz_utc
99 assert app_now - now <= timedelta(seconds=1)
100
101 # Check that timezone conversion is applied from configuration
102 self.app.conf.enable_utc = False
103 self.app.conf.timezone = timezone_setting_value
104 # timezone is a cached property
105 del self.app.timezone
106
107 app_now = self.app.now()
108
109 assert app_now.tzinfo == tz_us_eastern
110
111 diff = to_utc(datetime.now(datetime_timezone.utc)) - localize(app_now, tz_utc)
112 assert diff <= timedelta(seconds=1)
113
114 # Verify that timezone setting overrides enable_utc=on setting
115 self.app.conf.enable_utc = True
116 del self.app.timezone
117 app_now = self.app.now()
118 assert self.app.timezone == tz_us_eastern
119 assert app_now.tzinfo == tz_us_eastern
120
121 @patch('celery.app.base.set_default_app')
122 def test_set_default(self, set_default_app):

Callers

nothing calls this directly

Calls 4

to_utcFunction · 0.90
localizeFunction · 0.90
get_timezoneMethod · 0.80
nowMethod · 0.45

Tested by

no test coverage detected