From fe23510c51616f8cbb3976f34b0e897cef472e20 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Tue, 28 Jul 2015 17:00:04 +0100 Subject: [PATCH] Test: Drop default confirmation:off and correct tests accordingly --- test/basetest/task.py | 4 +--- test/bash_completion.t | 2 +- test/bug.954.t | 2 +- test/bug.summary.t | 2 +- test/burndown.t | 2 +- test/columns.t | 2 +- test/completed.t | 2 +- test/context.t | 15 +++++++++++++++ test/count.t | 2 +- test/delete.t | 16 ++++++++-------- test/dependencies.t | 3 ++- test/enpassant.t | 2 ++ test/feature.725.t | 2 +- test/import.t | 2 +- test/project.t | 11 ++++++++--- test/recurrence.t | 15 ++++----------- test/sequence.t | 2 +- test/start.t | 2 +- test/stats.t | 2 +- test/tag.t | 7 ++++--- test/tw-1379.t | 2 +- test/tw-1475.t | 9 ++++++++- test/undo.t | 4 ++-- test/unique.t | 2 +- 24 files changed, 68 insertions(+), 46 deletions(-) diff --git a/test/basetest/task.py b/test/basetest/task.py index 6c7aefadd..dc6ad8ecc 100644 --- a/test/basetest/task.py +++ b/test/basetest/task.py @@ -49,10 +49,8 @@ class Task(object): self.reset_env() - # Cannot call self.config until confirmation is disabled with open(self.taskrc, 'w') as rc: rc.write("data.location={0}\n" - "confirmation=no\n" "hooks=off\n" "".format(self.datadir)) @@ -137,7 +135,7 @@ class Task(object): """ # Add -- to avoid misinterpretation of - in things like UUIDs cmd = (self.taskw, "config", "--", var, value) - return run_cmd_wait(cmd, env=self.env) + return run_cmd_wait(cmd, env=self.env, input="y\n") @property def taskrc_content(self): diff --git a/test/bash_completion.t b/test/bash_completion.t index e5b81b902..45a18dfb0 100755 --- a/test/bash_completion.t +++ b/test/bash_completion.t @@ -154,7 +154,7 @@ class TestProject(TestBashCompletionBase): code, out, err = self.t("add this task should be number 2 and stay number 2") self.assertIn("Created task 2", out) - code, out, err = self.t("1 delete") + code, out, err = self.t("1 delete", input="y\n") self.assertIn("Deleted 1 task", out) with tasksh(self.t): diff --git a/test/bug.954.t b/test/bug.954.t index c069314a0..0dc995524 100755 --- a/test/bug.954.t +++ b/test/bug.954.t @@ -45,7 +45,7 @@ class TestBug954(TestCase): def test_deletion_by_uuid(self): """Verify deletion using extant UUID""" code, out, err = self.t("_get 1.uuid") - code, out, err = self.t(out.strip() + " delete") + code, out, err = self.t(out.strip() + " delete", input="y\n") self.assertIn("Deleting task 1 'foo'", out) def test_deletion_by_missing_uuid(self): diff --git a/test/bug.summary.t b/test/bug.summary.t index 974e5cab3..fffc3ce4e 100755 --- a/test/bug.summary.t +++ b/test/bug.summary.t @@ -46,7 +46,7 @@ class TestSummaryPercentage(TestCase): self.t("add project:A two") self.t("add project:A three") self.t("1 done") - self.t("2 delete") + self.t("2 delete", input="y\n") code, out, err = self.t("summary") self.assertIn(" 50%", out) diff --git a/test/burndown.t b/test/burndown.t index 3aca85d39..a826819d8 100755 --- a/test/burndown.t +++ b/test/burndown.t @@ -44,7 +44,7 @@ class TestBurndownCommand(TestCase): cls.t("add two") cls.t("2 start") cls.t("add three") - cls.t("3 delete") + cls.t("3 delete", input="y\n") cls.t("add four") cls.t("4 start") cls.t("4 done") diff --git a/test/columns.t b/test/columns.t index 7a9d2d396..b4239363a 100755 --- a/test/columns.t +++ b/test/columns.t @@ -191,7 +191,7 @@ class TestStatusFormats(TestCase): cls.t("add zero") cls.t("add one") - cls.t("2 delete") + cls.t("2 delete", input="y\n") cls.t("log two") cls.t("add three due:eom recur:weekly") cls.t("add four wait:eom") diff --git a/test/completed.t b/test/completed.t index 436e6bb7d..f3fe5489e 100755 --- a/test/completed.t +++ b/test/completed.t @@ -47,7 +47,7 @@ class TestCompleted(TestCase): self.t("add two") self.t("add three") self.t("1 done") - self.t("2 delete") + self.t("2 delete", input="y\n") code, out, err = self.t("completed") self.assertIn('one', out) diff --git a/test/context.t b/test/context.t index 529b5745b..9330900c5 100755 --- a/test/context.t +++ b/test/context.t @@ -41,6 +41,19 @@ class ContextManagementTest(TestCase): def setUp(self): self.t = Task() + self.t.config("confirmation", "off") + + def test_context_define_confirmation(self): + """With confirmation active, prompt if context filter matches no tasks""" + self.t.config("confirmation", "on") + + code, out, err = self.t.runError('context define work project:Work', timeout=0.2) + self.assertIn("The filter 'project:Work' matches 0 pending tasks.", out) + self.assertNotIn("Context 'work' defined.", out) + + # Assert the config contains context definition + self.assertNotIn('context.work=project:Work\n', self.t.taskrc_content) + def test_context_define(self): """Test simple context definition.""" code, out, err = self.t('context define work project:Work') @@ -274,6 +287,8 @@ class ContextEvaluationTest(TestCase): def setUp(self): self.t = Task() + self.t.config("confirmation", "off") + # Setup contexts self.t('context define work project:Work') self.t('context define home +home') diff --git a/test/count.t b/test/count.t index 4ddffec23..5f055c2cb 100755 --- a/test/count.t +++ b/test/count.t @@ -44,7 +44,7 @@ class TestCount(TestCase): cls.t("add one") cls.t("log two") cls.t("add three") - cls.t("1 delete") + cls.t("1 delete", input="y\n") def test_count_unfiltered(self): code, out, err = self.t("count") diff --git a/test/delete.t b/test/delete.t index 1273f4753..88b99b432 100755 --- a/test/delete.t +++ b/test/delete.t @@ -46,7 +46,7 @@ class TestDelete(TestCase): code, out, err = self.t("_get 1.uuid") uuid = out.strip() - self.t("1 delete") + self.t("1 delete", input="y\n") self.t.runError("list") # GC/handleRecurrence code, out, err = self.t("_get 1.status") self.assertEqual("\n", out) @@ -54,7 +54,7 @@ class TestDelete(TestCase): code, out, err = self.t("_get %s.status" % uuid) self.assertIn("deleted\n", out) - self.t("undo") + self.t("undo", input="y\n") code, out, err = self.t("_get 1.status") self.assertIn("pending\n", out) code, out, err = self.t("_get %s.status" % uuid) @@ -63,7 +63,7 @@ class TestDelete(TestCase): def test_delete_en_passant(self): """Verify that en-passant works with delete""" self.t("add foo") - code, out, err = self.t("1 delete project:work") + code, out, err = self.t("1 delete project:work", input="y\n") self.assertIn("Deleted 1 task.", out) code, out, err = self.t("all rc.verbose:nothing") @@ -80,7 +80,7 @@ class TestDelete(TestCase): self.t("all") # GC/handleRecurrence - code, out, err = self.t("%s delete" % uuid) + code, out, err = self.t("%s delete" % uuid, input="y\n") self.assertIn("Deleted 1 task.", out) code, out, err = self.t("_get %s.status" % uuid) @@ -90,7 +90,7 @@ class TestDelete(TestCase): """Delete prompt with closed STDIN causes infinite loop and floods stdout (single)""" self.t("add foo1") - self._validate_prompt_loop() + self._validate_prompt_loop(input="y\n") def test_delete_bulk_prompt_loop(self): """Delete prompt with closed STDIN causes infinite loop and floods stdout (bulk)""" @@ -99,12 +99,12 @@ class TestDelete(TestCase): self.t("add foo2") self.t("add foo3") - self._validate_prompt_loop() + self._validate_prompt_loop(input="y\n") - def _validate_prompt_loop(self): + def _validate_prompt_loop(self, input=""): """Helper method to check if task flooded stream on closed STDIN""" try: - code, out, err = self.t("/foo[1-3]/ delete", input="", timeout=0.2) + code, out, err = self.t("/foo[1-3]/ delete", input=input, timeout=0.2) except CommandError as e: # If delete fails with a timeout, don't fail the test immediately code, out, err = e.code, e.out, e.err diff --git a/test/dependencies.t b/test/dependencies.t index de43453b0..ab7e034fc 100755 --- a/test/dependencies.t +++ b/test/dependencies.t @@ -164,8 +164,9 @@ class TestDependencies(TestCase): # 3 <-- 4 Deleting 4 requires no repair # 3 - code, out, err = self.t("4 delete") + code, out, err = self.t("4 delete", input="y\n") self.assertNotIn("Would you like the dependency chain fixed?", out) + self.assertIn("Deleted 1 task", out) @unittest.expectedFailure def test_id_range_dep(self): diff --git a/test/enpassant.t b/test/enpassant.t index ccf13b273..642da37ca 100755 --- a/test/enpassant.t +++ b/test/enpassant.t @@ -84,6 +84,8 @@ class TestEnpassant(BaseTestEnpassant): def setUp(self): super(TestEnpassant, self).setUp() + self.t.config("confirmation", "off") + self.t("add one") self.t("add two") self.t("add three") diff --git a/test/feature.725.t b/test/feature.725.t index 40351f5ca..832ae1e34 100755 --- a/test/feature.725.t +++ b/test/feature.725.t @@ -58,7 +58,7 @@ class TestFeature725(TestCase): self.assertIn("Unblocked", out) # 1 does unblock 4. - code, out, er = self.t("1 delete") + code, out, er = self.t("1 delete", input="y\n") self.assertIn("Unblocked", out) diff --git a/test/import.t b/test/import.t index 1d77b7ad6..abbbcd020 100755 --- a/test/import.t +++ b/test/import.t @@ -139,7 +139,7 @@ class TestImport(TestCase): def test_import_update(self): """Update existing tasks""" self.t("import", input=self.data1) - self.t("a1111111-a111-a111-a111-a11111111111 delete") + self.t("a1111111-a111-a111-a111-a11111111111 delete", input="y\n") self.t("next") # Run GC _t = sorted(self.t.export(), key=lambda t: t["uuid"]) diff --git a/test/project.t b/test/project.t index 61c270cf3..2678fbbd1 100755 --- a/test/project.t +++ b/test/project.t @@ -49,7 +49,7 @@ class TestProjects(TestCase): self.t("add project:A 1") self.t("add project:B 2") self.t("add project:B 3") - self.t("3 delete") + self.t("3 delete", input="y\n") code, out, err = self.t("project:B projects") expected = "1 project \(1 task\)" @@ -78,7 +78,7 @@ class TestProjects(TestCase): self.assertRegexpMatches(err, self.STATUS.format("foo", "25%", "3 of 4 tasks")) - code, out, err = self.t("2 delete") + code, out, err = self.t("2 delete", input="y\n") self.assertRegexpMatches(err, self.STATUS.format("foo", "33%", "2 of 3 tasks")) @@ -156,7 +156,7 @@ class TestProjects(TestCase): """Verify _projects helper list projects""" self.t("add project:A one") self.t("add project:B two") - self.t("2 delete") + self.t("2 delete", input="y\n") self.t("log project:C three") self.t("list") @@ -170,6 +170,7 @@ class TestProjects(TestCase): self.assertIn("B", out) self.assertIn("C", out) + class TestBug299(TestCase): def setUp(self): self.t = Task() @@ -245,6 +246,7 @@ class TestBug605(TestCase): code, out, err = self.t("2 done") self.assertIn("is 100% complete", err) + class TestBug906(TestCase): def setUp(self): self.t = Task() @@ -278,6 +280,7 @@ class TestBug906(TestCase): self.assertNotIn("one", out) self.assertIn("two", out) + class TestBug856(TestCase): def setUp(self): self.t = Task() @@ -302,6 +305,7 @@ class TestBug856(TestCase): self.assertIn("floating", out) self.assertNotIn("assigned", out) + class TestBug1511(TestCase): def setUp(self): self.t = Task() @@ -317,6 +321,7 @@ class TestBug1511(TestCase): self.assertIn("one", out) self.assertNotIn("zero", out) + class TestBug1455(TestCase): def setUp(self): self.t = Task() diff --git a/test/recurrence.t b/test/recurrence.t index 56b1835fd..6ee389b28 100755 --- a/test/recurrence.t +++ b/test/recurrence.t @@ -194,7 +194,7 @@ class TestRecurrenceTasks(TestCase): self.assertEqual("complex3\n", out) # Delete a child task, do not propagate. - code, out, err = self.t("3 delete", input="n\n") + code, out, err = self.t("3 delete", input="y\n") self.assertIn("Deleted 1 task.", out) # Delete a child task, propagate. @@ -229,7 +229,7 @@ class TestDeletionRecurrence(TestCase): """Delete a parent with child tasks""" self.t("add one due:eom recur:daily") self.t("list") # GC/handleRecurrence - code, out, err = self.t("1 delete", input="y\n") + code, out, err = self.t("1 delete", input="y\ny\n") self.assertIn("Deleted 2 tasks.", out) code, out, err = self.t.runError("list") @@ -242,7 +242,7 @@ class TestDeletionRecurrence(TestCase): code, out, err = self.t("list rc.verbose:nothing") # GC/handleRecurrence self.assertEqual(out.count("one"), 5) - code, out, err = self.t("2 delete", input="y\n") + code, out, err = self.t("2 delete", input="y\ny\n") self.assertIn("Deleted 5 tasks.", out) @@ -312,7 +312,6 @@ class TestBug955(TestCase): def setUp(self): self.t = Task() - @unittest.expectedFailure def test_no_prompt_for_parent_on_child_delete(self): """Deleting a child of a recurring task doesn't prompt for parent deletion @@ -322,13 +321,7 @@ class TestBug955(TestCase): code, out, err = self.t("ls") self.assertRegexpMatches(out, re.compile("^2 tasks", re.MULTILINE)) - # NOTE: Test fails here due to some strange handling of STDIN in task - # "y\nn\n" actually behaves as "y\ny\n" so both tasks are deleted - # in the shell 'printf "y\nn\n" | task 2 delete' works as expected. - # Yet replacing the task binary with something like "hexdump", all - # bytes received via STDIN are identical in python vs shell. - # NOTE: This may be related to delete.t test_delete_bulk_prompt_loop - code, out, err = self.t("2 delete", input="y\nn\n") + code, out, err = self.t("2 delete", input="n\ny\n") self.assertIn("Deleting task 2", out) self.assertIn("Deleted 1 task", out) diff --git a/test/sequence.t b/test/sequence.t index af0cb6c92..6af9e7bcd 100755 --- a/test/sequence.t +++ b/test/sequence.t @@ -50,7 +50,7 @@ class TestSequences(TestCase): def test_sequence_delete(self): """Test sequences in delete""" - self.t("1,2 delete") + self.t("1,2 delete", input="y\ny\n") code, out, err = self.t("_get 1.status 2.status") self.assertEqual("deleted deleted\n", out) diff --git a/test/start.t b/test/start.t index ba9882bc5..0ae4f294b 100755 --- a/test/start.t +++ b/test/start.t @@ -110,7 +110,7 @@ class TestActiveTaskHandling(TestCase): def test_start_deleted(self): """Deleted task set to pending by start""" - self.t("+one delete") + self.t("+one delete", input="y\n") self.t("+one start") tl = self.t.export() self.assertEqual(tl[0]["status"], "pending") diff --git a/test/stats.t b/test/stats.t index 46244f9d2..d00f0a0ff 100755 --- a/test/stats.t +++ b/test/stats.t @@ -44,7 +44,7 @@ class TestStatisticsCommand(TestCase): """Verify stats records task states""" self.t("add one") self.t("add two") - self.t("2 delete") + self.t("2 delete", input="y\n") self.t("log three") code, out, err = self.t("stats") diff --git a/test/tag.t b/test/tag.t index d55f0b9e7..f15d16d02 100755 --- a/test/tag.t +++ b/test/tag.t @@ -50,7 +50,7 @@ class TestTags(TestCase): code, out, err = self.t("_get 1.tags") self.assertEqual("one,two,three\n", out) - # Remove tags. + # Remove tags. self.t("1 modify -three -two -one") code, out, err = self.t("_get 1.tags") self.assertEqual("\n", out) @@ -74,6 +74,7 @@ class TestTags(TestCase): code, out, err = self.t("1 modify -missing") self.assertIn("Modified 0 tasks", out) + class TestVirtualTags(TestCase): @classmethod def setUpClass(cls): @@ -82,7 +83,7 @@ class TestVirtualTags(TestCase): cls.t.config("verbose", "nothing") cls.t("log completed") cls.t("add deleted") - cls.t("1 delete") + cls.t("1 delete", input="y\n") cls.t("add minimal") cls.t("add maximal +tag pro:PRO pri:H due:yesterday") cls.t("3 start") @@ -480,7 +481,7 @@ class TestListAllTags(TestCase): self.t("add +t1 one") self.t("add +t2 two") self.t("1 done") - self.t("list") # GC/handleRecurrence + self.t("list") # GC/handleRecurrence code, out, err = self.t("rc.verbose:nothing tags") self.assertNotIn("t1", out) diff --git a/test/tw-1379.t b/test/tw-1379.t index 52c1361fc..a4fd6d845 100755 --- a/test/tw-1379.t +++ b/test/tw-1379.t @@ -153,7 +153,7 @@ class TestBug1379(TestCase): self.t.config("color.deleted", "") self.t("add Delete") - self.t("1 delete") + self.t("1 delete", input="y\n") code, out, err = self.t("all +DELETED") self.assertRegexpMatches(out, self.RED + r".*Delete.*" + self.CLEAR) diff --git a/test/tw-1475.t b/test/tw-1475.t index ff7d74b78..08f782207 100755 --- a/test/tw-1475.t +++ b/test/tw-1475.t @@ -42,7 +42,14 @@ class TestBug1475(TestCase): def test_config_unmolested(self): """Verify that a config value is not borked by lex/eval""" - self.t("config name one/two/three") + self.t.config("name", "one/two/three") + + code, out, err = self.t("_get rc.name") + self.assertEqual("one/two/three\n", out) + + def test_config_unmolested_2(self): + """Verify that a config value is not borked by lex/eval - literal""" + self.t("config name one/two/three", input="y\n") code, out, err = self.t("_get rc.name") self.assertEqual("one/two/three\n", out) diff --git a/test/undo.t b/test/undo.t index a5fafb803..335d6b347 100755 --- a/test/undo.t +++ b/test/undo.t @@ -45,7 +45,7 @@ class TestUndo(TestCase): self.t('add one') code, out, err = self.t('_get 1.status') self.assertEqual(out.strip(), 'pending') - self.t('undo') + self.t('undo', input="y\n") code, out, err = self.t('_get 1.status') self.assertEqual(out.strip(), '') @@ -57,7 +57,7 @@ class TestUndo(TestCase): self.t('1 done') code, out, err = self.t('_get 1.status') self.assertEqual(out.strip(), 'completed') - self.t('undo') + self.t('undo', input="y\n") code, out, err = self.t('_get 1.status') self.assertEqual(out.strip(), 'pending') diff --git a/test/unique.t b/test/unique.t index dbf439ca4..c4d8a35d1 100755 --- a/test/unique.t +++ b/test/unique.t @@ -46,7 +46,7 @@ class TestUnique(TestCase): self.t("add two project:A") self.t("add three project:B") self.t("add four project:C") - self.t("4 delete") + self.t("4 delete", input="y\n") self.t("log five project:D") code, out, err = self.t("_unique project")