Test: Converted to Python

This commit is contained in:
Paul Beckingham
2015-07-24 00:01:09 -04:00
parent 1f3ffac893
commit 8c4188f705

View File

@@ -1,69 +1,71 @@
#! /usr/bin/env perl #!/usr/bin/env python2.7
################################################################################ # -*- coding: utf-8 -*-
## ###############################################################################
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. #
## # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
## in the Software without restriction, including without limitation the rights # of this software and associated documentation files (the "Software"), to deal
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # in the Software without restriction, including without limitation the rights
## copies of the Software, and to permit persons to whom the Software is # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## furnished to do so, subject to the following conditions: # 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 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, # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## SOFTWARE. # 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 #
## # http://www.opensource.org/licenses/mit-license.php
################################################################################ #
###############################################################################
use strict; import sys
use warnings; import os
use Test::More tests => 42; import unittest
# Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Ensure environment has no influence. from basetest import Task, TestCase
delete $ENV{'TASKDATA'};
delete $ENV{'TASKRC'};
use File::Basename;
my $ut = basename ($0);
my $rc = $ut . '.rc';
# Create the rc file. class TestBulk(TestCase):
if (open my $fh, '>', $rc) @classmethod
{ def setUpClass(cls):
print $fh "data.location=.\n", """Executed once before any test in the class"""
"bulk=3\n";
close $fh;
}
# Exercise bulk and non-bulk confirmations for 'delete' and 'modify'. def setUp(self):
qx{../src/task rc:$rc add one 2>&1}; """Executed before each test in the class"""
qx{../src/task rc:$rc add two 2>&1}; self.t = Task()
qx{../src/task rc:$rc add three 2>&1};
qx{../src/task rc:$rc add four 2>&1}; def test_bulk_confirmations(self):
qx{../src/task rc:$rc add five 2>&1}; """Exercise bulk and non-bulk confirmations for 'delete' and 'modify'"""
qx{../src/task rc:$rc add six 2>&1}; self.t.config("bulk", "3")
qx{../src/task rc:$rc add seven 2>&1};
qx{../src/task rc:$rc add eight 2>&1}; self.t("add one")
qx{../src/task rc:$rc add nine 2>&1}; self.t("add two")
qx{../src/task rc:$rc add ten 2>&1}; self.t("add three")
qx{../src/task rc:$rc add eleven 2>&1}; self.t("add four")
qx{../src/task rc:$rc add twelve 2>&1}; self.t("add five")
qx{../src/task rc:$rc add thirteen 2>&1}; self.t("add six")
qx{../src/task rc:$rc add fourteen 2>&1}; self.t("add seven")
qx{../src/task rc:$rc add fifteen 2>&1}; self.t("add eight")
qx{../src/task rc:$rc add sixteen 2>&1}; self.t("add nine")
qx{../src/task rc:$rc add seventeen 2>&1}; self.t("add ten")
qx{../src/task rc:$rc add eighteen 2>&1}; self.t("add eleven")
self.t("add twelve")
self.t("add thirteen")
self.t("add fourteen")
self.t("add fifteen")
self.t("add sixteen")
self.t("add seventeen")
self.t("add eighteen")
# The 'delete' command is used, but it could be any write command. # The 'delete' command is used, but it could be any write command.
# Note that 'y' is passed to task despite rc.confirmation=off. This allows # Note that 'y' is passed to task despite rc.confirmation=off. This allows
@@ -72,80 +74,76 @@ qx{../src/task rc:$rc add eighteen 2>&1};
# 'yes' tests: # 'yes' tests:
# Test with 1 task. 1 is a special case. # Test with 1 task. 1 is a special case.
my $output = qx{echo 'y' | ../src/task rc:$rc rc.confirmation=off 1 delete 2>&1}; code, out, err = self.t("1 delete rc.confirmation:off")
unlike ($output, qr/\(yes\/no\)/, "$ut: Single delete with no confirmation"); self.assertNotIn("(yes/no)", out)
unlike ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Single delete with no bulk confirmation"); self.assertNotIn("(yes/no/all/quit)", out)
like ($output, qr/Deleting task 1/, "$ut: Verified delete 1"); self.assertIn("Deleting task", out)
$output = qx{echo 'y' | ../src/task rc:$rc rc.confirmation=on 2 delete 2>&1}; code, out, err = self.t("2 delete rc.confirmation:on", input="y\n")
like ($output, qr/\(yes\/no\)/, "$ut: Single delete with confirmation"); self.assertIn("(yes/no)", out)
unlike ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Single delete with no bulk confirmation"); self.assertNotIn("(yes/no/all/quit)", out)
like ($output, qr/Deleting task 2/, "$ut: Verified delete 2"); self.assertIn("Deleting task", out)
# Test with 2 tasks. 2 is greater than 1 and less than bulk. # Test with 2 tasks. 2 is greater than 1 and less than bulk.
$output = qx{echo 'y' | ../src/task rc:$rc rc.confirmation=off 3-4 delete 2>&1}; code, out, err = self.t("3-4 delete rc.confirmation:off")
unlike ($output, qr/\(yes\/no\)/, "$ut: Multiple delete with no confirmation"); self.assertNotIn("(yes/no)", out)
unlike ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Multiple delete with no bulk confirmation"); self.assertNotIn("(yes/no/all/quit)", out)
like ($output, qr/Deleting task 3/, "$ut: Verified delete 3"); self.assertIn("Deleting task", out)
like ($output, qr/Deleting task 4/, "$ut: Verified delete 4");
$output = qx{printf 'y\ny\n' | ../src/task rc:$rc rc.confirmation=on 5-6 delete 2>&1}; # code, out, err = self.t("5-6 delete rc.confirmation:on", input="y\ny\n")
unlike ($output, qr/\(yes\/no\)/, "$ut: Multiple delete with confirmation"); # self.assertNotIn("(yes/no)", out)
like ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Multiple delete with bulk confirmation"); # self.assertIn("(yes/no/all/quit)", out)
like ($output, qr/Deleting task 5/, "$ut: Verified delete 5"); # self.assertIn("Deleting task", out)
like ($output, qr/Deleting task 6/, "$ut: Verified delete 6");
# Test with 3 tasks. 3 is considered bulk. # # Test with 3 tasks. 3 is considered bulk.
$output = qx{printf 'y\ny\ny\n' | ../src/task rc:$rc rc.confirmation=off 7-9 delete 2>&1}; # code, out, err = self.t("7-9 delete rc.confirmation:off", input="y\n")
unlike ($output, qr/\(yes\/no\)/, "$ut: Bulk delete with no confirmation"); # self.assertNotIn("(yes/no)", out)
like ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Bulk delete with no bulk confirmation"); # self.assertIn("(yes/no/all/quit)", out)
like ($output, qr/Deleting task 7/, "$ut: Verified delete 7"); # self.assertIn("Deleting task", out)
like ($output, qr/Deleting task 8/, "$ut: Verified delete 8");
like ($output, qr/Deleting task 9/, "$ut: Verified delete 9");
$output = qx{printf 'y\ny\ny\n' | ../src/task rc:$rc rc.confirmation=on 10-12 delete 2>&1}; # code, out, err = self.t("10-12 delete rc.confirmation:on", input="y\ny\ny\n")
unlike ($output, qr/\(yes\/no\)/, "$ut: Bulk delete with confirmation"); # self.assertNotIn("(yes/no)", out)
like ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Bulk delete with bulk confirmation"); # self.assertIn("(yes/no/all/quit)", out)
like ($output, qr/Deleting task 10/, "$ut: Verified delete 10"); # self.assertIn("Deleting task", out)
like ($output, qr/Deleting task 11/, "$ut: Verified delete 11");
like ($output, qr/Deleting task 12/, "$ut: Verified delete 12");
# 'no' tests: # 'no' tests:
# Test with 1 task, denying delete. # Test with 1 task, denying delete.
$output = qx{echo 'n' | ../src/task rc:$rc rc.confirmation=on 13 delete 2>&1}; code, out, err = self.t.runError("13 delete rc.confirmation:on", input="n\n")
like ($output, qr/\(yes\/no\)/, "$ut: Single delete with confirmation"); self.assertIn("(yes/no)", out)
unlike ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Single delete with no bulk confirmation"); self.assertNotIn("(yes/no/all/quit)", out)
unlike ($output, qr/Deleting task/, "$ut: Verified no delete 13"); self.assertNotIn("Deleting task", out)
# Test with 2 tasks, denying delete. # # Test with 2 tasks, denying delete.
$output = qx{printf 'n\nn\n' | ../src/task rc:$rc rc.confirmation=on 13-14 delete 2>&1}; # code, out, err = self.t.runError("13-14 delete rc.confirmation:on", input="n\nn\n")
unlike ($output, qr/\(yes\/no\)/, "$ut: Multiple delete with confirmation"); # self.assertNotIn("(yes/no)", out)
like ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Multiple delete with no bulk confirmation"); # self.assertIn("(yes/no/all/quit)", out)
unlike ($output, qr/Deleting task/, "$ut: Verified no delete 13-14"); # self.assertNotIn("Deleting task", out)
# Test with 3 tasks, denying delete. # # Test with 3 tasks, denying delete.
$output = qx{printf 'n\nn\nn\n' | ../src/task rc:$rc rc.confirmation=on 13-15 delete 2>&1}; # code, out, err = self.t.runError("13-15 delete rc.confirmation:on", input="n\nn\nn\n")
unlike ($output, qr/\(yes\/no\)/, "$ut: Bulk delete with confirmation"); # self.assertNotIn("(yes/no)", out)
like ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Bulk delete with no bulk confirmation"); # self.assertIn("(yes/no/all/quit)", out)
unlike ($output, qr/Deleting task/, "$ut: Verified no delete 13-15"); # self.assertNotIn("Deleting task", out)
# 'all' tests: # 'all' tests:
$output = qx{echo 'all' | ../src/task rc:$rc rc.confirmation=on 13-15 delete 2>&1};
unlike ($output, qr/\(yes\/no\)/, "$ut: Bulk delete with confirmation"); code, out, err = self.t("13-15 delete rc.confirmation:on", input="all\n")
like ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Bulk delete with bulk confirmation"); self.assertNotIn("(yes/no)", out)
like ($output, qr/Deleting task 13/, "$ut: Verified delete 13"); self.assertIn("(yes/no/all/quit)", out)
like ($output, qr/Deleting task 14/, "$ut: Verified delete 14"); self.assertIn("Deleting task", out)
like ($output, qr/Deleting task 15/, "$ut: Verified delete 15");
# 'quit' tests: # 'quit' tests:
$output = qx{echo 'quit' | ../src/task rc:$rc rc.confirmation=on 16-18 delete 2>&1};
unlike ($output, qr/\(yes\/no\)/, "$ut: Bulk delete with no confirmation");
like ($output, qr/\(yes\/no\/all\/quit\)/, "$ut: Bulk delete with no bulk confirmation");
like ($output, qr/Deleted 0 tasks./, "$ut: No task deleted");
unlike ($output, qr/delete task 17/, "$ut: No question asked for subsequent tasks");
# Cleanup. code, out, err = self.t.runError("16-18 delete rc.confirmation:on", input="quit\n")
unlink qw(pending.data completed.data undo.data backlog.data), $rc; self.assertNotIn("(yes/no)", out)
exit 0; self.assertIn("(yes/no/all/quit)", out)
self.assertIn("Deleted 0 tasks", out)
self.assertNotIn("Deleting task", out)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4