コード例 #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')
コード例 #13
0
 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')
コード例 #16
0
 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')
コード例 #17
0
 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')
コード例 #20
0
 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) ')
コード例 #21
0
 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')
コード例 #26
0
 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')