Test: Converted to Python

This commit is contained in:
Paul Beckingham
2015-07-23 09:55:47 -04:00
parent 9dc6772f78
commit 298c9b2dde

View File

@@ -1,164 +1,389 @@
#! /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 => 39; 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 TestTags(TestCase):
if (open my $fh, '>', $rc) @classmethod
{ def setUpClass(cls):
print $fh "data.location=.\n", """Executed once before any test in the class"""
"confirmation=off\n", cls.t = Task()
"verbose=nothing\n";
close $fh;
}
# Add task with tags. def setUp(self):
my $output = qx{../src/task rc:$rc add +one This +two is a test +three 2>&1; ../src/task rc:$rc info 1 2>&1}; """Executed before each test in the class"""
like ($output, qr/^Tags\s+one two three\n/m, "$ut: tags found");
# Remove tags. def test_tag_manipulation(self):
$output = qx{../src/task rc:$rc 1 modify -three -two -one 2>&1; ../src/task rc:$rc info 1 2>&1}; """Test addition and removal of tags"""
unlike ($output, qr/^Tags/m, "$ut: -three -two -one tag removed"); self.t("add +one This +two is a test +three")
code, out, err = self.t("_get 1.tags")
self.assertEqual("one,two,three\n", out)
# Add tags. # Remove tags.
$output = qx{../src/task rc:$rc 1 modify +four +five +six 2>&1; ../src/task rc:$rc info 1 2>&1}; self.t("1 modify -three -two -one")
like ($output, qr/^Tags\s+four five six\n/m, "$ut: tags found"); code, out, err = self.t("_get 1.tags")
self.assertEqual("\n", out)
# Remove tags. # Add tags.
$output = qx{../src/task rc:$rc 1 modify -four -five -six 2>&1; ../src/task rc:$rc info 1 2>&1}; self.t("1 modify +four +five +six")
unlike ($output, qr/^Tags/m, "$ut: -four -five -six tag removed"); code, out, err = self.t("_get 1.tags")
self.assertEqual("four,five,six\n", out)
# Add and remove tags. # Remove tags.
$output = qx{../src/task rc:$rc 1 modify +duplicate -duplicate 2>&1; ../src/task rc:$rc info 1 2>&1}; self.t("1 modify -four -five -six")
unlike ($output, qr/^Tags/m, "$ut: +duplicate -duplicate NOP"); code, out, err = self.t("_get 1.tags")
self.assertEqual("\n", out)
# Remove missing tag. # Add and remove tags.
$output = qx{../src/task rc:$rc 1 modify -missing 2>&1; ../src/task rc:$rc info 1 2>&1}; self.t("1 modify +duplicate -duplicate")
unlike ($output, qr/^Tags/m, "$ut: -missing NOP"); code, out, err = self.t("_get 1.tags")
self.assertEqual("\n", out)
# Virtual tag testing. # Remove missing tag.
qx{../src/task rc:$rc log completed 2>&1}; code, out, err = self.t("1 modify -missing")
qx{../src/task rc:$rc add deleted 2>&1; ../src/task rc:$rc 2 delete 2>&1}; self.assertIn("Modified 0 tasks", out)
qx{../src/task rc:$rc add minimal 2>&1};
qx{../src/task rc:$rc add maximal +tag pro:PRO pri:H due:yesterday 2>&1};
qx{../src/task rc:$rc 4 start 2>&1};
qx{../src/task rc:$rc 4 annotate note 2>&1};
qx{../src/task rc:$rc add blocked depends:1 2>&1};
qx{../src/task rc:$rc add due_eom due:eom 2>&1};
qx{../src/task rc:$rc add due_eow due:eow 2>&1};
$output = qx{../src/task rc:$rc +COMPLETED all}; class TestVirtualTags(TestCase):
like ($output, qr/completed/, "$ut: +COMPLETED"); @classmethod
$output = qx{../src/task rc:$rc -COMPLETED all}; def setUpClass(cls):
unlike ($output, qr/completed/, "$ut: -COMPLETED"); """Executed once before any test in the class"""
cls.t = Task()
cls.t.config("verbose", "nothing")
cls.t("log completed")
cls.t("add deleted")
cls.t("1 delete")
cls.t("add minimal")
cls.t("add maximal +tag pro:PRO pri:H due:yesterday")
cls.t("3 start")
cls.t("3 annotate note")
cls.t("add blocked depends:2")
cls.t("add due_eom due:eom")
cls.t("add due_eow due:eow")
$output = qx{../src/task rc:$rc +DELETED all}; def setUp(self):
like ($output, qr/deleted/, "$ut: +DELETED"); """Executed before each test in the class"""
$output = qx{../src/task rc:$rc -DELETED all};
unlike ($output, qr/deleted/, "$ut: -DELETED");
$output = qx{../src/task rc:$rc +PENDING all}; def test_virtual_tag_COMPLETED(self):
like ($output, qr/minimal/, "$ut: +PENDING"); """Verify 'COMPLETED' appears when expected"""
$output = qx{../src/task rc:$rc -PENDING all}; code, out, err = self.t("+COMPLETED all")
unlike ($output, qr/minimal/, "$ut: -PENDING"); self.assertIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
$output = qx{../src/task rc:$rc +TAGGED list}; code, out, err = self.t("-COMPLETED all")
like ($output, qr/maximal/, "$ut: +TAGGED"); self.assertNotIn("completed", out)
$output = qx{../src/task rc:$rc -TAGGED list}; self.assertIn("deleted", out)
unlike ($output, qr/maximal/, "$ut: -TAGGED"); self.assertIn("minimal", out)
self.assertIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
$output = qx{../src/task rc:$rc +OVERDUE list}; def test_virtual_tag_DELETED(self):
like ($output, qr/maximal/, "$ut: +OVERDUE"); """Verify 'DELETED' appears when expected"""
$output = qx{../src/task rc:$rc -OVERDUE list}; code, out, err = self.t("+DELETED all")
unlike ($output, qr/maximal/, "$ut: -OVERDUE"); self.assertNotIn("completed", out)
self.assertIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
$output = qx{../src/task rc:$rc +BLOCKED list}; code, out, err = self.t("-DELETED all")
like ($output, qr/blocked/, "$ut: +BLOCKED"); self.assertIn("completed", out)
$output = qx{../src/task rc:$rc -BLOCKED list}; self.assertNotIn("deleted", out)
unlike ($output, qr/blocked/, "$ut: -BLOCKED"); self.assertIn("minimal", out)
self.assertIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
$output = qx{../src/task rc:$rc +BLOCKING list}; def test_virtual_tag_PENDING(self):
like ($output, qr/This is a test/, "$ut: +BLOCKING"); """Verify 'PENDING' appears when expected"""
$output = qx{../src/task rc:$rc -BLOCKING list}; code, out, err = self.t("+PENDING all")
unlike ($output, qr/This is a test/, "$ut: -BLOCKING"); self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertIn("minimal", out)
self.assertIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
$output = qx{../src/task rc:$rc +UNBLOCKED list}; code, out, err = self.t("-PENDING all")
like ($output, qr/minimal/, "$ut: +UNBLOCKED"); self.assertIn("completed", out)
$output = qx{../src/task rc:$rc -UNBLOCKED list}; self.assertIn("deleted", out)
unlike ($output, qr/minimal/, "$ut: -UNBLOCKED"); self.assertNotIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
$output = qx{../src/task rc:$rc +YEAR list}; def test_virtual_tag_TAGGED(self):
like ($output, qr/due_eom/, "$ut: +YEAR"); """Verify 'TAGGED' appears when expected"""
$output = qx{../src/task rc:$rc -YEAR list}; code, out, err = self.t("+TAGGED all")
unlike ($output, qr/due_eom/, "$ut: -YEAR"); self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
$output = qx{../src/task rc:$rc +MONTH list}; code, out, err = self.t("-TAGGED all")
like ($output, qr/due_eom/, "$ut: +MONTH"); self.assertIn("completed", out)
$output = qx{../src/task rc:$rc -MONTH list}; self.assertIn("deleted", out)
unlike ($output, qr/due_eom/, "$ut: -MONTH"); self.assertIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
$output = qx{../src/task rc:$rc +WEEK list}; def test_virtual_tag_OVERDUE(self):
like ($output, qr/due_eow/, "$ut: +WEEK"); """Verify 'OVERDUE' appears when expected"""
$output = qx{../src/task rc:$rc -WEEK list}; code, out, err = self.t("+OVERDUE all")
unlike ($output, qr/due_eow/, "$ut: -WEEK"); self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
$output = qx{../src/task rc:$rc +ACTIVE list}; code, out, err = self.t("-OVERDUE all")
like ($output, qr/maximal/, "$ut: +ACTIVE"); self.assertIn("completed", out)
$output = qx{../src/task rc:$rc -ACTIVE list}; self.assertIn("deleted", out)
unlike ($output, qr/maximal/, "$ut: -ACTIVE"); self.assertIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
$output = qx{../src/task rc:$rc +ANNOTATED list}; def test_virtual_tag_BLOCKED(self):
like ($output, qr/maximal/, "$ut: +ANNOTATED"); """Verify 'BLOCKED' appears when expected"""
$output = qx{../src/task rc:$rc -ANNOTATED list}; code, out, err = self.t("+BLOCKED all")
unlike ($output, qr/maximal/, "$ut: -ANNOTATED"); self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
qx{../src/task rc:$rc add seven tags:A,A,B,C,C,C}; code, out, err = self.t("-BLOCKED all")
$output = qx{../src/task rc:$rc /seven/ list}; self.assertIn("completed", out)
like ($output, qr/ A B C /, 'Direct tags setting enforces uniqueness'); self.assertIn("deleted", out)
self.assertIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
$output = qx{../src/task rc:$rc _tags}; def test_virtual_tag_BLOCKING(self):
like ($output, qr/PENDING/, '_tags contains PENDING'); """Verify 'BLOCKING' appears when expected"""
like ($output, qr/next/, '_tags contains next'); code, out, err = self.t("+BLOCKING all")
like ($output, qr/nocal/, '_tags contains nocal'); self.assertNotIn("completed", out)
like ($output, qr/nocolor/, '_tags contains nocolor'); self.assertNotIn("deleted", out)
like ($output, qr/nonag/, '_tags contains nonag'); self.assertIn("minimal", out)
like ($output, qr/tag/, '_tags contains tag'); self.assertNotIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
# Cleanup. code, out, err = self.t("-BLOCKING all")
unlink qw(pending.data completed.data undo.data backlog.data), $rc; self.assertIn("completed", out)
exit 0; self.assertIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
def test_virtual_tag_UNBLOCKED(self):
"""Verify 'UNBLOCKED' appears when expected"""
code, out, err = self.t("+UNBLOCKED all")
self.assertIn("completed", out)
self.assertIn("deleted", out)
self.assertIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
code, out, err = self.t("-UNBLOCKED all")
self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
def test_virtual_tag_YEAR(self):
"""Verify 'YEAR' appears when expected"""
code, out, err = self.t("+YEAR all")
self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
code, out, err = self.t("-YEAR all")
self.assertIn("completed", out)
self.assertIn("deleted", out)
self.assertIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
def test_virtual_tag_MONTH(self):
"""Verify 'MONTH' appears when expected"""
code, out, err = self.t("+MONTH all")
self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
code, out, err = self.t("-MONTH all")
self.assertIn("completed", out)
self.assertIn("deleted", out)
self.assertIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
def test_virtual_tag_WEEK(self):
"""Verify 'WEEK' appears when expected"""
code, out, err = self.t("+WEEK all")
self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertIn("due_eow", out)
code, out, err = self.t("-WEEK all")
self.assertIn("completed", out)
self.assertIn("deleted", out)
self.assertIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertNotIn("due_eow", out)
def test_virtual_tag_ACTIVE(self):
"""Verify 'ACTIVE' appears when expected"""
code, out, err = self.t("+ACTIVE all")
self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
code, out, err = self.t("-ACTIVE all")
self.assertIn("completed", out)
self.assertIn("deleted", out)
self.assertIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
def test_virtual_tag_ANNOTATED(self):
"""Verify 'ANNOTATED' appears when expected"""
code, out, err = self.t("+ANNOTATED all")
self.assertNotIn("completed", out)
self.assertNotIn("deleted", out)
self.assertNotIn("minimal", out)
self.assertIn("maximal", out)
self.assertNotIn("blocked", out)
self.assertNotIn("due_eom", out)
self.assertNotIn("due_eow", out)
code, out, err = self.t("-ANNOTATED all")
self.assertIn("completed", out)
self.assertIn("deleted", out)
self.assertIn("minimal", out)
self.assertNotIn("maximal", out)
self.assertIn("blocked", out)
self.assertIn("due_eom", out)
self.assertIn("due_eow", out)
def test_virtual_tags_helper(self):
"""Verify '_tags' shows appropriate tags"""
code, out, err = self.t("_tags")
self.assertIn("PENDING", out)
self.assertIn("next", out)
self.assertIn("nocal", out)
self.assertIn("nocolor", out)
self.assertIn("nonag", out)
self.assertIn("tag", out)
class TestDuplicateTags(TestCase):
@classmethod
def setUpClass(cls):
"""Executed once before any test in the class"""
cls.t = Task()
cls.t.config("verbose", "nothing")
def setUp(self):
"""Executed before each test in the class"""
def test_duplicate_tags(self):
"""When using the 'tags' attribute directly, make sure it strips duplicates"""
self.t("add one tags:A,A,B,C,C,C")
code, out, err = self.t("_get 1.tags")
self.assertEqual("A,B,C\n", out)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4