mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Test: Converted to Python
This commit is contained in:
parent
e55528e21e
commit
29486144c9
1 changed files with 111 additions and 125 deletions
236
test/oldest.t
236
test/oldest.t
|
@ -1,137 +1,123 @@
|
||||||
#! /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 => 48;
|
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'};
|
|
||||||
|
|
||||||
use File::Basename;
|
|
||||||
my $ut = basename ($0);
|
|
||||||
my $rc = $ut . '.rc';
|
|
||||||
|
|
||||||
# Create the rc file.
|
class TestOldestAndNewest(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("add one entry:2015-07-10T10:30:00")
|
||||||
|
cls.t("add two entry:2015-07-10T10:30:01")
|
||||||
|
cls.t("add three entry:2015-07-10T10:30:02")
|
||||||
|
cls.t("add four entry:2015-07-10T10:30:03")
|
||||||
|
cls.t("add five entry:2015-07-10T10:30:04")
|
||||||
|
cls.t("add six entry:2015-07-10T10:30:05")
|
||||||
|
cls.t("add seven entry:2015-07-10T10:30:06")
|
||||||
|
cls.t("add eight entry:2015-07-10T10:30:07")
|
||||||
|
cls.t("add nine entry:2015-07-10T10:30:08")
|
||||||
|
cls.t("add ten entry:2015-07-10T10:30:09")
|
||||||
|
cls.t("add eleven entry:2015-07-10T10:30:10")
|
||||||
|
|
||||||
# Create 11 tasks, progressively 1 second newer.
|
def setUp(self):
|
||||||
if (open my $fh, '>', 'pending.data')
|
"""Executed before each test in the class"""
|
||||||
{
|
|
||||||
my $entry = time () - 3600; # An hour ago.
|
|
||||||
|
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000001" status:"pending" description:"one" entry:"$entry"]\n};
|
def test_oldest_ten(self):
|
||||||
$entry++;
|
"""Test oldest report + limit:10"""
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000002" status:"pending" description:"two" entry:"$entry"]\n};
|
code, out, err = self.t("oldest limit:10")
|
||||||
$entry++;
|
self.assertIn(" one", out)
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000003" status:"pending" description:"three" entry:"$entry"]\n};
|
self.assertIn(" two", out)
|
||||||
$entry++;
|
self.assertIn(" three", out)
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000004" status:"pending" description:"four" entry:"$entry"]\n};
|
self.assertIn(" four", out)
|
||||||
$entry++;
|
self.assertIn(" five", out)
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000005" status:"pending" description:"five" entry:"$entry"]\n};
|
self.assertIn(" six", out)
|
||||||
$entry++;
|
self.assertIn(" seven", out)
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000006" status:"pending" description:"six" entry:"$entry"]\n};
|
self.assertIn(" eight", out)
|
||||||
$entry++;
|
self.assertIn(" nine", out)
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000007" status:"pending" description:"seven" entry:"$entry"]\n};
|
self.assertIn(" ten", out)
|
||||||
$entry++;
|
self.assertNotIn(" eleven", out)
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000008" status:"pending" description:"eight" entry:"$entry"]\n};
|
|
||||||
$entry++;
|
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000009" status:"pending" description:"nine" entry:"$entry"]\n};
|
|
||||||
$entry++;
|
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000010" status:"pending" description:"ten" entry:"$entry"]\n};
|
|
||||||
$entry++;
|
|
||||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000011" status:"pending" description:"eleven" entry:"$entry"]\n};
|
|
||||||
$entry++;
|
|
||||||
|
|
||||||
close $fh;
|
def test_oldest_three(self):
|
||||||
}
|
"""Test oldest report + limit:3"""
|
||||||
|
code, out, err = self.t("oldest limit:3")
|
||||||
|
self.assertIn(" one", out)
|
||||||
|
self.assertIn(" two", out)
|
||||||
|
self.assertIn(" three", out)
|
||||||
|
self.assertNotIn(" four", out)
|
||||||
|
self.assertNotIn(" five", out)
|
||||||
|
self.assertNotIn(" six", out)
|
||||||
|
self.assertNotIn(" seven", out)
|
||||||
|
self.assertNotIn(" eight", out)
|
||||||
|
self.assertNotIn(" nine", out)
|
||||||
|
self.assertNotIn(" ten", out)
|
||||||
|
self.assertNotIn(" eleven", out)
|
||||||
|
|
||||||
my $output = qx{../src/task rc:$rc oldest limit:10 2>&1};
|
def test_newest_ten(self):
|
||||||
ok ($? == 0, "$ut: oldest limit:10");
|
"""Test newest report + limit:10"""
|
||||||
like ($output, qr/ one/, "$ut: oldest limit:10: one");
|
code, out, err = self.t("newest limit:10")
|
||||||
like ($output, qr/ two/, "$ut: oldest limit:10: two");
|
self.assertNotIn(" one", out)
|
||||||
like ($output, qr/ three/, "$ut: oldest limit:10: three");
|
self.assertIn(" two", out)
|
||||||
like ($output, qr/ four/, "$ut: oldest limit:10: four");
|
self.assertIn(" three", out)
|
||||||
like ($output, qr/ five/, "$ut: oldest limit:10: five");
|
self.assertIn(" four", out)
|
||||||
like ($output, qr/ six/, "$ut: oldest limit:10: six");
|
self.assertIn(" five", out)
|
||||||
like ($output, qr/ seven/, "$ut: oldest limit:10: seven");
|
self.assertIn(" six", out)
|
||||||
like ($output, qr/ eight/, "$ut: oldest limit:10: eight");
|
self.assertIn(" seven", out)
|
||||||
like ($output, qr/ nine/, "$ut: oldest limit:10: nine");
|
self.assertIn(" eight", out)
|
||||||
like ($output, qr/ ten/, "$ut: oldest limit:10: ten");
|
self.assertIn(" nine", out)
|
||||||
unlike ($output, qr/ eleven/, "$ut: oldest limit:10: ! eleven");
|
self.assertIn(" ten", out)
|
||||||
|
self.assertIn(" eleven", out)
|
||||||
|
|
||||||
$output = qx{../src/task rc:$rc oldest limit:3 2>&1};
|
def test_newest_three(self):
|
||||||
ok ($? == 0, "$ut: oldest limit:3");
|
"""Test newest report + limit:3"""
|
||||||
like ($output, qr/ one/, "$ut: oldest limit:3: one");
|
code, out, err = self.t("newest limit:3")
|
||||||
like ($output, qr/ two/, "$ut: oldest limit:3: two");
|
self.assertNotIn(" one", out)
|
||||||
like ($output, qr/ three/, "$ut: oldest limit:3: three");
|
self.assertNotIn(" two", out)
|
||||||
unlike ($output, qr/ four/, "$ut: oldest limit:3: ! four");
|
self.assertNotIn(" three", out)
|
||||||
unlike ($output, qr/ five/, "$ut: oldest limit:3: ! five");
|
self.assertIn(" four", out)
|
||||||
unlike ($output, qr/ six/, "$ut: oldest limit:3: ! six");
|
self.assertIn(" five", out)
|
||||||
unlike ($output, qr/ seven/, "$ut: oldest limit:3: ! seven");
|
self.assertIn(" six", out)
|
||||||
unlike ($output, qr/ eight/, "$ut: oldest limit:3: ! eight");
|
self.assertIn(" seven", out)
|
||||||
unlike ($output, qr/ nine/, "$ut: oldest limit:3: ! nine");
|
self.assertIn(" eight", out)
|
||||||
unlike ($output, qr/ ten/, "$ut: oldest limit:3: ! ten");
|
self.assertIn(" nine", out)
|
||||||
unlike ($output, qr/ eleven/, "$ut: oldest limit:3: ! eleven");
|
self.assertIn(" ten", out)
|
||||||
|
self.assertIn(" eleven", out)
|
||||||
|
|
||||||
$output = qx{../src/task rc:$rc newest limit:10 2>&1};
|
|
||||||
ok ($? == 0, "$ut: newest limit:10");
|
|
||||||
unlike ($output, qr/ one/, "$ut: newest limit:10: ! one");
|
|
||||||
like ($output, qr/ two/, "$ut: newest limit:10: two");
|
|
||||||
like ($output, qr/ three/, "$ut: newest limit:10: three");
|
|
||||||
like ($output, qr/ four/, "$ut: newest limit:10: four");
|
|
||||||
like ($output, qr/ five/, "$ut: newest limit:10: five");
|
|
||||||
like ($output, qr/ six/, "$ut: newest limit:10: six");
|
|
||||||
like ($output, qr/ seven/, "$ut: newest limit:10: seven");
|
|
||||||
like ($output, qr/ eight/, "$ut: newest limit:10: eight");
|
|
||||||
like ($output, qr/ nine/, "$ut: newest limit:10: nine");
|
|
||||||
like ($output, qr/ ten/, "$ut: newest limit:10: ten");
|
|
||||||
like ($output, qr/ eleven/, "$ut: newest limit:10: eleven");
|
|
||||||
|
|
||||||
$output = qx{../src/task rc:$rc newest limit:3 2>&1};
|
if __name__ == "__main__":
|
||||||
ok ($? == 0, "$ut: newest limit:3");
|
from simpletap import TAPTestRunner
|
||||||
unlike ($output, qr/ one/, "$ut: newest limit:3: ! one");
|
unittest.main(testRunner=TAPTestRunner())
|
||||||
unlike ($output, qr/ two/, "$ut: newest limit:3: ! two");
|
|
||||||
unlike ($output, qr/ three/, "$ut: newest limit:3: ! three");
|
|
||||||
unlike ($output, qr/ four/, "$ut: newest limit:3: ! four");
|
|
||||||
unlike ($output, qr/ five/, "$ut: newest limit:3: ! five");
|
|
||||||
unlike ($output, qr/ six/, "$ut: newest limit:3: ! six");
|
|
||||||
unlike ($output, qr/ seven/, "$ut: newest limit:3: ! seven");
|
|
||||||
unlike ($output, qr/ eight/, "$ut: newest limit:3: ! eight");
|
|
||||||
like ($output, qr/ nine/, "$ut: newest limit:3: nine");
|
|
||||||
like ($output, qr/ ten/, "$ut: newest limit:3: ten");
|
|
||||||
like ($output, qr/ eleven/, "$ut: newest limit:3: eleven");
|
|
||||||
|
|
||||||
# Cleanup.
|
|
||||||
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
|
|
||||||
exit 0;
|
|
||||||
|
|
||||||
|
# vim: ai sts=4 et sw=4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue