Test: Converted to Python

This commit is contained in:
Paul Beckingham
2015-07-24 08:20:31 -04:00
parent 8c4188f705
commit f1b06bff93

View File

@@ -1,126 +1,97 @@
#! /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 => 24; import json
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, '>', 'seq.rc')
{
print $fh "data.location=.\n",
"confirmation=off\n",
"dateformat.annotation=m/d/Y\n";
close $fh;
}
# Test sequences in done/undo class TestSequences(TestCase):
qx{../src/task rc:seq.rc add one mississippi 2>&1}; def setUp(self):
qx{../src/task rc:seq.rc add two mississippi 2>&1}; """Executed before each test in the class"""
qx{../src/task rc:seq.rc 1,2 done 2>&1}; self.t = Task()
my $output = qx{../src/task rc:seq.rc info 1 2>&1}; self.t("add one mississippi")
like ($output, qr/Status\s+Completed/, 'sequence done 1'); self.t("add two mississippi")
$output = qx{../src/task rc:seq.rc info 2 2>&1};
like ($output, qr/Status\s+Completed/, 'sequence done 2');
qx{../src/task rc:seq.rc undo 2>&1};
qx{../src/task rc:seq.rc undo 2>&1};
$output = qx{../src/task rc:seq.rc info 1 2>&1};
like ($output, qr/Status\s+Pending/, 'sequence undo 1');
$output = qx{../src/task rc:seq.rc info 2 2>&1};
like ($output, qr/Status\s+Pending/, 'sequence undo 2');
# Test sequences in delete/undelete def test_sequence_done(self):
qx{../src/task rc:seq.rc 1,2 delete 2>&1}; """Test sequences in done"""
$output = qx{../src/task rc:seq.rc info 1 2>&1}; self.t("1,2 done")
like ($output, qr/Status\s+Deleted/, 'sequence delete 1'); code, out, err = self.t("_get 1.status 2.status")
$output = qx{../src/task rc:seq.rc info 2 2>&1}; self.assertEqual("completed completed\n", out)
like ($output, qr/Status\s+Deleted/, 'sequence delete 2');
qx{../src/task rc:seq.rc undo 2>&1};
qx{../src/task rc:seq.rc undo 2>&1};
$output = qx{../src/task rc:seq.rc info 1 2>&1};
like ($output, qr/Status\s+Pending/, 'sequence undo 1');
$output = qx{../src/task rc:seq.rc info 2 2>&1};
like ($output, qr/Status\s+Pending/, 'sequence undo 2');
# Test sequences in start/stop def test_sequence_delete(self):
qx{../src/task rc:seq.rc 1,2 start 2>&1}; """Test sequences in delete"""
$output = qx{../src/task rc:seq.rc info 1 2>&1}; self.t("1,2 delete")
like ($output, qr/Start/, 'sequence start 1'); code, out, err = self.t("_get 1.status 2.status")
$output = qx{../src/task rc:seq.rc info 2 2>&1}; self.assertEqual("deleted deleted\n", out)
like ($output, qr/Start/, 'sequence start 2');
qx{../src/task rc:seq.rc 1,2 stop 2>&1};
$output = qx{../src/task rc:seq.rc info 1 2>&1};
like ($output, qr/Start\sdeleted/, 'sequence stop 1');
$output = qx{../src/task rc:seq.rc info 2 2>&1};
like ($output, qr/Start\sdeleted/, 'sequence stop 2');
# Test sequences in modify def test_sequence_start_stop(self):
qx{../src/task rc:seq.rc 1,2 modify +tag 2>&1}; """Test sequences in start/stop"""
$output = qx{../src/task rc:seq.rc info 1 2>&1}; self.t("1,2 start")
like ($output, qr/Tags\s+tag/, 'sequence modify 1'); code, out, err = self.t("_get 1.start 2.start")
$output = qx{../src/task rc:seq.rc info 2 2>&1}; self.assertRegexpMatches(out, "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\n")
like ($output, qr/Tags\s+tag/, 'sequence modify 2');
qx{../src/task rc:seq.rc 1,2 modify -tag 2>&1};
$output = qx{../src/task rc:seq.rc info 1 2>&1};
unlike ($output, qr/Tags\s+tag/, 'sequence unmodify 1');
$output = qx{../src/task rc:seq.rc info 2 2>&1};
unlike ($output, qr/Tags\s+tag/, 'sequence unmodify 2');
# Test sequences in substitutions self.t("1,2 stop")
qx{../src/task rc:seq.rc 1,2 modify /miss/Miss/ 2>&1}; code, out, err = self.t("_get 1.start 2.start")
$output = qx{../src/task rc:seq.rc info 1 2>&1}; self.assertEqual("\n", out)
like ($output, qr/Description\s+one Miss/, 'sequence substitution 1');
$output = qx{../src/task rc:seq.rc info 2 2>&1};
like ($output, qr/Description\s+two Miss/, 'sequence substitution 2');
# Test sequences in info def test_sequence_modify(self):
$output = qx{../src/task rc:seq.rc info 1,2 2>&1}; """Test sequences in modify"""
like ($output, qr/Description\s+one Miss/, 'sequence info 1'); self.t("1,2 modify +xyz")
like ($output, qr/Description\s+two Miss/, 'sequence info 2'); code, out, err = self.t("_get 1.tags 2.tags")
self.assertEqual("xyz xyz\n", out)
# Test sequences in duplicate def test_sequence_info(self):
qx{../src/task rc:seq.rc 1,2 duplicate pri:H 2>&1}; """Test sequences in info"""
$output = qx{../src/task rc:seq.rc info 3 2>&1}; self.t("1,2 info")
like ($output, qr/Priority\s+H/, 'sequence duplicate 1'); code, out, err = self.t("_get 1.description 2.description")
$output = qx{../src/task rc:seq.rc info 4 2>&1}; self.assertEqual(out.count("miss"), 2)
like ($output, qr/Priority\s+H/, 'sequence duplicate 2');
# Test sequences in annotate def test_sequence_duplicate(self):
qx{../src/task rc:seq.rc 1,2 annotate note 2>&1}; """Test sequences in duplicate"""
$output = qx{../src/task rc:seq.rc info 1 2>&1}; self.t("1,2 duplicate priority:H")
like ($output, qr/\d+\/\d+\/\d+ note/, 'sequence 1 annotate'); code, out, err = self.t("_get 3.priority 4.priority")
$output = qx{../src/task rc:seq.rc info 2 2>&1}; self.assertEqual("H H\n", out)
like ($output, qr/\d+\/\d+\/\d+ note/, 'sequence 2 annotate');
# Cleanup. def test_sequence_annotate(self):
unlink qw(pending.data completed.data undo.data backlog.data seq.rc); """Test sequences in annotate"""
exit 0; self.t("1,2 annotate note")
code, out, err = self.t("_get 1.annotations.1.description 2.annotations.1.description")
self.assertEqual("note note\n", out)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4