Test: Converted to Python
This commit is contained in:
159
test/delete.t
159
test/delete.t
@@ -1,89 +1,98 @@
|
|||||||
#! /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 => 12;
|
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 TestDelete(TestCase):
|
||||||
if (open my $fh, '>', $rc)
|
@classmethod
|
||||||
{
|
def setUpClass(cls):
|
||||||
print $fh "data.location=.\n",
|
"""Executed once before any test in the class"""
|
||||||
"confirmation=no\n";
|
|
||||||
close $fh;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add a task, delete it, undelete it.
|
def setUp(self):
|
||||||
my $output = qx{../src/task rc:$rc add one 2>&1; ../src/task rc:$rc info 1 2>&1};
|
"""Executed before each test in the class"""
|
||||||
ok (-r 'pending.data', "$ut: pending.data created");
|
self.t = Task()
|
||||||
like ($output, qr/Status\s+Pending\n/, "$ut: Pending");
|
|
||||||
|
|
||||||
$output = qx{../src/task rc:$rc 1 delete 2>&1; ../src/task rc:$rc info 1 2>&1};
|
def test_add_delete_undo(self):
|
||||||
like ($output, qr/Status\s+Deleted\n/, "$ut: Deleted");
|
"""Verify that add/delete/undo yields a Pending task"""
|
||||||
|
self.t("add one")
|
||||||
|
code, out, err = self.t("_get 1.uuid")
|
||||||
|
uuid = out.strip()
|
||||||
|
|
||||||
$output = qx{../src/task rc:$rc undo 2>&1; ../src/task rc:$rc info 1 2>&1};
|
self.t("1 delete")
|
||||||
like ($output, qr/Status\s+Pending\n/, "$ut: Pending");
|
self.t.runError("list") # GC/handleRecurrence
|
||||||
|
code, out, err = self.t("_get 1.status")
|
||||||
|
self.assertEqual("\n", out)
|
||||||
|
|
||||||
$output = qx{../src/task rc:$rc 1 delete 2>&1; ../src/task rc:$rc list 2>&1 >/dev/null};
|
code, out, err = self.t("_get %s.status" % uuid)
|
||||||
like ($output, qr/No matches./, "$ut: No matches");
|
self.assertIn("deleted\n", out)
|
||||||
ok (-r 'completed.data', "$ut: completed.data created");
|
|
||||||
|
|
||||||
$output = qx{../src/task rc:$rc info 1 2>&1 >/dev/null};
|
self.t("undo")
|
||||||
like ($output, qr/No matches\./, "$ut: No matches");
|
code, out, err = self.t("_get 1.status")
|
||||||
|
self.assertIn("pending\n", out)
|
||||||
|
code, out, err = self.t("_get %s.status" % uuid)
|
||||||
|
self.assertIn("pending\n", out)
|
||||||
|
|
||||||
# Add a task, delete it, and modify on the fly.
|
def test_delete_en_passant(self):
|
||||||
qx{../src/task rc:$rc add one two 2>&1};
|
"""Verify that en-passant works with delete"""
|
||||||
$output = qx{../src/task rc:$rc list 2>&1};
|
self.t("add foo")
|
||||||
like ($output, qr/one two/, "$ut: Second task added");
|
code, out, err = self.t("1 delete project:work")
|
||||||
|
self.assertIn("Deleted 1 task.", out)
|
||||||
|
|
||||||
qx{../src/task rc:$rc 1 delete foo pri:H 2>&1};
|
code, out, err = self.t("all rc.verbose:nothing")
|
||||||
$output = qx{../src/task rc:$rc 1 info 2>&1};
|
self.assertIn("work", out)
|
||||||
like ($output, qr/foo/, "$ut: Deletion annotation successful");
|
|
||||||
like ($output, qr/H/, "$ut: Deletion modification successful");
|
|
||||||
|
|
||||||
# Add a task, complete it, then delete it.
|
def test_add_done_delete(self):
|
||||||
qx{../src/task rc:$rc add three 2>&1};
|
"""Verify that a completed task can be deleted"""
|
||||||
$output = qx{../src/task rc:$rc 2 info 2>&1};
|
self.t("add foo")
|
||||||
like ($output, qr/three/, "$ut: added and verified new task");
|
code, out, err = self.t("_get 1.uuid")
|
||||||
my ($uuid) = $output =~ /UUID\s+(\S+)/;
|
uuid = out.strip()
|
||||||
qx{../src/task rc:$rc 2 done 2>&1};
|
|
||||||
qx{../src/task rc:$rc $uuid delete 2>&1};
|
|
||||||
$output = qx{../src/task rc:$rc $uuid info 2>&1};
|
|
||||||
like ($output, qr/Deleted/, "$ut: task added, completed, then deleted");
|
|
||||||
|
|
||||||
# Cleanup.
|
code, out, err = self.t("1 done")
|
||||||
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
|
self.assertIn("Completed 1 task.", out)
|
||||||
exit 0;
|
|
||||||
|
|
||||||
|
self.t("all") # GC/handleRecurrence
|
||||||
|
|
||||||
|
code, out, err = self.t("%s delete" % uuid)
|
||||||
|
self.assertIn("Deleted 1 task.", out)
|
||||||
|
|
||||||
|
code, out, err = self.t("_get %s.status" % uuid)
|
||||||
|
self.assertIn("deleted\n", out)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from simpletap import TAPTestRunner
|
||||||
|
unittest.main(testRunner=TAPTestRunner())
|
||||||
|
|
||||||
|
# vim: ai sts=4 et sw=4
|
||||||
|
|||||||
Reference in New Issue
Block a user