Tests - merge bug.1044 into project.t and convert to python

This commit is contained in:
Renato Alves
2015-03-06 16:44:28 +00:00
parent 276050ce0b
commit ebd6977480
2 changed files with 121 additions and 150 deletions

View File

@@ -1,62 +0,0 @@
#! /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
##
################################################################################
use strict;
use warnings;
use Test::More tests => 1;
# Ensure environment has no influence.
delete $ENV{'TASKDATA'};
delete $ENV{'TASKRC'};
use File::Basename;
my $ut = basename ($0);
my $rc = $ut . '.rc';
# Create the rc file.
if (open my $fh, '>', $rc)
{
print $fh "data.location=.\n",
"confirmation=off\n";
close $fh;
}
# Bug #1044: 'task projects' considers newly deleted tasks and provides an
# incorrect summary
# Check that until attribute may be modified
qx{../src/task rc:$rc add project:A 1 2>&1};
qx{../src/task rc:$rc add project:B 2 2>&1};
qx{../src/task rc:$rc add project:B 3 2>&1};
qx{../src/task rc:$rc 3 delete 2>&1};
my $output = qx{../src/task rc:$rc project:B projects 2>&1};
like ($output, qr/^1 project \(1 task\)$/ms, "$ut: Summary filtered new deleted task 3 and project A");
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
exit 0;

View File

