Test: Convert timesheet.t to Python

This commit is contained in:
Renato Alves
2015-07-23 17:42:16 +01:00
parent b90d4a3aaf
commit 580754a65a

View File

@@ -1,88 +1,104 @@
#! /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 os
use warnings; import re
use Test::More tests => 3; import sys
import unittest
from time import time
# 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'};
# Create the rc file.
if (open my $fh, '>', 'time.rc')
{
print $fh "data.location=.\n";
close $fh;
}
# Create some tasks that were started/finished in different weeks, then verify class TestTimesheet(TestCase):
# the presence and grouping in the timesheet report. @classmethod
# P0 pending, this week def setUpClass(cls):
# PS0 started, this week cls.t = Task()
# PS1 started, last week
# PS2 started, 2wks ago
# D0 deleted, this week
# D1 deleted, last week
# D2 deleted, 2wks ago
# C0 completed, this week
# C1 completed, last week
# C2 completed, 2wks ago
my $now = time ();
my $seven = $now - 7 * 86_400;
my $fourteen = $now - 14 * 86_400;
if (open my $fh, '>', 'pending.data') # Create some tasks that were started/finished in different weeks, then verify
{ # the presence and grouping in the timesheet report.
print $fh <<EOF; # P0 pending, this week
[uuid:"00000000-0000-0000-0000-000000000000 " status:"pending" description:"P0" entry:"$fourteen"] # PS0 started, this week
[uuid:"11111111-1111-1111-1111-111111111111 " status:"pending" description:"PS0" entry:"$fourteen" start:"$now"] # PS1 started, last week
[uuid:"22222222-2222-2222-2222-222222222222 " status:"pending" description:"PS1" entry:"$fourteen" start:"$seven"] # PS2 started, 2wks ago
[uuid:"33333333-3333-3333-3333-333333333333 " status:"pending" description:"PS2" entry:"$fourteen" start:"$fourteen"] # D0 deleted, this week
[uuid:"44444444-4444-4444-4444-444444444444 " status:"deleted" description:"D0" entry:"$fourteen" end:"$now"] # D1 deleted, last week
[uuid:"55555555-5555-5555-5555-555555555555 " status:"deleted" description:"D1" entry:"$fourteen" end:"$seven"] # D2 deleted, 2wks ago
[uuid:"66666666-6666-6666-6666-666666666666 " status:"deleted" description:"D2" entry:"$fourteen" end:"$fourteen"] # C0 completed, this week
[uuid:"77777777-7777-7777-7777-777777777777 " status:"completed" description:"C0" entry:"$fourteen" end:"$now"] # C1 completed, last week
[uuid:"88888888-8888-8888-8888-888888888888 " status:"completed" description:"C1" entry:"$fourteen" end:"$seven"] # C2 completed, 2wks ago
[uuid:"99999999-9999-9999-9999-999999999999 " status:"completed" description:"C2" entry:"$fourteen" end:"$fourteen"] now = time()
EOF seven = now - 7 * 86400
close $fh; fourteen = now - 14 * 86400
}
my $output = qx{../src/task rc:time.rc timesheet 2>&1}; cls.t("add P0 entry:{0}".format(fourteen))
like ($output, qr/Completed.+C0.+Started.+PS0/ms, 'one week of started and completed'); cls.t("add PS0 entry:{0} start:{1}".format(fourteen, now))
cls.t("add PS1 entry:{0} start:{1}".format(fourteen, seven))
cls.t("add PS2 entry:{0} start:{0}".format(fourteen))
cls.t("add D0 entry:{0} end:{1}".format(fourteen, now))
cls.t("add D1 entry:{0} end:{1}".format(fourteen, seven))
cls.t("add D2 entry:{0} end:{0}".format(fourteen))
cls.t("/D[0-2]/ delete", input="all\n")
cls.t("log C0 entry:{0} end:{1}".format(fourteen, now))
cls.t("log C1 entry:{0} end:{1}".format(fourteen, seven))
cls.t("log C2 entry:{0} end:{0}".format(fourteen))
$output = qx{../src/task rc:time.rc timesheet 2 2>&1}; def test_one_week(self):
like ($output, qr/Completed.+C0.+Started.+PS0.+Completed.+C1.+Started.+PS1/ms, 'two weeks of started and completed'); """One week of started and completed"""
code, out, err = self.t("timesheet")
$output = qx{../src/task rc:time.rc timesheet 3 2>&1}; expected = re.compile("Completed.+C0.+Started.+PS0", re.DOTALL)
like ($output, qr/Completed.+C0.+Started.+PS0.+Completed.+C1.+Started.+PS1.+Completed.+C2.+Started.+PS2/ms, 'three weeks of started and completed'); self.assertRegexpMatches(out, expected)
# Cleanup. def test_two_weeks(self):
unlink qw(pending.data completed.data undo.data backlog.data time.rc); """Two weeks of started and completed"""
exit 0; code, out, err = self.t("timesheet 2")
expected = re.compile(
"Completed.+C0.+Started.+PS0.+"
"Completed.+C1.+Started.+PS1", re.DOTALL)
self.assertRegexpMatches(out, expected)
def test_three_weeks(self):
"""Three weeks of started and completed"""
code, out, err = self.t("timesheet 3")
expected = re.compile(
"Completed.+C0.+Started.+PS0.+"
"Completed.+C1.+Started.+PS1.+"
"Completed.+C2.+Started.+PS2", re.DOTALL)
self.assertRegexpMatches(out, expected)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4