mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Unit Tests
- Eliminated the Perl template, overwriting it with the Python template.
This commit is contained in:
parent
560f41a930
commit
f9ab71685d
2 changed files with 48 additions and 108 deletions
|
@ -1,56 +0,0 @@
|
||||||
#!/usr/bin/env python2.7
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
# Ensure python finds the local simpletap module
|
|
||||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
class TestCase(unittest.TestCase):
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls):
|
|
||||||
"""Executed once before any test in the class"""
|
|
||||||
# Empty rc file
|
|
||||||
open("version.rc", 'w').close()
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
"""Executed before each test in the class"""
|
|
||||||
|
|
||||||
def testVersion(self):
|
|
||||||
"""Copyright is current"""
|
|
||||||
command = ["../src/task", "rc:version.rc", "version"]
|
|
||||||
|
|
||||||
# Merge STDOUT and STDERR
|
|
||||||
p = Popen(command, stdout=PIPE, stderr=STDOUT)
|
|
||||||
out, err = p.communicate()
|
|
||||||
|
|
||||||
expected = "Copyright \(C\) \d{4} - %d" % (datetime.now().year,)
|
|
||||||
self.assertRegexpMatches(out.decode("utf8"), expected)
|
|
||||||
|
|
||||||
def testFailOther(self):
|
|
||||||
"""Nothing to do with Copyright"""
|
|
||||||
self.assertEqual("I like to code", "I like\nto code\n")
|
|
||||||
|
|
||||||
@unittest.skipIf(1 != 0, "This machine has sane logic")
|
|
||||||
def testSkipped(self):
|
|
||||||
"""Test all logic of the world"""
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
"""Executed after each test in the class"""
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
"""Executed once after all tests in the class"""
|
|
||||||
os.remove("version.rc")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from simpletap import TAPTestRunner
|
|
||||||
unittest.main(testRunner=TAPTestRunner())
|
|
||||||
|
|
||||||
# vim: ai sts=4 et sw=4
|
|
100
test/template.t
100
test/template.t
|
@ -1,60 +1,56 @@
|
||||||
#! /usr/bin/env perl
|
#!/usr/bin/env python2.7
|
||||||
################################################################################
|
# -*- coding: utf-8 -*-
|
||||||
##
|
|
||||||
## Copyright 2006 - 2014, 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
|
|
||||||
## in the Software without restriction, including without limitation the rights
|
|
||||||
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
## 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
||||||
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
## 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
|
|
||||||
##
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
use strict;
|
import sys
|
||||||
use warnings;
|
import os
|
||||||
use Test::More tests => 2;
|
# Ensure python finds the local simpletap module
|
||||||
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
# Ensure environment has no influence.
|
import unittest
|
||||||
delete $ENV{'TASKDATA'};
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
delete $ENV{'TASKRC'};
|
from datetime import datetime
|
||||||
|
|
||||||
use File::Basename;
|
|
||||||
my $ut = basename ($0);
|
|
||||||
my $rc = $ut . '.rc';
|
|
||||||
|
|
||||||
# Create the rc file.
|
class TestCase(unittest.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";
|
# Empty rc file
|
||||||
close $fh;
|
open("version.rc", 'w').close()
|
||||||
}
|
|
||||||
|
|
||||||
# Note: all commands checked for $? == 0
|
def setUp(self):
|
||||||
# Note: all commands redirect 2>&1
|
"""Executed before each test in the class"""
|
||||||
|
|
||||||
# Bug <id> - <description>
|
def testVersion(self):
|
||||||
qx{../src/task rc:$rc add sample 2>&1};
|
"""Copyright is current"""
|
||||||
ok ($? == 0, "$ut: add sample");
|
command = ["../src/task", "rc:version.rc", "version"]
|
||||||
|
|
||||||
my $output = qx{../src/task rc:$rc ls 2>&1};
|
# Merge STDOUT and STDERR
|
||||||
like ($output, qr/sample/ms, "$ut: sample task found");
|
p = Popen(command, stdout=PIPE, stderr=STDOUT)
|
||||||
|
out, err = p.communicate()
|
||||||
|
|
||||||
# Cleanup.
|
expected = "Copyright \(C\) \d{4} - %d" % (datetime.now().year,)
|
||||||
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
|
self.assertRegexpMatches(out.decode("utf8"), expected)
|
||||||
exit 0;
|
|
||||||
|
def testFailOther(self):
|
||||||
|
"""Nothing to do with Copyright"""
|
||||||
|
self.assertEqual("I like to code", "I like\nto code\n")
|
||||||
|
|
||||||
|
@unittest.skipIf(1 != 0, "This machine has sane logic")
|
||||||
|
def testSkipped(self):
|
||||||
|
"""Test all logic of the world"""
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""Executed after each test in the class"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
"""Executed once after all tests in the class"""
|
||||||
|
os.remove("version.rc")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from simpletap import TAPTestRunner
|
||||||
|
unittest.main(testRunner=TAPTestRunner())
|
||||||
|
|
||||||
|
# vim: ai sts=4 et sw=4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue