def test_list_with_criteria(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         o = c.handle('list', '2', '4')
         self.assertEqual(o, '     2  b\n     4  d')
 def test_list_plans(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'plans.txt')
         p.write_text('2019-01-04|g\n2019-02-05|p')
         c = Commander(root=t)
         o = c.handle('list', '--queue', 'plans')
         self.assertEqual(o, '     1  2019-01-04  g\n     2  2019-02-05  p')
Beispiel #3
0
 def test_add(self):
     with TemporaryDirectory() as t:
         c = Commander(root=t)
         with mock.patch('sys.stdin', StringIO('g')):
             c.handle('add', '--queue', 'j')
             x = Path(t, 'j.txt').read_text()
             self.assertEqual(x, 'g\n')
Beispiel #4
0
 def test_start_fails_gracefully_if_no_project_at_top(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb #g')
         c = Commander(root=t)
         with self.assertRaises(RuntimeError):
             c.handle('start')
Beispiel #5
0
 def test_get_from(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'a.txt')
         p.write_text('b\n')
         c = Commander(root=t)
         o = c.handle('get', '--queue', 'a')
         self.assertEqual(o, 'b')
Beispiel #6
0
 def test_no_output(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\n')
         c = Commander(root=t)
         o = c.handle('drop','1')
         self.assertEqual(o, None)
Beispiel #7
0
 def test_default_queue(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('b\n')
         c = Commander(root=t)
         o = c.handle('get')
         self.assertEqual(o, 'b')
Beispiel #8
0
 def test_get_with_criteria(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         with self.assertRaises(RuntimeError):
             c.handle('get', '3-4')
Beispiel #9
0
 def test_get(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         o = c.handle('get')
         self.assertEqual(o, 'a')
Beispiel #10
0
 def test_start_fails_if_criteria(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb #g\nc #k\nd #g')
         c = Commander(root=t)
         with self.assertRaises(RuntimeError):
             c.handle('start', 'g', '4')
Beispiel #11
0
 def test_start_pops_tasks_for_current_project(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a #k\nb #g\nc #k\nd #g')
         c = Commander(root=t)
         c.handle('start')
         o = p.read_text()
         self.assertEqual(o, 'a #k\nc #k\nb #g\nd #g\n')
Beispiel #12
0
 def test_start_works_for_named_project(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb #g\nc #k\nd #g')
         c = Commander(root=t)
         o = c.handle('start', 'g')
         f = p.read_text()
         self.assertEqual(f, 'b #g\nd #g\na\nc #k\n')
Beispiel #13
0
 def test_drop(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'u.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         c.handle('drop', '2', '4', '--queue', 'u')
         o = p.read_text()
         self.assertEqual(o, 'a\nc\nb\nd\n')
Beispiel #14
0
 def test_repeat_parse_fail(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a>repeat in x\n')
         c = Commander(root=t)
         with mock.patch('busy.dateparser.today', lambda : Date(2019,2,11)):
             with self.assertRaises(RuntimeError):
                 c.handle('finish','--yes')
Beispiel #15
0
 def test_followon(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a>b\n')
         c = Commander(root=t)
         c.handle('finish','--yes')
         o = p.read_text()
         self.assertEqual(o, 'b\n')
Beispiel #16
0
 def test_slashes(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a')
         c = Commander(root=t)
         c.handle('defer','--to','2019/09/06')
         o2 = Path(t, 'plans.txt').read_text()
         self.assertEqual(o2, '2019-09-06|a\n')
Beispiel #17
0
 def test_pop(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         c.handle('pop','2','4')
         o = p.read_text()
         self.assertEqual(o, 'b\nd\na\nc\n')
Beispiel #18
0
 def test_delete(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'w.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         c.handle('delete', '--yes', '3-', '--queue', 'w')
         o = p.read_text()
         self.assertEqual(o, 'a\nb\n')
 def test_pop(self):
     with TemporaryDirectory() as t:
         p1 = Path(t, 'tasks.txt')
         p1.write_text('x\n')
         p2 = Path(t, 'plans.txt')
         p2.write_text('2018-09-04|a\n')
         c = Commander(root=t)
         c.handle('activate', '1')
         self.assertEqual(p1.read_text(), 'a\nx\n')
Beispiel #20
0
 def test_followon_records_only_first_task_as_done(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a>b\n')
         c = Commander(root=t)
         with mock.patch('busy.dateparser.today', lambda : Date(2019,2,11)):
             c.handle('finish','--yes')
             o = Path(t, 'done.txt').read_text()
             self.assertEqual(o, '2019-02-11|a\n')
 def test_last_record(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\n')
         with mock.patch('busy.editor', lambda x: 'c\n'):
             c = Commander(root=t)
             o = c.handle('manage', '-')
             f = p.read_text()
             self.assertEqual(f, 'a\nc\n')
 def test_delete_defaults_to_first_task_only(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\n')
         c = Commander(root=t)
         with mock.patch('sys.stdin', StringIO('Y')):
             c.handle('delete')
             o = p.read_text()
             self.assertEqual(o, 'b\n')
 def test_delete_with_input_confirmation_no(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         with mock.patch('sys.stdin', StringIO('no')):
             c.handle('delete', '3-')
             o = p.read_text()
             self.assertEqual(o.strip(), 'a\nb\nc\nd')
Beispiel #24
0
 def test_thursday(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\n')
         c = Commander(root=t)
         with mock.patch('busy.dateparser.today', lambda : Date(2019,2,14)):
             c.handle('defer','--to','thursday')
             o2 = Path(t, 'plans.txt').read_text()
             self.assertEqual(o2, '2019-02-21|a\n')
Beispiel #25
0
 def test_manage(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'y.txt')
         p.write_text('a\n')
         with mock.patch('busy.editor', lambda x: 'b\n'):
             c = Commander(root=t)
             o = c.handle('manage', '--queue', 'y')
             f = p.read_text()
             self.assertEqual(f, 'b\n')
 def test_manage_includes_newline_at_end(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\n')
         m = Mock()
         m.return_value = 'b\n'
         with mock.patch('busy.editor', m):
             c = Commander(root=t)
             o = c.handle('manage')
             m.assert_called_with('a\n')
Beispiel #27
0
 def test_default_tomorrow(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\n')
         c = Commander(root=t)
         with mock.patch('busy.dateparser.today', lambda : Date(2019,2,11)):
             with mock.patch('sys.stdin', StringIO(' ')):
                 c.handle('defer')
                 o2 = Path(t, 'plans.txt').read_text()
                 self.assertEqual(o2, '2019-02-12|a\n')
Beispiel #28
0
 def test_defer_for(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         c.handle('defer','2','--for','2019-09-06')
         o = p.read_text()
         self.assertEqual(o, 'a\nc\nd\n')
         o2 = Path(t, 'plans.txt').read_text()
         self.assertEqual(o2, '2019-09-06|b\n')
 def test_delete(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\nc\nd')
         c = Commander(root=t)
         print("Handling...")
         c.handle('delete', '--yes', '3-')
         print("...handled")
         o = p.read_text()
         self.assertEqual(o, 'a\nb\n')
 def test_delete_outputs_before_confirmation(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\n')
         c = Commander(root=t)
         o = StringIO()
         with mock.patch('sys.stdin', StringIO('Y')):
             with mock.patch('sys.stdout', o):
                 c.handle('delete', '1')
                 self.assertEqual(o.getvalue(), 'a\nDelete? (Y/n) ')