本文整理汇总了Python中datetime.timedelta.max方法的典型用法代码示例。如果您正苦于以下问题:Python timedelta.max方法的具体用法?Python timedelta.max怎么用?Python timedelta.max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datetime.timedelta
的用法示例。
在下文中一共展示了timedelta.max方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extreme_ordinals
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_extreme_ordinals(self):
a = self.theclass.min
a = self.theclass(a.year, a.month, a.day) # get rid of time parts
aord = a.toordinal()
b = a.fromordinal(aord)
self.assertEqual(a, b)
self.assertRaises(ValueError, lambda: a.fromordinal(aord - 1))
b = a + timedelta(days=1)
self.assertEqual(b.toordinal(), aord + 1)
self.assertEqual(b, self.theclass.fromordinal(aord + 1))
a = self.theclass.max
a = self.theclass(a.year, a.month, a.day) # get rid of time parts
aord = a.toordinal()
b = a.fromordinal(aord)
self.assertEqual(a, b)
self.assertRaises(ValueError, lambda: a.fromordinal(aord + 1))
b = a - timedelta(days=1)
self.assertEqual(b.toordinal(), aord - 1)
self.assertEqual(b, self.theclass.fromordinal(aord - 1))
示例2: format_ad_timedelta
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def format_ad_timedelta(raw_value):
"""
Convert a negative filetime value to a timedelta.
"""
# Active Directory stores attributes like "minPwdAge" as a negative
# "filetime" timestamp, which is the number of 100-nanosecond intervals that
# have elapsed since the 0 hour on January 1, 1601.
#
# Handle the minimum value that can be stored in a 64 bit signed integer.
# See https://docs.microsoft.com/en-us/dotnet/api/system.int64.minvalue
# In attributes like "maxPwdAge", this signifies never.
if raw_value == b'-9223372036854775808':
return timedelta.max
# We can reuse format_ad_timestamp to get a datetime object from the
# timestamp. Afterwards, we can subtract a datetime representing 0 hour on
# January 1, 1601 from the returned datetime to get the timedelta.
return format_ad_timestamp(raw_value) - format_ad_timestamp(0)
示例3: test_max_runs_when_no_files
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_max_runs_when_no_files(self):
child_pipe, parent_pipe = multiprocessing.Pipe()
with TemporaryDirectory(prefix="empty-airflow-dags-") as dags_folder:
async_mode = 'sqlite' not in conf.get('core', 'sql_alchemy_conn')
manager = DagFileProcessorManager(
dag_directory=dags_folder,
max_runs=1,
processor_factory=FakeDagFileProcessorRunner._fake_dag_processor_factory,
processor_timeout=timedelta.max,
signal_conn=child_pipe,
dag_ids=[],
pickle_dags=False,
async_mode=async_mode)
self.run_processor_manager_one_loop(manager, parent_pipe)
child_pipe.close()
parent_pipe.close()
示例4: test_set_file_paths_when_processor_file_path_not_in_new_file_paths
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_set_file_paths_when_processor_file_path_not_in_new_file_paths(self):
manager = DagFileProcessorManager(
dag_directory='directory',
max_runs=1,
processor_factory=MagicMock().return_value,
processor_timeout=timedelta.max,
signal_conn=MagicMock(),
dag_ids=[],
pickle_dags=False,
async_mode=True)
mock_processor = MagicMock()
mock_processor.stop.side_effect = AttributeError(
'DagFileProcessor object has no attribute stop')
mock_processor.terminate.side_effect = None
manager._processors['missing_file.txt'] = mock_processor
manager._file_stats['missing_file.txt'] = DagFileStat(0, 0, None, None, 0)
manager.set_file_paths(['abc.txt'])
self.assertDictEqual(manager._processors, {})
示例5: test_set_file_paths_when_processor_file_path_is_in_new_file_paths
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_set_file_paths_when_processor_file_path_is_in_new_file_paths(self):
manager = DagFileProcessorManager(
dag_directory='directory',
max_runs=1,
processor_factory=MagicMock().return_value,
processor_timeout=timedelta.max,
signal_conn=MagicMock(),
dag_ids=[],
pickle_dags=False,
async_mode=True)
mock_processor = MagicMock()
mock_processor.stop.side_effect = AttributeError(
'DagFileProcessor object has no attribute stop')
mock_processor.terminate.side_effect = None
manager._processors['abc.txt'] = mock_processor
manager.set_file_paths(['abc.txt'])
self.assertDictEqual(manager._processors, {'abc.txt': mock_processor})
示例6: test_parse_once
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_parse_once(self):
test_dag_path = os.path.join(TEST_DAG_FOLDER, 'test_scheduler_dags.py')
async_mode = 'sqlite' not in conf.get('core', 'sql_alchemy_conn')
processor_agent = DagFileProcessorAgent(test_dag_path,
1,
type(self)._processor_factory,
timedelta.max,
[],
False,
async_mode)
processor_agent.start()
parsing_result = []
if not async_mode:
processor_agent.run_single_parsing_loop()
while not processor_agent.done:
if not async_mode:
processor_agent.wait_until_finished()
parsing_result.extend(processor_agent.harvest_simple_dags())
dag_ids = [result.dag_id for result in parsing_result]
self.assertEqual(dag_ids.count('test_start_date_scheduling'), 1)
示例7: test_launch_process
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_launch_process(self):
test_dag_path = os.path.join(TEST_DAG_FOLDER, 'test_scheduler_dags.py')
async_mode = 'sqlite' not in conf.get('core', 'sql_alchemy_conn')
log_file_loc = conf.get('logging', 'DAG_PROCESSOR_MANAGER_LOG_LOCATION')
try:
os.remove(log_file_loc)
except OSError:
pass
# Starting dag processing with 0 max_runs to avoid redundant operations.
processor_agent = DagFileProcessorAgent(test_dag_path,
0,
type(self)._processor_factory,
timedelta.max,
[],
False,
async_mode)
processor_agent.start()
if not async_mode:
processor_agent.run_single_parsing_loop()
processor_agent._process.join()
self.assertTrue(os.path.isfile(log_file_loc))
示例8: do_pull_minutes_active
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def do_pull_minutes_active(property: str, start_time: datetime, end_time: datetime,
realm: Optional[Realm] = None) -> int:
user_activity_intervals = UserActivityInterval.objects.filter(
end__gt=start_time, start__lt=end_time,
).select_related(
'user_profile',
).values_list(
'user_profile_id', 'user_profile__realm_id', 'start', 'end')
seconds_active: Dict[Tuple[int, int], float] = defaultdict(float)
for user_id, realm_id, interval_start, interval_end in user_activity_intervals:
if realm is None or realm.id == realm_id:
start = max(start_time, interval_start)
end = min(end_time, interval_end)
seconds_active[(user_id, realm_id)] += (end - start).total_seconds()
rows = [UserCount(user_id=ids[0], realm_id=ids[1], property=property,
end_time=end_time, value=int(seconds // 60))
for ids, seconds in seconds_active.items() if seconds >= 60]
UserCount.objects.bulk_create(rows)
return len(rows)
示例9: test_overflow
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_overflow(self):
tiny = timedelta.resolution
td = timedelta.min + tiny
td -= tiny # no problem
self.assertRaises(OverflowError, td.__sub__, tiny)
self.assertRaises(OverflowError, td.__add__, -tiny)
td = timedelta.max - tiny
td += tiny # no problem
self.assertRaises(OverflowError, td.__add__, tiny)
self.assertRaises(OverflowError, td.__sub__, -tiny)
self.assertRaises(OverflowError, lambda: -timedelta.max)
day = timedelta(1)
self.assertRaises(OverflowError, day.__mul__, 10**9)
self.assertRaises(OverflowError, day.__mul__, 1e9)
self.assertRaises(OverflowError, day.__truediv__, 1e-20)
self.assertRaises(OverflowError, day.__truediv__, 1e-10)
self.assertRaises(OverflowError, day.__truediv__, 9e-10)
示例10: test_non_abstractness
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_non_abstractness(self):
# In order to allow subclasses to get pickled, the C implementation
# wasn't able to get away with having __init__ raise
# NotImplementedError.
useless = tzinfo()
dt = datetime.max
self.assertRaises(NotImplementedError, useless.tzname, dt)
self.assertRaises(NotImplementedError, useless.utcoffset, dt)
self.assertRaises(NotImplementedError, useless.dst, dt)
示例11: test_resolution_info
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_resolution_info(self):
self.assertIsInstance(timedelta.min, timedelta)
self.assertIsInstance(timedelta.max, timedelta)
self.assertIsInstance(timedelta.resolution, timedelta)
self.assertTrue(timedelta.max > timedelta.min)
self.assertEqual(timedelta.min, timedelta(-999999999))
self.assertEqual(timedelta.max, timedelta(999999999, 24*3600-1, 1e6-1))
self.assertEqual(timedelta.resolution, timedelta(0, 0, 1))
示例12: test_overflow
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_overflow(self):
tiny = timedelta.resolution
td = timedelta.min + tiny
td -= tiny # no problem
self.assertRaises(OverflowError, td.__sub__, tiny)
self.assertRaises(OverflowError, td.__add__, -tiny)
td = timedelta.max - tiny
td += tiny # no problem
self.assertRaises(OverflowError, td.__add__, tiny)
self.assertRaises(OverflowError, td.__sub__, -tiny)
self.assertRaises(OverflowError, lambda: -timedelta.max)
示例13: test_extreme_timedelta
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_extreme_timedelta(self):
big = self.theclass.max - self.theclass.min
# 3652058 days, 23 hours, 59 minutes, 59 seconds, 999999 microseconds
n = (big.days*24*3600 + big.seconds)*1000000 + big.microseconds
# n == 315537897599999999 ~= 2**58.13
justasbig = timedelta(0, 0, n)
self.assertEqual(big, justasbig)
self.assertEqual(self.theclass.min + big, self.theclass.max)
self.assertEqual(self.theclass.max - big, self.theclass.min)
示例14: test_bool
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def test_bool(self):
# All dates are considered true.
self.assertTrue(self.theclass.min)
self.assertTrue(self.theclass.max)
示例15: valid_date_stop
# 需要导入模块: from datetime import timedelta [as 别名]
# 或者: from datetime.timedelta import max [as 别名]
def valid_date_stop(date_stop):
""" checks, whether date_stop has a valid value """
if not date_stop:
date_stop = Bank_Date.max
return date_stop