Пример #1
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')
Пример #2
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')
Пример #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')
Пример #4
0
 def test_with_root_option(self):
     with TemporaryDirectory() as t:
         c = Commander()
         c.handle('--root', t)
         c.handle('add','--task','a')
         x = Path(t, 'tasks.txt').read_text()
         self.assertEqual(x, 'a\n')
Пример #5
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')
Пример #6
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')
Пример #7
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')
Пример #8
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')
Пример #9
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')
Пример #10
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')
Пример #11
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')
Пример #12
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')
 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')
Пример #14
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')
Пример #15
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')
 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')
Пример #18
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')
Пример #19
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_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) ')
 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')
Пример #22
0
 def test_defer_with_input(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('2019-08-24')):
             c.handle('defer')
             o = p.read_text()
             self.assertEqual(o, 'b\n')
             o2 = Path(t, 'plans.txt').read_text()
             self.assertEqual(o2, '2019-08-24|a\n')
Пример #23
0
 def test_defer_d(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a\nb\nc\nd')
         with mock.patch('busy.dateparser.today', lambda : Date(2019,2,11)):
             c = Commander(root=t)
             c.handle('defer','2','--for','5d')
             o = p.read_text()
             self.assertEqual(o, 'a\nc\nd\n')
             o2 = Path(t, 'plans.txt').read_text()
             self.assertEqual(o2, '2019-02-16|b\n')
Пример #24
0
 def test_repeat_day_template_next_year(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a>repeat on 4\n')
         c = Commander(root=t)
         with mock.patch('busy.dateparser.today', lambda : Date(2019,12,11)):
             c.handle('finish','--yes')
             o = p.read_text()
             self.assertEqual(o, '')
             o2 = Path(t, 'plans.txt').read_text()
             self.assertEqual(o2, '2020-01-04|a>repeat on 4\n')
Пример #25
0
 def test_finish_caps(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a>Repeat ON 7-16\n')
         c = Commander(root=t)
         with mock.patch('busy.dateparser.today', lambda : Date(2019,9,11)):
             c.handle('finish','--yes')
             o = p.read_text()
             self.assertEqual(o, '')
             o2 = Path(t, 'plans.txt').read_text()
             self.assertEqual(o2, '2020-07-16|a>Repeat ON 7-16\n')
 def test_activate_with_today_option(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'plans.txt')
         p.write_text('2018-09-04|a\n2019-03-25|b\n')
         c = Commander(root=t)
         with mock.patch('busy.dateparser.today',
                         lambda: Date(2019, 2, 11)):
             c.handle('activate', '--today')
             self.assertEqual(p.read_text(), '2019-03-25|b\n')
             p2 = Path(t, 'tasks.txt')
             self.assertEqual(p2.read_text(), 'a\n')
Пример #27
0
 def test_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('busy.dateparser.today', lambda : Date(2019,2,11)):
             with mock.patch('sys.stdin', StringIO('Y')):
                 with mock.patch('sys.stdout', o):
                     c.handle('finish')
                     o = Path(t, 'done.txt').read_text()
                     self.assertEqual(o, '2019-02-11|a\n')
Пример #28
0
 def test_repeat_tomorrow(self):
     with TemporaryDirectory() as t:
         p = Path(t, 'tasks.txt')
         p.write_text('a>repeat tomorrow\n')
         c = Commander(root=t)
         with mock.patch('busy.dateparser.today', lambda : Date(2019,2,11)):
             c.handle('finish','--yes')
             o = p.read_text()
             self.assertEqual(o, '')
             o2 = Path(t, 'plans.txt').read_text()
             self.assertEqual(o2, '2019-02-12|a>repeat tomorrow\n')
             o3 = Path(t, 'done.txt').read_text()
             self.assertEqual(o3, '2019-02-11|a\n')
Пример #29
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')
Пример #30
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')