Tests - Convert add.t to python

* Also added UUID_regex to basetest.utils, likely to be reused
This commit is contained in:
Renato Alves
2015-02-16 15:36:38 +00:00
parent 395b08385b
commit 32d837fb25
2 changed files with 66 additions and 60 deletions

View File

@@ -1,68 +1,72 @@
#! /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'}; from basetest.utils import UUID_regex
delete $ENV{'TASKRC'};
use File::Basename;
my $ut = basename ($0);
my $rc = $ut . '.rc';
# Create the rc file. class TestAdd(TestCase):
if (open my $fh, '>', $rc) def setUp(self):
{ self.t = Task()
print $fh "data.location=.\n", self.t(("add", "This is a test"))
"confirmation=off\n";
close $fh;
}
# Test the add command. def test_add(self):
qx{../src/task rc:$rc add This is a test 2>&1}; "Testing add command"
my $output = qx{../src/task rc:$rc info 1 2>&1};
like ($output, qr/ID\s+1\n/, "$ut: add ID");
like ($output, qr/Description\s+This is a test\n/, "$ut: add ID");
like ($output, qr/Status\s+Pending\n/, "$ut: add Pending");
like ($output, qr/UUID\s+[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\n/,
"$ut: add UUID");
# Test the /// modifier. code, out, err = self.t(("info", "1"))
qx{../src/task rc:$rc 1 modify /test/TEST/ 2>&1};
qx{../src/task rc:$rc 1 modify "/is //" 2>&1};
$output = qx{../src/task rc:$rc info 1 2>&1};
like ($output, qr/ID\s+1\n/, "$ut: add ID");
like ($output, qr/Status\s+Pending\n/, "$ut: add Pending");
like ($output, qr/Description\s+This a TEST\n/, "$ut: add Description");
# Cleanup. self.assertRegexpMatches(out, "ID\s+1\n")
unlink qw(pending.data completed.data undo.data backlog.data), $rc; self.assertRegexpMatches(out, "Description\s+This is a test\n")
exit 0; self.assertRegexpMatches(out, "Status\s+Pending\n")
self.assertRegexpMatches(out, "UUID\s+" + UUID_regex + "\n")
def test_modify_slash(self):
"Test the /// modifier"
self.t(("1", "modify", "/test/TEST/"))
self.t(("1", "modify", "/is //"))
code, out, err = self.t(("info", "1"))
self.assertRegexpMatches(out, "ID\s+1\n")
self.assertRegexpMatches(out, "Status\s+Pending\n")
self.assertRegexpMatches(out, "Description\s+This a TEST\n")
self.assertRegexpMatches(out, "UUID\s+" + UUID_regex + "\n")
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4

View File

@@ -43,6 +43,8 @@ TASKD_SKIP = os.environ.get("TASKD_SKIP", False)
# Environment flags to control use of PATH or in-tree binaries # Environment flags to control use of PATH or in-tree binaries
USE_PATH = os.environ.get("USE_PATH", False) USE_PATH = os.environ.get("USE_PATH", False)
UUID_regex = ("[0-9A-Fa-f]{8}-" + ("[0-9A-Fa-f]{4}-" * 3) + "[0-9A-Fa-f]{12}")
def binary_location(cmd): def binary_location(cmd):
"""If USE_PATH is set rely on PATH to look for task/taskd binaries. """If USE_PATH is set rely on PATH to look for task/taskd binaries.