@@ -1,111 +1,144 @@
#! /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 => 16; 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 TestProjects(TestCase):
if (open my $fh, '>', $rc) def setUp(self):
{ self.t = Task()
print $fh "data.location=.\n",
"confirmation=off\n";
close $fh;
}
# Test the project status numbers. self.STATUS = ("The project '{0}' has changed\. "
my $output = qx{../src/task rc:$rc add one pro:foo 2>&1 >/dev/null}; "Project '{0}' is {1} complete \({2} remaining\)\.")
like ($output, qr/The project 'foo' has changed\. Project 'foo' is 0% complete \(1 task remaining\)\./, "$ut: add one");
$output = qx{../src/task rc:$rc add two pro:'foo' 2>&1 >/dev/null}; def test_project_summary_count(self):
like ($output, qr/The project 'foo' has changed\. Project 'foo' is 0% complete \(2 of 2 tasks remaining\)\./, "$ut: add two"); """'task projects' shouldn't consider deleted tasks in summary.
Reported in bug 1044
"""
self.t(("add", "project:A", "1"))
self.t(("add", "project:B", "2"))
self.t(("add", "project:B", "3"))
self.t(("3", "delete"))
code, out, err = self.t(("project:B", "projects"))
$output = qx{../src/task rc:$rc add three pro:'foo' 2>&1 >/dev/null}; expected = "1 project \(1 task\)"
like ($output, qr/The project 'foo' has changed\. Project 'foo' is 0% complete \(3 of 3 tasks remaining\)\./, "$ut: add three"); self.assertRegexpMatches(out, expected)
$output = qx{../src/task rc:$rc add four pro:'foo' 2>&1 >/dev/null}; def test_project_progress(self):
like ($output, qr/The project 'foo' has changed\. Project 'foo' is 0% complete \(4 of 4 tasks remaining\)\./, "$ut: add four"); """project status/progress is shown and is up-to-date"""
$output = qx{../src/task rc:$rc 1 done 2>&1 >/dev/null}; code, out, err = self.t(("add", "one", "pro:foo"))
like ($output, qr/Project 'foo' is 25% complete \(3 of 4 tasks remaining\)\./, "$ut: done one"); self.assertRegexpMatches(err, self.STATUS.format("foo", "0%",
"1 task"))
$output = qx{../src/task rc:$rc 2 delete 2>&1 >/dev/null}; code, out, err = self.t(("add", "two", "pro:foo"))
like ($output, qr/The project 'foo' has changed\. Project 'foo' is 33% complete \(2 of 3 tasks remaining\)\./, "$ut: delete two"); self.assertRegexpMatches(err, self.STATUS.format("foo", "0%",
"2 of 2 tasks"))
$output = qx{../src/task rc:$rc 3 modify pro:bar 2>&1 >/dev/null}; code, out, err = self.t(("add", "three", "pro:foo"))
like ($output, qr/The project 'foo' has changed\. Project 'foo' is 50% complete \(1 of 2 tasks remaining\)\./, "$ut: change project"); self.assertRegexpMatches(err, self.STATUS.format("foo", "0%",
like ($output, qr/The project 'bar' has changed\. Project 'bar' is 0% complete \(1 task remaining\)\./, "$ut: change project"); "3 of 3 tasks"))
# Test projects with spaces in them. code, out, err = self.t(("add", "four", "pro:foo"))
$output = qx{../src/task rc:$rc 3 modify pro:"foo bar" 2>&1 >/dev/null}; self.assertRegexpMatches(err, self.STATUS.format("foo", "0%",
like ($output, qr/The project 'foo bar' has changed\./, "$ut: project with spaces"); "4 of 4 tasks"))
# Bug 1056: Project indentation. code, out, err = self.t(("1", "done"))
# see also the tests of helper functions for CmdProjects in util.t.cpp self.assertRegexpMatches(err, self.STATUS.format("foo", "25%",
qx{../src/task rc:$rc add testing project:existingParent 2>&1 >/dev/null}; "3 of 4 tasks"))
qx{../src/task rc:$rc add testing project:existingParent.child 2>&1 >/dev/null};
qx{../src/task rc:$rc add testing project:abstractParent.kid 2>&1 >/dev/null};
qx{../src/task rc:$rc add testing project:.myProject 2>&1 >/dev/null};
qx{../src/task rc:$rc add testing project:myProject. 2>&1 >/dev/null};
qx{../src/task rc:$rc add testing project:.myProject. 2>&1 >/dev/null};
$output = qx{../src/task rc:$rc projects 2>&1}; code, out, err = self.t(("2", "delete"))
my @lines = split ('\n',$output); self.assertRegexpMatches(err, self.STATUS.format("foo", "33%",
"2 of 3 tasks"))
my ($project_name_column) = $lines[4] =~ /^(\s*\S+)/; code, out, err = self.t(("3", "modify", "pro:bar"))
like ($project_name_column, qr/^\.myProject$/, "$ut: '.myProject' not indented"); self.assertRegexpMatches(err, self.STATUS.format("foo", "50%",
"1 of 2 tasks"))
self.assertRegexpMatches(err, self.STATUS.format("bar", "0%",
"1 task"))
($project_name_column) = $lines[5] =~ /^(\s*\S+)/; def test_project_spaces(self):
like ($project_name_column, qr/^\.myProject\.$/, "$ut: '.myProject.' not indented"); """projects with spaces are handled correctly"""
($project_name_column) = $lines[6] =~ /^(\s*\S+)/; self.t(("add", "hello", "pro:bob"))
like ($project_name_column, qr/^abstractParent$/, "$ut: abstract parent not indented"); code, out, err = self.t(("1", "mod", 'pro:"foo bar"'))
self.assertRegexpMatches(err, self.STATUS.format("foo bar", "0%",
"1 task"))
($project_name_column) = $lines[7] =~ /^(\s*\S+)/; def test_project_indentation(self):
like ($project_name_column, qr/^ kid$/, "$ut: child indented and without parent name"); """check project/subproject indentation
($project_name_column) = $lines[8] =~ /^(\s*\S+)/; Reported in bug 1056
like ($project_name_column, qr/^existingParent$/, "$ut: existing parent not indented");
($project_name_column) = $lines[9] =~ /^(\s*\S+)/; See also the tests of helper functions for CmdProjects in util.t.cpp
like ($project_name_column, qr/^ child$/, "$ut: child of existing parent indented and without parent name"); """
self.t(("add", "testing", "project:existingParent"))
self.t(("add", "testing", "project:existingParent.child"))
self.t(("add", "testing", "project:abstractParent.kid"))
self.t(("add", "testing", "project:.myProject"))
self.t(("add", "testing", "project:myProject"))
self.t(("add", "testing", "project:.myProject."))
($project_name_column) = $lines[12] =~ /^(\s*\S+)/; code, out, err = self.t(("projects",))
like ($project_name_column, qr/^myProject\.$/, "$ut: 'myProject.' not indented");
# Cleanup. order = (
unlink qw(pending.data completed.data undo.data backlog.data), $rc; # NOTE all but abstractParent have 1 task hence the trailing space
exit 0; ".myProject ",
".myProject. ",
"abstractParent\n",
" kid ",
"existingParent ",
" child ",
"myProject ",
)
lines = out.splitlines(True) # True = keep newlines
# position where project names start on the lines list
position = 3
for i, proj in enumerate(order):
pos = position + i
self.assertTrue(
lines[pos].startswith(proj),
msg=("Project '{0}' is not in line #{1} or has an unexpected "
"indentation.{2}".format(proj, pos, out))
)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4