diff options
author | Diana Picus <diana.picus@linaro.org> | 2018-01-24 14:40:46 +0100 |
---|---|---|
committer | Diana Picus <diana.picus@linaro.org> | 2018-01-31 14:45:29 +0000 |
commit | 9276b78dd111f2ee91eca495d52c4a5c4f6893cb (patch) | |
tree | 333bcf2a045708a139e65d97fbd6f7cf4d832d2c /tests/cli/llvmtestcase.py | |
parent | efebf31c9c52e55ac595111b0d755c93ab33adfe (diff) |
Remove some duplication from the tests
Get rid of some of the duplication from the command line interface tests
by extracting a decorator that checks that the proper exception is
thrown when we run a command without one of its required arguments.
Change-Id: Ifd2b93b7ff1bb249c002f1b03c0a242feb1f39f9
Diffstat (limited to 'tests/cli/llvmtestcase.py')
-rw-r--r-- | tests/cli/llvmtestcase.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/cli/llvmtestcase.py b/tests/cli/llvmtestcase.py index 0f29ce6..f895c49 100644 --- a/tests/cli/llvmtestcase.py +++ b/tests/cli/llvmtestcase.py @@ -32,6 +32,30 @@ def debug(test): return wrapper +def require_command_arg(requiredArg): + """ + Decorator that simplifies writing CLI tests that check that 'requiredArg' is + in fact required (i.e. that the command that we're testing will blow up if + we don't pass it the required argument). + + Use this to decorate test functions, e.g: + + @require_command_arg("--my-required-arg") + def test_my_required_arg_is_compulsory(self): + run_command_without_my_required_arg() + """ + def decorate(test): + def wrapper(*args, **kwargs): + self = args[0] + with self.assertRaises(subprocess.CalledProcessError) as context: + test(*args, **kwargs) + + self.assertRegex(str(context.exception.output), + "(.*\n)*the following arguments are required: {}(.*\n)*".format(requiredArg)) + return wrapper + return decorate + + class LLVMTestCase(unittest.TestCase): python = "python3" script = os.path.join("scripts", "llvm.py") |