本文整理汇总了Python中interpreter.Interpreter._interpret_relative_modifier方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter._interpret_relative_modifier方法的具体用法?Python Interpreter._interpret_relative_modifier怎么用?Python Interpreter._interpret_relative_modifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter._interpret_relative_modifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InterpreterTest
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import _interpret_relative_modifier [as 别名]
#.........这里部分代码省略.........
time_modifier = mods[2]
self.assertEqual('3:01', time_modifier)
def test_interpret_time_modifier(self):
self.assertEqual(
time(hour=3, minute=1),
self.interpreter._interpret_time_modifier('3:01'))
self.assertEqual(
time(hour=15, minute=59),
self.interpreter._interpret_time_modifier('15:59'))
self.assertEqual(
time(hour=23, minute=59),
self.interpreter._interpret_time_modifier('23:59'))
self.assertEqual(
time(hour=1, minute=1),
self.interpreter._interpret_time_modifier('01:1'))
def test_interpret_invalid_time_modifier(self):
self.assertRaises(
AbsoluteTimeModifierException,
self.interpreter._interpret_time_modifier, '24:00')
self.assertRaises(
AbsoluteTimeModifierException,
self.interpreter._interpret_time_modifier, '23:60')
self.assertRaises(
AbsoluteTimeModifierException,
self.interpreter._interpret_time_modifier, '12:63')
def test_interpret_relative_modifier(self):
self.assertEqual(
timedelta(days=1),
self.interpreter._interpret_relative_modifier('+1d'))
self.assertEqual(
timedelta(days=-2),
self.interpreter._interpret_relative_modifier('-2d'))
self.assertEqual(
timedelta(days=10),
self.interpreter._interpret_relative_modifier('+10d'))
self.assertEqual(
timedelta(hours=123),
self.interpreter._interpret_relative_modifier('+0123h'))
self.assertEqual(
timedelta(hours=-23),
self.interpreter._interpret_relative_modifier('-23h'))
self.assertEqual(
timedelta(minutes=-50),
self.interpreter._interpret_relative_modifier('-050m'))
self.assertEqual(
timedelta(minutes=106),
self.interpreter._interpret_relative_modifier('+106m'))
self.assertEqual(
timedelta(weeks=-2),
self.interpreter._interpret_relative_modifier('-2w'))
示例2: InterpreterTest
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import _interpret_relative_modifier [as 别名]
#.........这里部分代码省略.........
mods = self.interpreter._get_modifiers_as_string("[email protected]:59")
time_modifier = mods[2]
self.assertEqual("10:59", time_modifier)
mods = self.interpreter._get_modifiers_as_string("[email protected]:59")
time_modifier = mods[2]
self.assertEqual("23:59", time_modifier)
mods = self.interpreter._get_modifiers_as_string("[email protected]:11")
time_modifier = mods[2]
self.assertEqual("22:11", time_modifier)
mods = self.interpreter._get_modifiers_as_string("[email protected]:01")
time_modifier = mods[2]
self.assertEqual("3:01", time_modifier)
def test_interpret_time_modifier(self):
self.assertEqual(time(hour=3, minute=1), self.interpreter._interpret_time_modifier("3:01"))
self.assertEqual(time(hour=15, minute=59), self.interpreter._interpret_time_modifier("15:59"))
self.assertEqual(time(hour=23, minute=59), self.interpreter._interpret_time_modifier("23:59"))
self.assertEqual(time(hour=1, minute=1), self.interpreter._interpret_time_modifier("01:1"))
def test_interpret_invalid_time_modifier(self):
self.assertRaises(AbsoluteTimeModifierException, self.interpreter._interpret_time_modifier, "24:00")
self.assertRaises(AbsoluteTimeModifierException, self.interpreter._interpret_time_modifier, "23:60")
self.assertRaises(AbsoluteTimeModifierException, self.interpreter._interpret_time_modifier, "12:63")
def test_interpret_relative_modifier(self):
self.assertEqual(timedelta(days=1), self.interpreter._interpret_relative_modifier("+1d"))
self.assertEqual(timedelta(days=-2), self.interpreter._interpret_relative_modifier("-2d"))
self.assertEqual(timedelta(hours=123), self.interpreter._interpret_relative_modifier("+0123h"))
self.assertEqual(timedelta(hours=-23), self.interpreter._interpret_relative_modifier("-23h"))
self.assertEqual(timedelta(minutes=-50), self.interpreter._interpret_relative_modifier("-050m"))
self.assertEqual(timedelta(minutes=106), self.interpreter._interpret_relative_modifier("+106m"))
self.assertEqual(timedelta(weeks=-2), self.interpreter._interpret_relative_modifier("-2w"))
self.assertEqual(timedelta(weeks=4), self.interpreter._interpret_relative_modifier("+4w"))
def test_build_new_date_from_event(self):
expected = arrow.get(2000, 1, 1, 0, 1).datetime
actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1).datetime, timedelta(minutes=1), None)
self.assertEqual(expected, actual)
expected = arrow.get(2000, 1, 1).datetime
actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1, 0, 2).datetime, timedelta(minutes=-2), None)
self.assertEqual(expected, actual)
expected = arrow.get(2000, 1, 1, 3).datetime
actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1).datetime, timedelta(hours=3), None)
self.assertEqual(expected, actual)
expected = arrow.get(1999, 12, 31).datetime
actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1).datetime, timedelta(days=-1), None)
self.assertEqual(expected, actual)