Example #1
0
	def should_use_custom_separator_for_entry_tuple(self):
		task = TaskWarrior(Config(separator='__'))
		task.start('foo')
		task.start('bar')
		self.assertTrue('__foo' in task.config.taskfile.read_text())
		task.stop()
		self.assertEqual([_.title for _ in task.get_history()], ['foo', 'bar', None])
Example #2
0
	def should_recognize_isodate_without_msecs(self):
		task = TaskWarrior(Config(separator='__'))
		task.config.taskfile.write_text(six.text_type('\n'.join([
			'{0}\tfoo'.format(datetime.datetime(2021, 12, 31, 8, 0, 0).isoformat().split('.', 1)[0]),
			'{0}\tbar'.format(datetime.datetime(2021, 12, 31, 8, 10, 0).isoformat()),
			'{0}'.format(datetime.datetime(2021, 12, 31, 8, 30, 0).isoformat()),
			]) + '\n'))
		self.assertEqual([_.title for _ in task.get_history()], ['foo', 'bar', None])
Example #3
0
	def should_try_to_guess_separator_for_line(self):
		task = TaskWarrior(Config(separator='__'))
		task.config.taskfile.write_text(six.text_type('\n'.join([
			'{0}__foo'.format(datetime.datetime(2021, 12, 31, 8, 0, 0).isoformat()),
			'{0}\tbar with space'.format(datetime.datetime(2021, 12, 31, 8, 10, 0).isoformat()),
			'{0} baz with space'.format(datetime.datetime(2021, 12, 31, 8, 20, 0).isoformat()),
			'{0}'.format(datetime.datetime(2021, 12, 31, 8, 30, 0).isoformat()),
			]) + '\n'))
		self.assertEqual([_.title for _ in task.get_history()], ['foo', 'bar with space', 'baz with space', None])
Example #4
0
	def should_rewrite_task_history_automatically(self):
		task = TaskWarrior(Config(separator='__'))
		task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 0, 0))
		task.start('bar', now=datetime.datetime(2021, 12, 31, 8, 1, 0))
		task.stop(now=datetime.datetime(2021, 12, 31, 8, 2, 0))
		task.start(now=datetime.datetime(2021, 12, 31, 8, 3, 0))
		task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 4, 0))

		with self.assertRaises(RuntimeError):
			task.rewrite_history(
					datetime.datetime(2021, 12, 31, 8, 2, 0),
					datetime.datetime(2021, 12, 31, 8, 3, 0),
					['baz', 'baz', 'excessive'],
					)
		with self.assertRaises(RuntimeError):
			task.rewrite_history(
					datetime.datetime(2021, 12, 31, 8, 2, 0),
					datetime.datetime(2021, 12, 31, 8, 3, 0),
					['not enough values'],
					)

		task.rewrite_history(
				datetime.datetime(2021, 12, 31, 8, 2, 0),
				datetime.datetime(2021, 12, 31, 8, 3, 0),
				['baz', 'baz'],
				)
		self.assertEqual([_.title for _ in task.get_history()], [
			'foo', 'bar',
			'baz', 'baz',
			'foo',
			])
		task.rewrite_history(
				datetime.datetime(2021, 12, 31, 8, 2, 0),
				datetime.datetime(2021, 12, 31, 8, 3, 0),
				['foo', None],
				)
		self.assertEqual([_.title for _ in task.get_history()], [
			'foo', 'bar',
			'foo', None,
			'foo',
			])
Example #5
0
	def should_not_consider_consequent_tasks_as_resume(self):
		task = TaskWarrior()
		task.start('foo')
		task.start('foo')
		task.stop()
		task.start()
		task.stop()
		task.start('foo')
		history = list(task.get_history())
		self.assertFalse(history[0].is_resume)
		self.assertFalse(history[1].is_resume)
		self.assertTrue(history[2].is_stop)
		self.assertTrue(history[3].is_resume)
		self.assertTrue(history[4].is_stop)
		self.assertTrue(history[5].is_resume)
Example #6
0
	def should_rewrite_task_history_with_fill_value(self):
		task = TaskWarrior(Config(separator='__'))
		task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 0, 0))
		task.start('bar', now=datetime.datetime(2021, 12, 31, 8, 1, 0))
		task.stop(now=datetime.datetime(2021, 12, 31, 8, 2, 0))
		task.start(now=datetime.datetime(2021, 12, 31, 8, 3, 0))
		task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 4, 0))

		task.rewrite_history(
				datetime.datetime(2021, 12, 31, 8, 2, 0),
				datetime.datetime(2021, 12, 31, 8, 3, 0),
				['foo'],
				fill_value='baz'
				)
		self.assertEqual([_.title for _ in task.get_history()], [
			'foo', 'bar',
			'foo', 'baz',
			'foo',
			])
