[elbe-devel] [PATCH] test: make ElbeTestCase.params implementation clearer
Olivier Dion
dion at linutronix.de
Wed Jul 22 17:59:02 CEST 2020
On Wed, 22 Jul 2020, Torben Hohn <torben.hohn at linutronix.de> wrote:
> that self.params is a single parameter is confusing.
>
> Add ElbeTestCase.__init__() that saves the methodname parameter.
> Then implement parameterize() that constructs another instance,
> with self.param setup to the parameter.
>
> Then make ElbeTestSuite() use that.
>
> Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
> ---
> elbepack/commands/test.py | 16 +++++++++++-----
> elbepack/tests/test_doctest.py | 6 +++---
> 2 files changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/elbepack/commands/test.py b/elbepack/commands/test.py
> index 31f1ae2dd..161008576 100644
> --- a/elbepack/commands/test.py
> +++ b/elbepack/commands/test.py
> @@ -25,12 +25,20 @@ class ElbeTestCase(unittest.TestCase):
>
> level = ElbeTestLevel.BASE
>
> + def __init__(self, methodName='runTest', param=None):
> + self.methodName = methodName
> + self.param = param
> + super().__init__(methodName)
> +
> def __str__(self):
> name = super(ElbeTestCase, self).__str__()
> - if hasattr(self, "params"):
> - return "%s : params=%s" % (name, getattr(self, "params"))
> + if self.param:
> + return "%s : param=%s" % (name, self.param)
> return name
>
> + def parameterize(self, param):
> + return self.__class__(methodName=self.methodName, param=param)
> +
> # TODO:py3 - Remove useless object inheritance
> # pylint: disable=useless-object-inheritance
> class ElbeTestSuite(object):
> @@ -50,9 +58,7 @@ class ElbeTestSuite(object):
> continue
>
> for param in test.params:
> - clone = copy.deepcopy(test)
> - clone.params = param
> - self.tests.append(clone)
> + self.tests.append(test.parameterize(param))
Remove 'import copy'. With this:
Reviewed-by: Olivier Dion <dion at linutronix.de>
--
Olivier Dion
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
More information about the elbe-devel
mailing list