Test: Converted to Python
This commit is contained in:
161
test/default.t
161
test/default.t
@@ -1,92 +1,91 @@
|
|||||||
#! /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 => 19;
|
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, '>', 'default.rc')
|
|
||||||
{
|
|
||||||
print $fh "data.location=.\n",
|
|
||||||
"default.command=list\n",
|
|
||||||
"default.project=PROJECT\n",
|
|
||||||
"uda.priority.default=M\n",
|
|
||||||
"default.due=eom\n",
|
|
||||||
"dateformat=m/d/Y\n";
|
|
||||||
close $fh;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set up a default command, project and priority.
|
class TestDefaults(TestCase):
|
||||||
qx{../src/task rc:default.rc add all defaults 2>&1};
|
@classmethod
|
||||||
my $output = qx{../src/task rc:default.rc list 2>&1};
|
def setUpClass(cls):
|
||||||
like ($output, qr/ all defaults/, 'task added');
|
"""Executed once before any test in the class"""
|
||||||
like ($output, qr/ PROJECT /, 'default project added');
|
cls.t = Task()
|
||||||
like ($output, qr/ M /, 'default priority added');
|
cls.t.config("default.command", "list")
|
||||||
like ($output, qr/\//, 'default due added');
|
cls.t.config("default.project", "PROJECT")
|
||||||
unlink 'pending.data';
|
cls.t.config("uda.priority.default", "M")
|
||||||
|
cls.t.config("default.due", "eom")
|
||||||
|
|
||||||
qx{../src/task rc:default.rc add project:specific priority:L due:eoy all specified 2>&1};
|
def test_all_defaults(self):
|
||||||
$output = qx{../src/task rc:default.rc list 2>&1};
|
"""Verify all defaults are emplyoed"""
|
||||||
like ($output, qr/ all specified/, 'task added');
|
self.t("add all defaults")
|
||||||
like ($output, qr/ specific /, 'project specified');
|
code, out, err = self.t("export")
|
||||||
like ($output, qr/ L /, 'priority specified');
|
self.assertIn('"description":"all defaults"', out)
|
||||||
like ($output, qr/\//, 'due specified');
|
self.assertIn('"project":"PROJECT"', out)
|
||||||
unlink 'pending.data';
|
self.assertIn('"priority":"M"', out)
|
||||||
|
self.assertIn('"due":"', out)
|
||||||
|
|
||||||
qx{../src/task rc:default.rc add project:specific project specified 2>&1};
|
def test_all_specified(self):
|
||||||
$output = qx{../src/task rc:default.rc list 2>&1};
|
self.t("add project:specific priority:L due:eoy all specified")
|
||||||
like ($output, qr/ project specified/, 'task added');
|
code, out, err = self.t("export")
|
||||||
like ($output, qr/ specific /, 'project specified');
|
self.assertIn('"description":"all specified"', out)
|
||||||
like ($output, qr/ M /, 'default priority added');
|
self.assertIn('"project":"specific"', out)
|
||||||
like ($output, qr/\//, 'default due added');
|
self.assertIn('"priority":"L"', out)
|
||||||
unlink 'pending.data';
|
self.assertIn('"due":"', out)
|
||||||
|
|
||||||
qx{../src/task rc:default.rc add priority:L priority specified 2>&1};
|
def test_project_specified(self):
|
||||||
$output = qx{../src/task rc:default.rc list 2>&1};
|
self.t("add project:specific project specified")
|
||||||
like ($output, qr/ priority specified/, 'task added');
|
code, out, err = self.t("export")
|
||||||
like ($output, qr/ PROJECT /, 'default project added');
|
self.assertIn('"description":"project specified"', out)
|
||||||
like ($output, qr/ L /, 'priority specified');
|
self.assertIn('"project":"specific"', out)
|
||||||
like ($output, qr/\//, 'default due added');
|
self.assertIn('"priority":"M"', out)
|
||||||
|
self.assertIn('"due":"', out)
|
||||||
|
|
||||||
$output = qx{../src/task rc:default.rc 2>&1};
|
def test_priority_specified(self):
|
||||||
like ($output, qr/1 .+ L PROJECT .+ priority specified/, 'default command worked');
|
self.t("add priority:L priority specified")
|
||||||
|
code, out, err = self.t("export")
|
||||||
|
self.assertIn('"description":"priority specified"', out)
|
||||||
|
self.assertIn('"project":"PROJECT"', out)
|
||||||
|
self.assertIn('"priority":"L"', out)
|
||||||
|
self.assertIn('"due":"', out)
|
||||||
|
|
||||||
qx{../src/task rc:default.rc add project:HOME priority:M due:tomorrow all specified 2>&1};
|
def test_default_command(self):
|
||||||
qx{echo 'y' | ../src/task rc:default.rc config default.command 'list priority:M' 2>&1};
|
self.t("add foo")
|
||||||
$output = qx{../src/task rc:default.rc 2>&1};
|
code, out, err = self.t("")
|
||||||
like ($output, qr/ M /, 'priority:M included in default command');
|
self.assertIn("foo", out)
|
||||||
unlike ($output, qr/ L /, 'priority:L excluded from default command');
|
|
||||||
|
|
||||||
# Cleanup.
|
|
||||||
unlink qw(pending.data completed.data undo.data backlog.data default.rc);
|
|
||||||
exit 0;
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from simpletap import TAPTestRunner
|
||||||
|
unittest.main(testRunner=TAPTestRunner())
|
||||||
|
|
||||||
|
# vim: ai sts=4 et sw=4
|
||||||
|
|||||||
Reference in New Issue
Block a user