[elbe-devel] [PATCH v3 3/3] tests test_doctest: Make doctests use ElbeTestCase

Torben Hohn torben.hohn at linutronix.de
Wed Jul 15 12:00:29 CEST 2020


On Fri, Jun 26, 2020 at 11:15:50AM -0400, Olivier Dion wrote:
> To test more module for doctesting, one has to add the module to the
> 'params' attribute.
> 
> If a module needs a certain context, do just like the 'filesystem'
> module does.
> 
> Signed-off-by: Olivier Dion <dion at linutronix.de>

Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>

> ---
>  elbepack/filesystem.py         |  5 ++++-
>  elbepack/tests/test_doctest.py | 25 ++++++++++++++++++++-----
>  2 files changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
> index 6c22368a..51697907 100644
> --- a/elbepack/filesystem.py
> +++ b/elbepack/filesystem.py
> @@ -502,7 +502,10 @@ class TmpdirFilesystem (Filesystem):
>          if self.debug:
>              print('leaving TmpdirFilesystem in "%s"' % self.path)
>          else:
> -            shutil.rmtree(self.path, True)
> +            self.delete()
> +
> +    def delete(self):
> +        shutil.rmtree(self.path, True)
>  
>  
>  class ImgMountFilesystem(Filesystem):
> diff --git a/elbepack/tests/test_doctest.py b/elbepack/tests/test_doctest.py
> index 9fd47d64..a19a5745 100644
> --- a/elbepack/tests/test_doctest.py
> +++ b/elbepack/tests/test_doctest.py
> @@ -9,9 +9,24 @@ import unittest
>  import elbepack.shellhelper as shellhelper
>  import elbepack.filesystem as filesystem
>  
> -def load_tests(loader, tests, ignore):
> -    tests.addTests(doctest.DocTestSuite(shellhelper))
> -    fs = filesystem.TmpdirFilesystem()
> -    tests.addTests(doctest.DocTestSuite(filesystem, extraglobs={"this":fs}))
> +from elbepack.commands.test import ElbeTestCase
>  
> -    return tests
> +class ElbeDocTest(ElbeTestCase):
> +
> +    params = [shellhelper, filesystem]
> +
> +    def setUp(self):
> +
> +        self.kwargs = {}
> +
> +        if self.params is filesystem:
> +            self.kwargs["extraglobs"] = {"this":filesystem.TmpdirFilesystem()}
> +
> +    def tearDown(self):
> +
> +        if self.params is filesystem:
> +            self.kwargs["extraglobs"]["this"].delete()
> +
> +    def test_doctest(self):
> +        fail, _ = doctest.testmod(self.params, **self.kwargs)
> +        self.assertEqual(fail, 0)
> -- 
> 2.27.0
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner


More information about the elbe-devel mailing list