Unit Tests

- Converted filter-prefix.t to Python.  Still needs a rename and possible merge
  with other tests.
This commit is contained in:
Paul Beckingham 2015-03-07 11:11:18 -05:00
parent ebd6977480
commit a2cae67644

View file

@ -1,130 +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 => 56; import unittest
from datetime import datetime
# 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 TestFilterPrefix(TestCase):
if (open my $fh, '>', $rc) @classmethod
{ def setUpClass(cls):
print $fh "data.location=.\n"; """Executed once before any test in the class"""
close $fh; cls.t = Task()
} cls.t.config("verbose", "nothing")
# Test the filters. cls.t(('add', 'project:foo.uno', 'priority:H', '+tag', 'one foo' ))
qx{../src/task rc:$rc add project:foo.uno priority:H +tag one foo 2>&1}; cls.t(('add', 'project:foo.dos', 'priority:H', 'two' ))
qx{../src/task rc:$rc add project:foo.dos priority:H two 2>&1}; cls.t(('add', 'project:foo.tres', 'three' ))
qx{../src/task rc:$rc add project:foo.tres three 2>&1}; cls.t(('add', 'project:bar.uno', 'priority:H', 'four' ))
qx{../src/task rc:$rc add project:bar.uno priority:H four 2>&1}; cls.t(('add', 'project:bar.dos', '+tag', 'five' ))
qx{../src/task rc:$rc add project:bar.dos +tag five 2>&1}; cls.t(('add', 'project:bar.tres', 'six foo' ))
qx{../src/task rc:$rc add project:bar.tres six foo 2>&1}; cls.t(('add', 'project:bazuno', 'seven bar foo'))
qx{../src/task rc:$rc add project:bazuno seven bar foo 2>&1}; cls.t(('add', 'project:bazdos', 'eight bar foo'))
qx{../src/task rc:$rc add project:bazdos eight bar foo 2>&1};
my $output = qx{../src/task rc:$rc list 2>&1}; def test_list_all(self):
like ($output, qr/one/, 'a1'); """No filter shows all tasks."""
like ($output, qr/two/, 'a2'); code, out, err = self.t(('list',))
like ($output, qr/three/, 'a3'); self.assertIn('one', out)
like ($output, qr/four/, 'a4'); self.assertIn('two', out)
like ($output, qr/five/, 'a5'); self.assertIn('three', out)
like ($output, qr/six/, 'a6'); self.assertIn('four', out)
like ($output, qr/seven/, 'a7'); self.assertIn('five', out)
like ($output, qr/eight/, 'a8'); self.assertIn('six', out)
self.assertIn('seven', out)
self.assertIn('eight', out)
$output = qx{../src/task rc:$rc list project:foo 2>&1}; def test_list_project_foo(self):
like ($output, qr/one/, 'b1'); """No filter shows all tasks."""
like ($output, qr/two/, 'b2'); code, out, err = self.t(('list', 'project:foo'))
like ($output, qr/three/, 'b3'); self.assertIn('one', out)
unlike ($output, qr/four/, 'b4'); self.assertIn('two', out)
unlike ($output, qr/five/, 'b5'); self.assertIn('three', out)
unlike ($output, qr/six/, 'b6'); self.assertNotIn('four', out)
unlike ($output, qr/seven/, 'b7'); self.assertNotIn('five', out)
unlike ($output, qr/eight/, 'b8'); self.assertNotIn('six', out)
self.assertNotIn('seven', out)
self.assertNotIn('eight', out)
$output = qx{../src/task rc:$rc list project.not:foo 2>&1}; def test_list_project_not_foo(self):
unlike ($output, qr/one/, 'c1'); """No filter shows all tasks."""
unlike ($output, qr/two/, 'c2'); code, out, err = self.t(('list', 'project.not:foo'))
unlike ($output, qr/three/, 'c3'); self.assertNotIn('one', out)
like ($output, qr/four/, 'c4'); self.assertNotIn('two', out)
like ($output, qr/five/, 'c5'); self.assertNotIn('three', out)
like ($output, qr/six/, 'c6'); self.assertIn('four', out)
like ($output, qr/seven/, 'c7'); self.assertIn('five', out)
like ($output, qr/eight/, 'c8'); self.assertIn('six', out)
self.assertIn('seven', out)
self.assertIn('eight', out)
$output = qx{../src/task rc:$rc list project.startswith:bar 2>&1}; def test_list_project_startwsith_bar(self):
unlike ($output, qr/one/, 'd1'); """No filter shows all tasks."""
unlike ($output, qr/two/, 'd2'); code, out, err = self.t(('list', 'project.startswith:bar'))
unlike ($output, qr/three/, 'd3'); self.assertNotIn('one', out)
like ($output, qr/four/, 'd4'); self.assertNotIn('two', out)
like ($output, qr/five/, 'd5'); self.assertNotIn('three', out)
like ($output, qr/six/, 'd6'); self.assertIn('four', out)
unlike ($output, qr/seven/, 'd7'); self.assertIn('five', out)
unlike ($output, qr/eight/, 'd8'); self.assertIn('six', out)
self.assertNotIn('seven', out)
self.assertNotIn('eight', out)
$output = qx{../src/task rc:$rc list project:ba 2>&1}; def test_list_project_ba(self):
unlike ($output, qr/one/, 'f1'); """No filter shows all tasks."""
unlike ($output, qr/two/, 'f2'); code, out, err = self.t(('list', 'project:ba'))
unlike ($output, qr/three/, 'f3'); self.assertNotIn('one', out)
like ($output, qr/four/, 'f4'); self.assertNotIn('two', out)
like ($output, qr/five/, 'f5'); self.assertNotIn('three', out)
like ($output, qr/six/, 'f6'); self.assertIn('four', out)
like ($output, qr/seven/, 'f7'); self.assertIn('five', out)
like ($output, qr/eight/, 'f8'); self.assertIn('six', out)
self.assertIn('seven', out)
self.assertIn('eight', out)
$output = qx{../src/task rc:$rc list project.not:ba 2>&1}; def test_list_project_not_ba(self):
like ($output, qr/one/, 'g1'); """No filter shows all tasks."""
like ($output, qr/two/, 'g2'); code, out, err = self.t(('list', 'project.not:ba'))
like ($output, qr/three/, 'g3'); self.assertIn('one', out)
unlike ($output, qr/four/, 'g4'); self.assertIn('two', out)
unlike ($output, qr/five/, 'g5'); self.assertIn('three', out)
unlike ($output, qr/six/, 'g6'); self.assertNotIn('four', out)
unlike ($output, qr/seven/, 'g7'); self.assertNotIn('five', out)
unlike ($output, qr/eight/, 'g8'); self.assertNotIn('six', out)
self.assertNotIn('seven', out)
self.assertNotIn('eight', out)
$output = qx{../src/task rc:$rc list description.has:foo 2>&1}; def test_list_descrtiption_has_foo(self):
like ($output, qr/one/, 'i1'); """No filter shows all tasks."""
unlike ($output, qr/two/, 'i2'); code, out, err = self.t(('list', 'description.has:foo'))
unlike ($output, qr/three/, 'i3'); self.assertIn('one', out)
unlike ($output, qr/four/, 'i4'); self.assertNotIn('two', out)
unlike ($output, qr/five/, 'i5'); self.assertNotIn('three', out)
like ($output, qr/six/, 'i6'); self.assertNotIn('four', out)
like ($output, qr/seven/, 'i7'); self.assertNotIn('five', out)
like ($output, qr/eight/, 'i8'); self.assertIn('six', out)
self.assertIn('seven', out)
self.assertIn('eight', out)
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
exit 0;
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4