From 42cfda704f74f544f746e3534e64250be7e4757d Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sun, 13 Jul 2014 20:09:18 +0100 Subject: [PATCH] Unittest - Replacing old basetest framework * Adapt bugs to work with the newer testing framework --- test/basetest/__init__.py | 169 +------------------------------------- test/bug.1254.t | 85 ++++++++----------- test/bug.1267.t | 97 +++++++++------------- test/bug.360.t | 113 +++++++++++-------------- test/template.t | 52 ++++++++---- test/tw-1300.t | 77 ++++++++--------- test/tw-1306.t | 69 ++++++++-------- test/tw-285.t | 101 ++++++++++------------- test/version.t | 76 ++++++++--------- 9 files changed, 301 insertions(+), 538 deletions(-) diff --git a/test/basetest/__init__.py b/test/basetest/__init__.py index d4d0ee03c..612335ca9 100644 --- a/test/basetest/__init__.py +++ b/test/basetest/__init__.py @@ -1,171 +1,6 @@ # -*- coding: utf-8 -*- -import os -import tempfile -import shutil -import unittest -from subprocess import Popen, PIPE, STDOUT - - -class BaseTestCase(unittest.TestCase): - @classmethod - def setUpClass(cls): - """Executed once before any test in the class""" - cls._original_pwd = os.getcwd() - cls._new_pwd = tempfile.mkdtemp() - - # Chdir into the temporary folder - os.chdir(cls._new_pwd) - - # Change environment Prepare Env - cls.prepareEnv() - - # Make task available locally - cls.prepareExecutable() - - # Prepare the environment - cls.prepare() - - @classmethod - def prepareEnv(cls): - """Ensure that any ENV variable used by task and setup in the - environment doesn't affect the test - """ - try: - del os.environ["TASKDATA"] - except KeyError: - pass - - try: - del os.environ["TASKRC"] - except KeyError: - pass - - @classmethod - def prepareExecutable(cls): - """Link the binary to be tested in the temporary folder""" - src = os.path.join(cls._original_pwd, "..", "src", "task") - os.symlink(src, "task") - - @classmethod - def prepare(cls): - """Additional setup, executed only once before any test - - The current (temporary) work dir is available as cls._new_pwd - and the original work dir as cls._original_pwd - """ - pass - - @classmethod - def tearDownClass(cls): - """Executed once after all tests in the class""" - # Finishing steps before removal of temp dir - cls.finish() - - # Finally remove whatever's left of the temporary folder - os.chdir(cls._original_pwd) - shutil.rmtree(cls._new_pwd) - - @classmethod - def finish(cls): - """Finishing steps, executed once after all tests are executed and - before removal of the temporary directory - - The current (temporary) work dir is available as cls._new_pwd - and the original work dir as cls._original_pwd - - Any files not removed here or via self.addCleanup() will be deleted - once this function completes, as part of the removal of the temporary - directory. Still it is good practice to explicitly clean your leftovers - - NOTE: If setUpClass or any of prepare* methods fails, finish() will - not get called. - """ - pass - - @classmethod - def callTask(cls, args, input=None, merge_streams=True): - """Invoke src/task with the given arguments - - Use callTaskSuccess or callTaskError if you want exit_code to be tested - automatically and fail if result is unexpected. - - If you wish to pass instructions to task you can do so by providing a - string via input. Such as input="add Hello task\n1 delete". - - If merge_streams=True stdout and stderr will be merged into stdout. - - Returns (exit_code, stdout, stderr) - """ - if merge_streams: - stderr = STDOUT - else: - stderr = PIPE - - if input is not None: - stdin = PIPE - else: - stdin = None - - command = ["./task"] - command.extend(args) - - p = Popen(command, stdin=stdin, stdout=PIPE, stderr=stderr) - out, err = p.communicate(input) - # In python3 we will be able use the following instead of the previous - # line to avoid locking if task is unexpectedly waiting for input - #try: - # out, err = p.communicate(input, timeout=15) - #except TimeoutExpired: - # p.kill() - # out, err = proc.communicate() - - return p.returncode, out, err - - @classmethod - def callTaskSuccess(cls, args, input=None, merge_streams=True): - """Invoke src/task with the given arguments and expect a zero exit - code. - Causes test to fail if exit_code != 0 - - If you wish to pass instructions to task you can do so by providing a - string via input. Such as input="add Hello task\n1 delete". - - If merge_streams=True stdout and stderr will be merged into stdout. - - Returns (exit_code, stdout, stderr) - """ - out = cls.callTask(args, input, merge_streams) - - assert out[0] == 0, ("Task finished with non-zero ({0}) exit code\n" - "OUTPUT: {1}".format(out[0], out[1])) - return out - - @classmethod - def callTaskError(cls, args, input=None, merge_streams=True): - """Invoke src/task with the given arguments and expect a non-zero exit - code. - Causes test to fail if exit_code == 0 - - If you wish to pass instructions to task you can do so by providing a - string via input. Such as input="add Hello task\n1 delete". - - If merge_streams=True stdout and stderr will be merged into stdout. - - Returns (exit_code, stdout, stderr) - """ - out = cls.callTask(args, input, merge_streams) - - assert out[0] != 0, "Task finished with zero exit (0) code" - return out - - @classmethod - def diag(cls, out): - """Diagnostics are just lines preceded with #. - """ - print '# --- diag start ---' - for line in out.split("\n"): - print '#', line - print '# --- diag end ---' +from .task import Task +from .taskd import Taskd # vim: ai sts=4 et sw=4 diff --git a/test/bug.1254.t b/test/bug.1254.t index 63dceadc8..4ece13ff6 100755 --- a/test/bug.1254.t +++ b/test/bug.1254.t @@ -1,78 +1,60 @@ #!/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 -## -################################################################################ +############################################################################### +# +# 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 +# +############################################################################### import sys import os import signal -from glob import glob +import unittest # Ensure python finds the local simpletap and basetest modules sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from basetest import BaseTestCase +from basetest import Task -class BaseTestBug1254(BaseTestCase): - @classmethod - def prepare(cls): - with open("bug.rc", 'w') as fh: - fh.write("data.location=.\n" - "confirmation=no\n") +class TestBug1254(unittest.TestCase): + def setUp(self): + self.t = Task() - def tearDown(self): - """Needed after each test or setUp will cause duplicated data at start - of the next test. - """ - for file in glob("*.data"): - os.remove(file) - - @classmethod - def finish(cls): - os.remove("bug.rc") - - -class TestBug1254(BaseTestBug1254): def test_no_segmentation_fault_calc_negative_multiplication(self): """calc can multiply zero and negative numbers """ - args = ["rc:bug.rc", "calc", "0*-1"] - + args = ("calc", "0*-1") self.run_command(args) def test_calc_positive_multiplication(self): """calc can multiply negative zero and positive """ - args = ["rc:bug.rc", "calc", "0*1"] - + args = ("calc", "0*1") self.run_command(args) def run_command(self, args): - code, out, err = self.callTask(args) + code, out, err = self.t(args) # We shouldn't get a segmentation fault # (negative exit code == 128 - real_exit_code) @@ -87,7 +69,6 @@ class TestBug1254(BaseTestBug1254): if __name__ == "__main__": from simpletap import TAPTestRunner - import unittest unittest.main(testRunner=TAPTestRunner()) # vim: ai sts=4 et sw=4 diff --git a/test/bug.1267.t b/test/bug.1267.t index 188bab4f8..b582337fc 100755 --- a/test/bug.1267.t +++ b/test/bug.1267.t @@ -1,72 +1,55 @@ #!/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 -## -################################################################################ +############################################################################### +# +# 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 +# +############################################################################### import sys import os -import re -from glob import glob +import unittest # Ensure python finds the local simpletap and basetest modules sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from basetest import BaseTestCase +from basetest import Task -class BaseTestBug1267(BaseTestCase): - @classmethod - def prepare(cls): - with open("bug.rc", 'w') as fh: - fh.write("data.location=.\n" - "confirmation=no\n") +class TestBug1267(unittest.TestCase): + def setUp(self): + self.t = Task() - def tearDown(self): - """Needed after each test or setUp will cause duplicated data at start - of the next test. - """ - for file in glob("*.data"): - os.remove(file) - - @classmethod - def cleanup(cls): - os.remove("bug.rc") - - -class TestBug1267(BaseTestBug1267): def test_add_task_no_project_with_default(self): """Add a task without a project using direct rc change """ project = "MakePudding" - args = ["rc:bug.rc", "rc.default.project={0}".format(project), "add", + args = ["rc.default.project={0}".format(project), "add", "proj:", "Add cream"] - self.callTaskSuccess(args) + self.t(args) - args = ["rc:bug.rc", "ls"] - code, out, err = self.callTaskSuccess(args, merge_streams=False) + args = ("ls",) + code, out, err = self.t(args, merge_streams=False) self.assertNotIn(project, out) @@ -75,21 +58,19 @@ class TestBug1267(BaseTestBug1267): """ project = "MakePudding" - with open("bug.rc", 'a') as fh: - fh.write("default.project={0}\n".format(project)) + self.t.config("default.project", project) - args = ["rc:bug.rc", "add", "proj:", "Add cream"] - self.callTaskSuccess(args) + args = ("add", "proj:", "Add cream") + self.t(args) - args = ["rc:bug.rc", "ls"] - code, out, err = self.callTaskSuccess(args, merge_streams=False) + args = ("ls",) + code, out, err = self.t(args, merge_streams=False) self.assertNotIn(project, out) if __name__ == "__main__": from simpletap import TAPTestRunner - import unittest unittest.main(testRunner=TAPTestRunner()) # vim: ai sts=4 et sw=4 diff --git a/test/bug.360.t b/test/bug.360.t index 293043b15..cc9185241 100755 --- a/test/bug.360.t +++ b/test/bug.360.t @@ -1,66 +1,50 @@ #!/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 -## -################################################################################ +############################################################################### +# +# 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 +# +############################################################################### import sys import os import re -from glob import glob +import unittest # Ensure python finds the local simpletap and basetest modules sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from basetest import BaseTestCase +from basetest import Task -class BaseTestBug360(BaseTestCase): - @classmethod - def prepare(cls): - with open("bug.rc", 'w') as fh: - fh.write("data.location=.\n" - "confirmation=no\n") - +class BaseTestBug360(unittest.TestCase): def setUp(self): """Executed before each test in the class""" - args = ["rc:bug.rc", "add", "foo", "due:tomorrow", "recur:daily"] - self.callTaskSuccess(args) + self.t = Task() + args = ("add", "foo", "due:tomorrow", "recur:daily") + self.t(args) # TODO: Add explanation why this line is necessary - args = ["rc:bug.rc", "ls"] - self.callTaskSuccess(args) - - def tearDown(self): - """Needed after each test or setUp will cause duplicated data at start - of the next test. - """ - for file in glob("*.data"): - os.remove(file) - - @classmethod - def finish(cls): - os.remove("bug.rc") + args = ("ls",) + self.t(args) class TestBug360RemovalError(BaseTestBug360): @@ -68,9 +52,9 @@ class TestBug360RemovalError(BaseTestBug360): """Modifying a recursive task by adding project: also modifies parent """ commands = "y\n" - args = ["rc:bug.rc", "1", "modify", "project:bar"] + args = ("1", "modify", "project:bar") - code, out, err = self.callTaskSuccess(args, commands) + code, out, err = self.t(args, commands) expected = "Modified 2 tasks." self.assertIn(expected, out) @@ -82,9 +66,9 @@ class TestBug360RemovalError(BaseTestBug360): """ # TODO Removing recur: from a recurring task should also remove imask # and parent. - args = ["rc:bug.rc", "2", "modify", "recur:"] + args = ("2", "modify", "recur:") - code, out, err = self.callTaskError(args) + code, out, err = self.t.runError(args) # Expected non zero exit-code self.assertEqual(code, 2) @@ -96,9 +80,9 @@ class TestBug360RemovalError(BaseTestBug360): """ # TODO Removing due: from a recurring task should also remove recur, # imask and parent - args = ["rc:bug.rc", "2", "modify", "due:"] + args = ("2", "modify", "due:") - code, out, err = self.callTaskError(args) + code, out, err = self.t.runError(args) # Expected non zero exit-code self.assertEqual(code, 2) @@ -112,14 +96,14 @@ class TestBug360AllowedChanges(BaseTestBug360): # Also do setUp from BaseTestBug360 super(TestBug360AllowedChanges, self).setUp() - self.callTaskSuccess(["rc:bug.rc", "add", "nonrecurring", "due:today"]) + self.t(("add", "nonrecurring", "due:today")) def test_allow_modify_due_in_nonrecurring(self): """Allow modifying due date in non recurring task """ # Retrieve the id of the non recurring task - args = ["rc:bug.rc", "ls"] - code, out, err = self.callTaskSuccess(args) + args = ("ls",) + code, out, err = self.t(args) expected = "2 tasks" self.assertIn(expected, out) @@ -127,26 +111,23 @@ class TestBug360AllowedChanges(BaseTestBug360): # NOTE: raw python string r"" avoids having to escape backslashes id = re.search(r"(\d+)\s.+\snonrecurring", out).group(1) - args = ["rc:bug.rc", id, "modify", "due:"] - code, out, err = self.callTaskSuccess(args) + args = (id, "modify", "due:") + code, out, err = self.t(args) expected = "Modified 1 task." self.assertIn(expected, out) expected = "You cannot remove the due date from a recurring task." self.assertNotIn(expected, out) - # TODO: I'm not really sure what this is supposed to test for and if it - # should be here at all. On another note turning it into an independent - # test requires too much duplication of code - args = ["rc:bug.rc", "diag"] - code, out, err = self.callTaskSuccess(args) + # Make sure no duplicate tasks were created + args = ("diag",) + code, out, err = self.t(args) expected = "No duplicates found" self.assertIn(expected, out) if __name__ == "__main__": from simpletap import TAPTestRunner - import unittest unittest.main(testRunner=TAPTestRunner()) # vim: ai sts=4 et sw=4 diff --git a/test/template.t b/test/template.t index 5f2d0392f..e462559ab 100755 --- a/test/template.t +++ b/test/template.t @@ -3,41 +3,43 @@ import sys import os +import unittest +from datetime import datetime # 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 +from basetest import Task, Taskd class TestCase(unittest.TestCase): @classmethod def setUpClass(cls): """Executed once before any test in the class""" - # Empty rc file - open("version.rc", 'w').close() + # Used to initialize objects that can be shared across tests + # Also useful if none of the tests of the current TestCase performs + # data alterations. See tw-285.t for an example def setUp(self): """Executed before each test in the class""" + # Used to initialize objects that should be re-initialized or + # re-created for each individual test + self.t = Task() - def testVersion(self): + def test_version(self): """Copyright is current""" - command = ["../src/task", "rc:version.rc", "version"] + command = ("version",) - # Merge STDOUT and STDERR - p = Popen(command, stdout=PIPE, stderr=STDOUT) - out, err = p.communicate() + code, out, err = self.t(command) expected = "Copyright \(C\) \d{4} - %d" % (datetime.now().year,) self.assertRegexpMatches(out.decode("utf8"), expected) - def testFailOther(self): + def test_fail_other(self): """Nothing to do with Copyright""" -# self.assertEqual("I like to code", "I like\nto code\n") + self.assertEqual("I like to code", "I like\nto code\n") -# @unittest.skipIf(1 != 0, "This machine has sane logic") - def testSkipped(self): + @unittest.skipIf(1 != 0, "This machine has sane logic") + def test_skipped(self): """Test all logic of the world""" def tearDown(self): @@ -46,10 +48,30 @@ class TestCase(unittest.TestCase): @classmethod def tearDownClass(cls): """Executed once after all tests in the class""" - os.remove("version.rc") + + +class ServerTestCase(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.taskd = Taskd() + # This takes a while... + cls.taskd.start() + + def setUp(self): + """Executed before each test in the class""" + self.t = Task(taskd=self.taskd) + # Or if Task() is already available + # self.t.bind_taskd_server(self.taskd) + + def test_server_sync(self): + """Testing if client and server can speak to each other""" + self.t(("add", "Something to sync")) + self.t(("sync",)) if __name__ == "__main__": + # NOTE Uncomment the next line to actually execute the tests + # In this template tests are not valid and are meant to serve as example from simpletap import TAPTestRunner unittest.main(testRunner=TAPTestRunner()) diff --git a/test/tw-1300.t b/test/tw-1300.t index aed8b8285..100645d7c 100755 --- a/test/tw-1300.t +++ b/test/tw-1300.t @@ -1,71 +1,58 @@ #!/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 -## -################################################################################ +############################################################################### +# +# 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 +# +############################################################################### import sys import os -import signal -from glob import glob +import unittest # Ensure python finds the local simpletap and basetest modules sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from basetest import BaseTestCase +from basetest import Task -class BaseTestBug1300(BaseTestCase): +class TestBug1300(unittest.TestCase): @classmethod - def prepare(cls): - with open("bug.rc", 'w') as fh: - fh.write("data.location=.\n" - "confirmation=no\n") + def setUp(cls): + cls.t = Task() - @classmethod - def finish(cls): - for file in glob("*.data"): - os.remove(file) - - os.remove("bug.rc") - - -class TestBug1300(BaseTestBug1300): def test_dom_exit_status_good(self): """If the DOM recognizes a reference, it should return '0' """ - self.callTaskSuccess(["rc:bug.rc", "_get", "context.program"]) + self.t(("_get", "context.program")) def test_dom_exit_status_bad(self): """If the DOM does not recognize a reference, it should return '1' """ - self.callTaskError(["rc:bug.rc", "_get", "XYZ"]) + self.t.runError(("_get", "XYZ")) if __name__ == "__main__": from simpletap import TAPTestRunner - import unittest unittest.main(testRunner=TAPTestRunner()) # vim: ai sts=4 et sw=4 diff --git a/test/tw-1306.t b/test/tw-1306.t index 2b3469351..4574a1925 100755 --- a/test/tw-1306.t +++ b/test/tw-1306.t @@ -1,54 +1,51 @@ #!/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 -## -################################################################################ +############################################################################### +# +# 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 +# +############################################################################### import sys import os +import unittest sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from basetest import BaseTestCase +from basetest import Task -class BaseTestBug1306(BaseTestCase): - @classmethod - def prepare(cls): - with open("1306.rc", 'w') as fh: - fh.write("data.location=.\n" - "confirmation=no\n") -class TestBug1306(BaseTestBug1306): +class TestBug1306(unittest.TestCase): + def setUp(self): + self.t = Task() + def test_mod_before_add(self): """FILTER before 'add' command upgraded to MODIFICATION""" - self.callTaskSuccess(["rc:1306.rc", "project:PROJ", "add", "foo"]) - code, out, err = self.callTaskSuccess(["rc:1306.rc", "1", "info"]) + self.t(("project:PROJ", "add", "foo")) + code, out, err = self.t(("1", "info")) self.assertIn("PROJ", out) if __name__ == "__main__": from simpletap import TAPTestRunner - import unittest unittest.main(testRunner=TAPTestRunner()) # vim: ai sts=4 et sw=4 diff --git a/test/tw-285.t b/test/tw-285.t index 79fa86818..67ddc9251 100755 --- a/test/tw-285.t +++ b/test/tw-285.t @@ -1,48 +1,45 @@ #!/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 -## -################################################################################ +############################################################################### +# +# 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 +# +############################################################################### import sys import os -import signal -from glob import glob +import unittest # Ensure python finds the local simpletap and basetest modules sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from basetest import BaseTestCase +from basetest import Task -class BaseTest285(BaseTestCase): +class Test285(unittest.TestCase): @classmethod - def prepare(cls): - with open("bug.rc", 'w') as fh: - fh.write("data.location=.\n" - "verbose=nothing\n" - "confirmation=no\n") + def setUpClass(cls): + cls.t = Task() + cls.t.config("verbose", "nothing") # OVERDUE YESTERDAY DUE TODAY TOMORROW WEEK MONTH YEAR # due:-1week Y - - - - ? ? ? @@ -53,57 +50,47 @@ class BaseTest285(BaseTestCase): # due:1month - - - - - - - ? # due:1year - - - - - - - - - cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_last_week', 'due:-1week']) - cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_yesterday', 'due:-1day']) - cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_earlier_today', 'due:today']) - cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_later_today', 'due:tomorrow']) - cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_three_days', 'due:3days']) - cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_next_month', 'due:1month']) - cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_next_year', 'due:1year']) + cls.t(('add', 'due_last_week', 'due:-1week')) + cls.t(('add', 'due_yesterday', 'due:-1day')) + cls.t(('add', 'due_earlier_today', 'due:today')) + cls.t(('add', 'due_later_today', 'due:tomorrow')) + cls.t(('add', 'due_three_days', 'due:3days')) + cls.t(('add', 'due_next_month', 'due:1month')) + cls.t(('add', 'due_next_year', 'due:1year')) - @classmethod - def finish(cls): - for file in glob("*.data"): - os.remove(file) - - os.remove("bug.rc") - - -class Test285(BaseTest285): def test_overdue(self): """+OVERDUE""" - code, out, err = self.callTaskSuccess(["rc:bug.rc", "+OVERDUE", "count"]) + code, out, err = self.t(("+OVERDUE", "count")) self.assertEqual(out, "3\n", "+OVERDUE == 3 tasks") def test_yesterday(self): """+YESTERDAY""" - code, out, err = self.callTaskSuccess(["rc:bug.rc", "+YESTERDAY", "count"]) + code, out, err = self.t(("+YESTERDAY", "count")) self.assertEqual(out, "1\n", "+YESTERDAY == 1 task") def test_due(self): """+DUE""" - code, out, err = self.callTaskSuccess(["rc:bug.rc", "+DUE", "count"]) + code, out, err = self.t(("+DUE", "count")) self.assertEqual(out, "3\n", "+DUE == 3 task") def test_today(self): """+TODAY""" - code, out, err = self.callTaskSuccess(["rc:bug.rc", "+TODAY", "count"]) + code, out, err = self.t(("+TODAY", "count")) self.assertEqual(out, "1\n", "+TODAY == 1 task") def test_duetoday(self): """+DUETODAY""" - code, out, err = self.callTaskSuccess(["rc:bug.rc", "+DUETODAY", "count"]) + code, out, err = self.t(("+DUETODAY", "count")) self.assertEqual(out, "1\n", "+DUETODAY == 1 task") def test_tomorrow(self): """+TOMORROW""" - code, out, err = self.callTaskSuccess(["rc:bug.rc", "+TOMORROW", "count"]) + code, out, err = self.t(("+TOMORROW", "count")) self.assertEqual(out, "1\n", "+TOMORROW == 1 task") if __name__ == "__main__": from simpletap import TAPTestRunner - import unittest unittest.main(testRunner=TAPTestRunner()) # vim: ai sts=4 et sw=4 diff --git a/test/version.t b/test/version.t index df4ce2386..e392e9eb9 100755 --- a/test/version.t +++ b/test/version.t @@ -1,65 +1,57 @@ #! /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 -## -################################################################################ +############################################################################### +# +# 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 +# +############################################################################### import sys import os +import unittest +from datetime import datetime # Ensure python finds the local simpletap module sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from basetest import BaseTestCase - -from subprocess import Popen, PIPE, STDOUT -from datetime import datetime +from basetest import Task -class TestVersion(BaseTestCase): - @classmethod - def prepare(cls): - # Empty rc file - open("version.rc", 'w').close() +class TestVersion(unittest.TestCase): + def setUp(self): + self.t = Task() - def testVersion(self): + def test_version(self): """Copyright is current""" - args = ["rc:version.rc", "version"] + args = ("version",) - code, out, err = self.callTaskSuccess(args) + code, out, err = self.t(args) expected = "Copyright \(C\) \d{4} - %d" % (datetime.now().year,) self.assertRegexpMatches(out.decode("utf8"), expected) - @classmethod - def finish(cls): - os.remove("version.rc") - if __name__ == "__main__": from simpletap import TAPTestRunner - import unittest unittest.main(testRunner=TAPTestRunner()) # vim: ai sts=4 et sw=4