[elbe-devel] [PATCH 4/6] elbepack: test_xml: migrate to subtests
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Tue Mar 5 16:36:11 CET 2024
The custom test-parameterization is not compatible with pytest.
As pytest is more featureful than our own test runner prepare for
switching over.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/tests/test_xml.py | 107 ++++++++++++++++++++++-----------------------
1 file changed, 53 insertions(+), 54 deletions(-)
diff --git a/elbepack/tests/test_xml.py b/elbepack/tests/test_xml.py
index 1cc6dc6050cc..65f83d843110 100644
--- a/elbepack/tests/test_xml.py
+++ b/elbepack/tests/test_xml.py
@@ -14,72 +14,71 @@ from elbepack.directories import elbe_dir, elbe_exe
@unittest.skipIf(ElbeTestCase.level < ElbeTestLevel.INITVM,
'Test level not set to INITVM')
class TestSimpleXML(ElbeTestCase):
- params = [os.path.join(elbe_dir, 'tests', fname)
- for fname
- in os.listdir(os.path.join(elbe_dir, 'tests'))
- if fname.startswith('simple') and fname.endswith('.xml')]
def test_simple_build(self):
+ for param in [os.path.join(elbe_dir, 'tests', fname)
+ for fname
+ in os.listdir(os.path.join(elbe_dir, 'tests'))
+ if fname.startswith('simple') and fname.endswith('.xml')]:
- with tempfile.TemporaryDirectory(prefix='elbe-test-simple-xml-') as build_dir:
+ with tempfile.TemporaryDirectory(prefix='elbe-test-simple-xml-') as build_dir:
- prj = os.path.join(build_dir, 'uuid.prj')
- uuid = None
+ prj = os.path.join(build_dir, 'uuid.prj')
+ uuid = None
- try:
- system(
- f'{sys.executable} {elbe_exe} initvm submit "{self.param}" '
- f'--output "{build_dir}" --keep-files '
- f'--build-sdk --writeproject "{prj}"')
+ try:
+ system(
+ f'{sys.executable} {elbe_exe} initvm submit "{param}" '
+ f'--output "{build_dir}" --keep-files '
+ f'--build-sdk --writeproject "{prj}"')
- # Ensure project build is done
- with open(prj, 'r') as f:
- uuid = f.read()
- system(f'{sys.executable} {elbe_exe} control list_projects | '
- f'grep {uuid} | grep build_done || false')
+ # Ensure project build is done
+ with open(prj, 'r') as f:
+ uuid = f.read()
+ system(f'{sys.executable} {elbe_exe} control list_projects | '
+ f'grep {uuid} | grep build_done || false')
- for cmd in ('cdrom', 'img', 'sdk', 'rebuild'):
- with self.subTest(f'check build {cmd}'):
- system(f'{sys.executable} {elbe_exe} check-build {cmd} "{build_dir}"')
+ for cmd in ('cdrom', 'img', 'sdk', 'rebuild'):
+ with self.subTest(f'check build {cmd}'):
+ system(f'{sys.executable} {elbe_exe} check-build {cmd} "{build_dir}"')
- except Exception as e:
- raise e
- else:
- # This is a tear down of the project, it's okay if it fails
- system(
- f'{sys.executable} {elbe_exe} control del_project {uuid}', allow_fail=True)
+ except Exception as e:
+ raise e
+ else:
+ # This is a tear down of the project, it's okay if it fails
+ system(
+ f'{sys.executable} {elbe_exe} control del_project {uuid}', allow_fail=True)
@unittest.skipIf(ElbeTestCase.level < ElbeTestLevel.INITVM,
'Test level not set to INITVM')
class TestPbuilder(ElbeTestCase):
- params = [os.path.join(elbe_dir, 'tests', fname)
- for fname
- in os.listdir(os.path.join(elbe_dir, 'tests'))
- if fname.startswith('pbuilder') and fname.endswith('.xml')]
-
def test_pbuilder_build(self):
-
- with tempfile.TemporaryDirectory(prefix='elbe-test-pbuilder-xml-') as build_dir:
-
- prj = os.path.join(build_dir, 'uuid.prj')
- uuid = None
-
- try:
- system(f'{sys.executable} {elbe_exe} pbuilder create --xmlfile "{self.param}" \
- --writeproject "{prj}"')
- with open(prj, 'r') as f:
- uuid = f.read()
-
- for package in ['libgpio', 'gpiotest']:
- system(f'cd "{build_dir}"; \
- git clone https://github.com/Linutronix/{package}.git')
- system(f'cd "{build_dir}/{package}"; \
- {sys.executable} {elbe_exe} pbuilder build --project {uuid}')
- except Exception as e:
- raise e
- else:
- # This is a tearDown of the project, it's okay if it fails
- system(
- f'{sys.executable} {elbe_exe} control del_project {uuid}', allow_fail=True)
+ for param in [os.path.join(elbe_dir, 'tests', fname)
+ for fname
+ in os.listdir(os.path.join(elbe_dir, 'tests'))
+ if fname.startswith('pbuilder') and fname.endswith('.xml')]:
+
+ with tempfile.TemporaryDirectory(prefix='elbe-test-pbuilder-xml-') as build_dir:
+
+ prj = os.path.join(build_dir, 'uuid.prj')
+ uuid = None
+
+ try:
+ system(f'{sys.executable} {elbe_exe} pbuilder create --xmlfile "{self.param}" \
+ --writeproject "{prj}"')
+ with open(prj, 'r') as f:
+ uuid = f.read()
+
+ for package in ['libgpio', 'gpiotest']:
+ system(f'cd "{build_dir}"; \
+ git clone https://github.com/Linutronix/{package}.git')
+ system(f'cd "{build_dir}/{package}"; \
+ {sys.executable} {elbe_exe} pbuilder build --project {uuid}')
+ except Exception as e:
+ raise e
+ else:
+ # This is a tearDown of the project, it's okay if it fails
+ system(
+ f'{sys.executable} {elbe_exe} control del_project {uuid}', allow_fail=True)
--
2.44.0
More information about the elbe-devel
mailing list