Tests: bug.425, bug_434 and wait now in python

This commit is contained in:
Renato Alves 2015-06-10 23:13:42 +01:00
parent 4dd09ca13f
commit cd3a848bad
3 changed files with 124 additions and 187 deletions

View file

@ -1,86 +1,88 @@
#! /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 => 7;
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
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",
"report.ls.columns=id,project,priority,description\n",
"report.ls.labels=ID,Proj,Pri,Description\n",
"report.ls.sort=priority-,project+\n",
"report.ls.filter=status:pending\n",
"confirmation=off\n";
close $fh;
}
class TestWait(TestCase):
def setUp(self):
self.t = Task()
self.t.config("report.ls.columns", "id,project,priority,description")
self.t.config("report.ls.labels", "ID,Proj,Pri,Description")
self.t.config("report.ls.sort", "priority-,project+")
self.t.config("report.ls.filter", "status:pending")
# [1] add waited task that already expired
# [2] add waited task that is still waited
if (open my $fh, '>', 'pending.data')
{
my $wait = time () - 3600; # Became visible an hour ago
my $entry = $wait - 86400; # Created a day ago
my $tomorrow = $wait + 86400; # Still waiting
def test_visibility_waiting(self):
"""visibility of waiting tasks"""
# Create 2 tasks with waiting times:
# [1] an hour before current time (visible 'now')
# [2] 22 hours after current time (hidden 'now', visible 'tomorrow')
self.t.faketime("-2h")
self.t(("add", "wait:1h", "visible"))
self.t(("add", "wait:1d", "hidden"))
print $fh <<eof;
[uuid:"00000000-0000-0000-0000-000000000000" status:"waiting" description:"visible" entry:"$entry" wait:"$wait"]
[uuid:"00000000-0000-0000-0000-000000000001" status:"waiting" description:"invisible" entry:"$entry" wait:"$tomorrow"]
eof
close $fh;
}
self.t.faketime()
code, out, err = self.t(("ls",))
self.assertIn("visible", out)
self.assertNotIn("hidden", out)
# verify [1] visible already
# verify [2] inviѕible
my $output = qx{../src/task rc:$rc ls 2>&1};
ok ($? == 0, "$ut: list tasks");
like ($output, qr/visible/ms, "$ut: task 1 visible");
unlike ($output, qr/invisible/ms, "$ut: task 2 invisible");
self.t.faketime("+1d")
code, out, err = self.t(("ls",))
self.assertIn("visible", out)
self.assertIn("hidden", out)
# verify [1] has status:pending
$output = qx{../src/task rc:$rc 1 info 2>&1};
ok ($? == 0, "$ut: 1 info");
like ($output, qr/Status\s+Pending/ms, "$ut: task 1 pending");
# verify [2] visible via info
$output = qx{../src/task rc:$rc 2 info 2>&1};
ok ($? == 0, "$ut: 2 info");
like ($output, qr/invisible/ms, "$ut: task 2 visible");
class TestBug434(TestCase):
# Bug #434: Task shouldn't prevent users from marking as done tasks with
# status:waiting
def setUp(self):
self.t = Task()
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
exit 0;
def test_complete_waiting(self):
"""completion of waiting tasks"""
self.t(("add", "One", "wait:tomorrow"))
code, out, err = self.t(("1", "done"))
self.assertIn("Completed 1 task", out)
code, out, err = self.t.runError(("ls",))
self.assertNotIn("One", out)
self.assertIn("No matches", err)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4