From 29b18c216c28e1c7709d8debbc7af4170bdacdaa Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 24 Jul 2015 17:01:57 -0400 Subject: [PATCH] Test: Converted to Python --- test/dependencies.t | 378 +++++++++++++++++++------------------------- 1 file changed, 165 insertions(+), 213 deletions(-) diff --git a/test/dependencies.t b/test/dependencies.t index 8ecc45d80..f68f8f550 100755 --- a/test/dependencies.t +++ b/test/dependencies.t @@ -1,248 +1,198 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### -use strict; -use warnings; -use Test::More tests => 41; +import sys +import os +import unittest +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; +from basetest import Task, TestCase -# Create the rc file. -if (open my $fh, '>', 'dep.rc') -{ - print $fh "data.location=.\n"; - print $fh "dependency.confirmation=yes\n"; - print $fh "report.depreport.columns=id,depends,description\n"; - print $fh "report.depreport.labels=ID,Depends,Description\n"; - print $fh "report.depreport.filter=status:pending\n"; - print $fh "report.depreport.sort=depends+\n"; - close $fh; -} -qx{../src/task rc:dep.rc add One 2>&1}; -qx{../src/task rc:dep.rc add Two 2>&1}; +class TestDependencies(TestCase): + def setUp(self): + """Executed before each test in the class""" + self.t = Task() + self.t("add one") + self.t("add two") -# [2] -my $output = qx{../src/task rc:dep.rc 1 modify dep:-2 2>&1 >/dev/null}; -like ($output, qr/Could not delete a dependency on task 2 - not found\./, 'dependencies - remove nonexistent dependency'); + def test_removing_missing_dep(self): + """Remove a dependency that isn't there""" + code, out, err = self.t.runError("1 modify dep:-2") + self.assertIn("Could not delete a dependency on task 2 - not found.", err) -# [3] -$output = qx{../src/task rc:dep.rc 1 modify dep:99 2>&1 >/dev/null}; -like ($output, qr/Could not create a dependency on task 99 - not found\./, 'dependencies - add dependency for nonexistent task'); + def test_add_missing_dep(self): + """Add a dependency on a missing task""" + code, out, err = self.t.runError("1 modify dep:99") + self.assertIn("Could not create a dependency on task 99 - not found.", err) -# [4] -$output = qx{../src/task rc:dep.rc 99 modify dep:1 2>&1 >/dev/null}; -like ($output, qr/No tasks specified\./, 'dependencies - add dependency to nonexistent task'); + def test_add_dep_to_missing_task(self): + """Add a dependency to a missing task""" + code, out, err = self.t.runError("99 modify dep:1") + self.assertIn("No tasks specified.", err) -# [5,6] t 1 dep:2; t info 1 => blocked by 2 -$output = qx{../src/task rc:dep.rc 1 modify dep:2 2>&1; ../src/task rc:dep.rc info 1 2>&1}; -like ($output, qr/This task blocked by\s+2 Two\n/, 'dependencies - trivial blocked'); -unlike ($output, qr/This task is blocking\n/, 'dependencies - trivial blocked'); + def test_add_dep_to_missing_task(self): + """Add a dependency to a missing task""" + code, out, err = self.t.runError("99 modify dep:1") + self.assertIn("No tasks specified.", err) -# [7,8] t info 2 => blocking 1 -$output = qx{../src/task rc:dep.rc info 2 2>&1}; -unlike ($output, qr/This task blocked by/, 'dependencies - trivial blocking'); -like ($output, qr/This task is blocking\s+1 One\n/, 'dependencies - trivial blocking'); + def test_double_dep(self): + """Check adding a dep twice is an error""" + self.t("2 modify dep:1") + code, out, err = self.t("2 modify dep:1") + self.assertIn("Task 2 already depends on task 1.", err) -# [9] t 1 dep:2 (again) -$output = qx{../src/task rc:dep.rc 1 modify dep:2 2>&1 >/dev/null}; -like ($output, qr/Task 1 already depends on task 2\./, 'dependencies - add already existing dependency'); + def test_circular_1(self): + """Check a task cannot depend on itself""" + code, out, err = self.t.runError("1 modify dep:1") + self.assertIn("A task cannot be dependent on itself.", err) -# [10,11] t 1 dep:1 => error -$output = qx{../src/task rc:dep.rc 1 modify dep:1 2>&1}; -like ($output, qr/A task cannot be dependent on itself\./, 'dependencies - cannot depend on self'); -unlike ($output, qr/Modified 1 task\./, 'dependencies - cannot depend on self'); + def test_circular_2(self): + """Check circular dependencies are caught, using 2 tasks""" + self.t("2 modify dep:1") + code, out, err = self.t.runError("1 modify dep:2") + self.assertIn("Circular dependency detected and disallowed.", err) -# [12,13] t 1 dep:2; t 2 dep:1 => error -$output = qx{../src/task rc:dep.rc 2 modify dep:1 2>&1}; -like ($output, qr/Circular dependency detected and disallowed\./, 'dependencies - trivial circular'); -unlike ($output, qr/Modified 1 task\./, 'dependencies - trivial circular'); + def test_circular_5(self): + """Check circular dependencies are caught, using 5 tasks""" + self.t("add three") + self.t("add four") + self.t("add five") + self.t("5 modify dep:4") + self.t("4 modify dep:3") + self.t("3 modify dep:2") + self.t("2 modify dep:1") + code, out, err = self.t.runError("1 modify dep:5") + self.assertIn("Circular dependency detected and disallowed.", err) -# [14,15] t 1 dep:2; t 2 dep:3; t 1 dep:3 => not circular -qx{../src/task rc:dep.rc 1 modify dep:2 2>&1}; -qx{../src/task rc:dep.rc add Three 2>&1}; -qx{../src/task rc:dep.rc 2 modify dep:3 2>&1}; -$output = qx{../src/task rc:dep.rc 1 modify dep:3 2>&1}; -unlike ($output, qr/Circular dependency detected and disallowed\./, 'dependencies - diamond, non-circular'); -like ($output, qr/Modified 1 task\./, 'dependencies - diamond, non-circular'); + def test_dag(self): + """Check acyclic graph support""" + self.t("add three") + self.t("1 modify dep:2") + self.t("1 modify dep:3") + self.t("2 modify dep:3") + code, out, err = self.t("1 modify dep:2") + self.assertNotIn("Circular dependency detected and disallowed.", err) -# [16] -unlink 'pending.data'; + def test_blocked_blocking(self): + """Check blocked/blocking status of two tasks""" + self.t("2 modify dep:1") -qx{../src/task rc:dep.rc add One 2>&1}; -qx{../src/task rc:dep.rc add Two 2>&1}; -qx{../src/task rc:dep.rc add Three 2>&1}; -qx{../src/task rc:dep.rc add Four 2>&1}; -qx{../src/task rc:dep.rc add Five 2>&1}; + code, out, err = self.t("_get 1.tag.BLOCKED") + self.assertEqual("\n", out) + code, out, err = self.t("_get 1.tag.BLOCKING") + self.assertEqual("BLOCKING\n", out) -qx{../src/task rc:dep.rc 5 modify dep:4 2>&1; ../src/task rc:dep.rc 4 modify dep:3 2>&1; ../src/task rc:dep.rc 3 modify dep:2 2>&1; ../src/task rc:dep.rc 2 modify dep:1 2>&1}; + code, out, err = self.t("_get 2.tag.BLOCKED") + self.assertEqual("BLOCKED\n", out) + code, out, err = self.t("_get 2.tag.BLOCKING") + self.assertEqual("\n", out) -# [17,18] 5 dep 4 dep 3 dep 2 dep 1 dep 5 => error -$output = qx{../src/task rc:dep.rc 1 modify dep:5 2>&1 >/dev/null}; -like ($output, qr/Circular dependency detected and disallowed\./, 'dependencies - nontrivial circular'); -unlike ($output, qr/Modified 1 task\./, 'dependencies - nontrivial circular'); + def test_modify_multiple(self): + """Check circular dependencies are caught, using 5 tasks""" + self.t("add three") + self.t("add four") + self.t("add five") + code, out, err = self.t("1 modify dep:2,3,4") + self.assertIn("Modified 1 task.", out) -# [19] -unlink 'pending.data'; + code, out, err = self.t("1 modify dep:5,-4") + self.assertIn("Modified 1 task.", out) -qx{../src/task rc:dep.rc add One 2>&1}; -qx{../src/task rc:dep.rc add Two 2>&1}; -qx{../src/task rc:dep.rc add Three 2>&1}; -qx{../src/task rc:dep.rc add Four 2>&1}; -qx{../src/task rc:dep.rc add Five 2>&1}; -qx{../src/task rc:dep.rc add Six recurring due:tomorrow recur:daily 2>&1}; + code, out, err = self.t("_get 3.tag.BLOCKING") + self.assertEqual("BLOCKING\n", out) -# [20] -qx{../src/task rc:dep.rc ls 2>&1}; # To force handleRecurrence call. -$output = qx{echo 'y' | ../src/task rc:dep.rc 6 modify dep:5 2>&1}; -like ($output, qr/Modified \d+ task/, 'dependencies - recurring task depending on another task'); + code, out, err = self.t("_get 4.tag.BLOCKING") + self.assertEqual("\n", out) -# [21] -$output = qx{../src/task rc:dep.rc 4 modify dep:5 2>&1}; -like ($output, qr/Modified \d+ task/, 'dependencies - task depending on recurring task'); + def test_done_dep(self): + """Check that completing a task unblocks""" + self.t("1 modify dep:2") -# [22] t 1 dep:2,3,4; t 1 dep:-2,-4,5; t info 1 => blocked by 3,5 -$output = qx{../src/task rc:dep.rc 1 modify dep:2,3,4 2>&1; ../src/task rc:dep.rc 1 modify dep:-2,-4,5 2>&1; ../src/task rc:dep.rc info 1 2>&1}; -like ($output, qr/This task blocked by\s+3 Three\n\s+5 Five\n/, 'dependencies - multiple dependencies modified'); + code, out, err = self.t("_get 1.tag.BLOCKED") + self.assertEqual("BLOCKED\n", out) -# [23,24] -$output = qx{../src/task rc:dep.rc 3,5 done 2>&1; ../src/task rc:dep.rc info 1 2>&1}; -unlike ($output, qr/This task blocked by/, 'dependencies - task info reflects completed dependencies'); -unlike ($output, qr/This task is blocking/, 'dependencies - task info reflects completed dependencies'); + code, out, err = self.t("2 done") + self.assertIn("Unblocked 1 'one'.", out) -# [25] -$output = qx{../src/task rc:dep.rc depreport 2>&1}; -like ($output, qr/\s1\s+One\s+/, 'dependencies - depends report column reflects completed dependencies'); + code, out, err = self.t("_get 1.tag.BLOCKED") + self.assertEqual("\n", out) -# [26] -unlink 'pending.data'; + def test_chain_repair(self): + """Check that a broken chain is repaired""" + self.t("add three") + self.t("add four") + self.t("2 modify dep:1") + self.t("3 modify dep:2") + self.t("4 modify dep:3") -qx{../src/task rc:dep.rc add One 2>&1}; -qx{../src/task rc:dep.rc add Two 2>&1}; -qx{../src/task rc:dep.rc add Three 2>&1}; -qx{../src/task rc:dep.rc add Four 2>&1}; + # 1 <-- 2 <-- 3 <-- 4 Completing 2 requires repair + # 1 <-- 3 <-- 4 + code, out, err = self.t("2 done", input="y\n") + self.assertIn("Would you like the dependency chain fixed?", out) -qx{../src/task rc:dep.rc 1 modify dep:3,4 2>&1}; -qx{../src/task rc:dep.rc 2 done 2>&1}; + # 1 <-- 3 <-- 4 Completing 1 requires no repair + # 3 <-- 4 + code, out, err = self.t("1 done") + self.assertNotIn("Would you like the dependency chain fixed?", out) -# [27] -$output = qx{../src/task rc:dep.rc depreport 2>&1}; -like ($output, qr/\s1\s+2 3\s+One\s+/, 'dependencies - depends report column reflects changed IDs'); + # 3 <-- 4 Deleting 4 requires no repair + # 3 + code, out, err = self.t("4 delete") + self.assertNotIn("Would you like the dependency chain fixed?", out) -# [28] -qx{../src/task rc:dep.rc 3 done 2>&1}; -$output = qx{../src/task rc:dep.rc depreport 2>&1}; -like ($output, qr/\s1\s+2\s+One\s+/, 'dependencies - depends report column reflects completed dependencies'); + def test_id_range_dep(self): + """Check that an ID range can be used for deps""" + self.t("add three") -# [29] -unlink 'pending.data'; + # Add a range of IDs + self.t("3 modify dep:1-2") + code, out, err = self.t("_get 1.tag.BLOCKING") + self.assertEqual("BLOCKING\n", out) + code, out, err = self.t("_get 2.tag.BLOCKING") + self.assertEqual("BLOCKING\n", out) -qx{../src/task rc:dep.rc add One 2>&1}; -qx{../src/task rc:dep.rc add Two 2>&1}; -qx{../src/task rc:dep.rc add Three 2>&1}; -qx{../src/task rc:dep.rc add Four 2>&1}; + def test_id_uuid_dep(self): + """Check that IDs and UUIDs are both usable for deps""" -qx{../src/task rc:dep.rc 2 modify dep:1 2>&1; ../src/task rc:dep.rc 3 modify dep:2 2>&1; ../src/task rc:dep.rc 4 modify dep:3 2>&1}; + # Get 2.uuid + code, out, err = self.t("_get 2.uuid") + uuid = out.strip() -# [30,31] -$output = qx{echo 'y' | ../src/task rc:dep.rc 2 done 2>&1}; -like ($output, qr/fixed/, 'dependencies - user prompted to fix broken chain after completing a blocked task'); -like ($output, qr/is blocked by/, 'dependencies - user nagged for completing a blocked task'); + # Add a mix of IDs and UUID + code, out, err = self.t("add three dep:1,%s" % uuid) + self.assertIn("Created task 3.", out) -# [32] -$output = qx{echo 'y' | ../src/task rc:dep.rc 1 done 2>&1}; -unlike ($output, qr/fixed/, 'dependencies - user not prompted to fix broken chain when the head of the chain is marked as complete'); + # Remove a mix of IЅs and UUID + code, out, err = self.t("3 modify dep:-1,-%s" % uuid) + self.assertIn("Modifying task 3 'three'.", out) -# [33] -$output = qx{echo 'y' | ../src/task rc:dep.rc 4 del 2>&1}; -unlike ($output, qr/fixed/, 'dependencies - user not prompted to fix broken chain when the tail of the chain is deleted'); - -# [34] -unlink 'pending.data'; - -qx{../src/task rc:dep.rc add One 2>&1}; -qx{../src/task rc:dep.rc add Two 2>&1}; -qx{../src/task rc:dep.rc add Three 2>&1}; -qx{../src/task rc:dep.rc add Four 2>&1}; -qx{../src/task rc:dep.rc add Five 2>&1}; - -qx{../src/task rc:dep.rc 2 modify dep:1 2>&1}; -qx{../src/task rc:dep.rc 3 modify dep:2 2>&1}; -qx{../src/task rc:dep.rc 4 modify dep:3 2>&1}; -qx{../src/task rc:dep.rc 5 modify dep:4 2>&1}; - -# [35] -qx{echo 'y' | ../src/task rc:dep.rc 2 done 2>&1}; -$output = qx{../src/task rc:dep.rc depreport 2>&1}; -like ($output, qr/\s1\s+One\s*\n\s2\s+1\s+Three\s*\n\s3\s+2\s+Four\s*\n\s4\s+3\s+Five/, 'dependencies - fixed chain after completing a blocked task'); - -# [36] -qx{echo "Y\nY\n" | ../src/task rc:dep.rc 2 del 2>&1}; -$output = qx{../src/task rc:dep.rc depreport 2>&1}; -like ($output, qr/\s1\s+One\s*\n\s2\s+1\s+Four\s*\n\s3\s+2\s+Five/, 'dependencies - fixed chain after deleting a blocked task'); - -# [37] -qx{../src/task rc:dep.rc 2 modify dep:-1 2>&1}; -$output = qx{../src/task rc:dep.rc depreport 2>&1}; -like ($output, qr/\s1\s+One\s*\n\s2\s+Four\s*\n\s3\s+2\s+Five/, 'dependencies - chain should not be automatically repaired after manually removing a dependency'); - -# [38] -unlink 'pending.data'; - -# Bug when adding a range of dependencies - 'task 3 mod dep:1-2' interprets the -# range 1-2 as the id 1 - -qx{../src/task rc:dep.rc add test1 2>&1}; -qx{../src/task rc:dep.rc add test2 2>&1}; -qx{../src/task rc:dep.rc add test3 2>&1}; -qx{../src/task rc:dep.rc add test4 2>&1}; -qx{../src/task rc:dep.rc add test5 2>&1}; -my $uuid = qx{../src/task rc:dep.rc _get 5.uuid}; -chomp $uuid; - -# [38-42] test a comma-separated list of IDs, UUIDs, and ID ranges for creation -qx{../src/task rc:dep.rc add test6 dep:1,2,3,4,$uuid 2>&1}; -$output = qx{../src/task rc:dep.rc 6 info 2>&1}; -like ($output, qr/test1/ms, 'Dependency appearing for task1'); -like ($output, qr/test2/ms, 'Dependency appearing for task2'); -like ($output, qr/test3/ms, 'Dependency appearing for task3'); -like ($output, qr/test4/ms, 'Dependency appearing for task4'); -like ($output, qr/test5/ms, 'Dependency appearing for task5'); - -# [43-47] test a comma-separated list of IDs, UUIDs, and ID ranges for deletion -qx{../src/task rc:dep.rc 6 mod dep:-1,-2,-3,-4,-$uuid 2>&1}; -$output = qx{../src/task rc:dep.rc 6 info 2>&1}; -unlike ($output, qr/test1/ms, 'Dependency not appearing for task1'); -unlike ($output, qr/test2/ms, 'Dependency not appearing for task2'); -unlike ($output, qr/test3/ms, 'Dependency not appearing for task3'); -unlike ($output, qr/test4/ms, 'Dependency not appearing for task4'); -unlike ($output, qr/test5/ms, 'Dependency not appearing for task5'); # TODO - test dependency.confirmation config variable # TODO - test undo on backing out chain gap repair @@ -250,7 +200,9 @@ unlike ($output, qr/test5/ms, 'Dependency not appearing for task5'); # TODO - test blocked task completion nag # TODO - test depend.any and depend.none report filters -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data dep.rc); -exit 0; +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4