Example #7
0
	def should_list_task_history(self):
		task = TaskWarrior()
		task.start('foo')
		task.start('bar')
		task.stop()
		self.assertEqual([_.title for _ in task.get_history()], ['foo', 'bar', None])
Example #8
0
	def should_use_custom_aliases_for_stop_and_resume(self):
		task = TaskWarrior(Config(
			resume_alias='UNLOCK',
			stop_alias='LOCK',
			))

		task.config.taskfile.write_text(six.text_type('\n'.join([
			'{0} foo'.format(datetime.datetime(2021, 12, 31, 8, 0, 0).isoformat()),
			'{0} LOCK'.format(datetime.datetime(2021, 12, 31, 8, 10, 0).isoformat()),
			'{0} UNLOCK'.format(datetime.datetime(2021, 12, 31, 8, 30, 0).isoformat()),
			]) + '\n'))
		history = list(task.get_history())
		self.assertEqual(len(history), 3)
		self.assertFalse(history[0].is_resume)
		self.assertFalse(history[0].is_stop)
		self.assertFalse(history[1].is_resume)
		self.assertTrue(history[1].is_stop)
		self.assertTrue(history[2].is_resume)
		self.assertFalse(history[2].is_stop)
		self.assertEqual(task.get_current_task(), 'foo')

		task.config.taskfile.write_text(six.text_type('\n'.join([
			'{0} foo'.format(datetime.datetime(2021, 12, 31, 8, 0, 0).isoformat()),
			'{0} LOCK'.format(datetime.datetime(2021, 12, 31, 8, 10, 0).isoformat()),
			'{0} UNLOCK'.format(datetime.datetime(2021, 12, 31, 8, 30, 0).isoformat()),
			'{0}'.format(datetime.datetime(2021, 12, 31, 8, 0, 0).isoformat()),
			'{0} foo'.format(datetime.datetime(2021, 12, 31, 8, 0, 0).isoformat()),
			]) + '\n'))
		history = list(task.get_history())
		self.assertEqual(len(history), 5)
		self.assertFalse(history[0].is_resume)
		self.assertFalse(history[0].is_stop)
		self.assertFalse(history[1].is_resume)
		self.assertTrue(history[1].is_stop)
		self.assertTrue(history[2].is_resume)
		self.assertFalse(history[2].is_stop)
		self.assertFalse(history[3].is_resume)
		self.assertTrue(history[3].is_stop)
		self.assertTrue(history[4].is_resume)
		self.assertFalse(history[4].is_stop)
		self.assertEqual(task.get_current_task(), 'foo')

		task.config.taskfile.write_text(six.text_type('\n'.join([
			'{0} foo'.format(datetime.datetime(2021, 12, 31, 8, 0, 0).isoformat()),
			'{0} LOCK'.format(datetime.datetime(2021, 12, 31, 8, 10, 0).isoformat()),
			'{0} UNLOCK'.format(datetime.datetime(2021, 12, 31, 8, 30, 0).isoformat()),
			'{0} bar'.format(datetime.datetime(2021, 12, 31, 8, 40, 0).isoformat()),
			'{0} foo'.format(datetime.datetime(2021, 12, 31, 8, 50, 0).isoformat()),
			]) + '\n'))
		history = list(task.get_history())
		self.assertEqual(len(history), 5)
		self.assertFalse(history[0].is_resume)
		self.assertFalse(history[0].is_stop)
		self.assertFalse(history[1].is_resume)
		self.assertTrue(history[1].is_stop)
		self.assertIsNone(history[1].title)
		self.assertTrue(history[2].is_resume)
		self.assertFalse(history[2].is_stop)
		self.assertEqual(history[2].title, 'foo')
		self.assertFalse(history[3].is_resume)
		self.assertFalse(history[3].is_stop)
		self.assertEqual(history[3].title, 'bar')
		self.assertFalse(history[4].is_resume)
		self.assertFalse(history[4].is_stop)
		self.assertEqual(history[4].title, 'foo')
		self.assertEqual(task.get_current_task(), 'foo')