Test: Converted to Python

This commit is contained in:
Paul Beckingham
2015-07-03 21:01:41 -04:00
parent e516f2bf65
commit 2d90a7bb96

View File

@@ -1,82 +1,92 @@
#! /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 => 7; 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'};
# Create the rc file.
if (open my $fh, '>', 'subst.rc')
{
print $fh "data.location=.\n",
"regex=off\n";
close $fh;
}
# Test the substitution command. class TestSubstitutions(TestCase):
qx{../src/task rc:subst.rc add foo foo foo 2>&1};
qx{../src/task rc:subst.rc 1 modify /foo/FOO/ 2>&1};
my $output = qx{../src/task rc:subst.rc info 1 2>&1};
like ($output, qr/FOO foo foo/, 'substitution in description');
qx{../src/task rc:subst.rc 1 modify /foo/FOO/g 2>&1}; def setUp(self):
$output = qx{../src/task rc:subst.rc info 1 2>&1}; """Executed before each test in the class"""
like ($output, qr/FOO FOO FOO/, 'global substitution in description'); self.t = Task()
# Test the substitution command on annotations. def test_substitution(self):
qx{../src/task rc:subst.rc 1 annotate bar bar bar 2>&1}; """Verify substitution for task description"""
qx{../src/task rc:subst.rc 1 modify /bar/BAR/ 2>&1}; self.t.config("regex", "off")
$output = qx{../src/task rc:subst.rc info 1 2>&1};
like ($output, qr/BAR bar bar/, 'substitution in annotation');
qx{../src/task rc:subst.rc 1 modify /bar/BAR/g 2>&1}; self.t("add foo foo foo")
$output = qx{../src/task rc:subst.rc info 1 2>&1}; self.t("1 modify /foo/FOO/")
like ($output, qr/BAR BAR BAR/, 'global substitution in annotation'); code, out, err = self.t("_get 1.description")
self.assertEqual("FOO foo foo\n", out)
qx{../src/task rc:subst.rc 1 modify /FOO/aaa/ 2>&1}; self.t("1 modify /foo/FOO/g")
qx{../src/task rc:subst.rc 1 modify /FOO/bbb/ 2>&1}; code, out, err = self.t("_get 1.description")
qx{../src/task rc:subst.rc 1 modify /FOO/ccc/ 2>&1}; self.assertEqual("FOO FOO FOO\n", out)
$output = qx{../src/task rc:subst.rc info 1 2>&1};
like ($output, qr/aaa bbb ccc/, 'individual successive substitution in description');
qx{../src/task rc:subst.rc 1 modify /bbb// 2>&1}; self.t("1 modify /FOO/aaa/")
$output = qx{../src/task rc:subst.rc info 1 2>&1}; self.t("1 modify /FOO/bbb/")
like ($output, qr/aaa ccc/, 'word deletion in description'); self.t("1 modify /FOO/ccc/")
code, out, err = self.t("_get 1.description")
self.assertEqual("aaa bbb ccc\n", out)
# Regexes self.t("1 modify /bbb//")
qx{../src/task rc:subst.rc rc.regex:on 1 modify "/c{3}/CcC/" 2>&1}; code, out, err = self.t("_get 1.description")
$output = qx{../src/task rc:subst.rc info 1 2>&1}; self.assertEqual("aaa ccc\n", out)
like ($output, qr/aaa CcC/, 'regex');
# Cleanup. def test_substitution_annotation(self):
unlink qw(pending.data completed.data undo.data backlog.data subst.rc); """Verify substitution for task annotation"""
exit 0; self.t("add foo foo foo")
self.t("1 annotate bar bar bar")
self.t("1 modify /bar/BAR/")
code, out, err = self.t("_get 1.annotations.1.description")
self.assertEqual("BAR bar bar\n", out)
self.t("1 modify /bar/BAR/g")
code, out, err = self.t("_get 1.annotations.1.description")
self.assertEqual("BAR BAR BAR\n", out)
def test_substitution_regex(self):
"""Verify regex substitution for task description"""
self.t.config("regex", "on")
self.t("add aaa bbb")
self.t("1 modify /b{3}/BbB/")
code, out, err = self.t("_get 1.description")
self.assertEqual("aaa BbB\n", out)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4