mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Refactor testing framework to allow using callTask* methods inside @classmethods
This commit is contained in:
parent
be59e526f1
commit
2e64231886
1 changed files with 11 additions and 8 deletions
|
@ -83,7 +83,8 @@ class BaseTestCase(unittest.TestCase):
|
|||
"""
|
||||
pass
|
||||
|
||||
def callTask(self, args, input=None, merge_streams=True):
|
||||
@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
|
||||
|
@ -122,7 +123,8 @@ class BaseTestCase(unittest.TestCase):
|
|||
|
||||
return p.returncode, out, err
|
||||
|
||||
def callTaskSuccess(self, args, input=None, merge_streams=True):
|
||||
@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
|
||||
|
@ -134,13 +136,14 @@ class BaseTestCase(unittest.TestCase):
|
|||
|
||||
Returns (exit_code, stdout, stderr)
|
||||
"""
|
||||
out = self.callTask(args, input, merge_streams)
|
||||
out = cls.callTask(args, input, merge_streams)
|
||||
|
||||
self.assertEqual(out[0], 0, "Task finished with non-zero ({0}) exit "
|
||||
"code\nOUTPUT: {1}".format(out[0], out[1]))
|
||||
assert out[0] == 0, ("Task finished with non-zero ({0}) exit code\n"
|
||||
"OUTPUT: {1}".format(out[0], out[1]))
|
||||
return out
|
||||
|
||||
def callTaskError(self, args, input=None, merge_streams=True):
|
||||
@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
|
||||
|
@ -152,9 +155,9 @@ class BaseTestCase(unittest.TestCase):
|
|||
|
||||
Returns (exit_code, stdout, stderr)
|
||||
"""
|
||||
out = self.callTask(args, input, merge_streams)
|
||||
out = cls.callTask(args, input, merge_streams)
|
||||
|
||||
self.assertNotEqual(out[0], 0, "Task finished with zero exit (0) code")
|
||||
assert out[0] != 0, "Task finished with zero exit (0) code"
|
||||
return out
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue