diff mbox series

[4/4] oeqa/selftest: add test case for oeqa.utils.subprocesstweak

Message ID 20250604140326.2214919-4-ross.burton@arm.com
State New
Headers show
Series [1/4] recipetool/create: show more of the license path when it can't be identified | expand

Commit Message

Ross Burton June 4, 2025, 2:03 p.m. UTC
This class has a monkey-patched CalledProcessError instance that extends
the __str__ method. Add a test case to ensure that it behaves as
expected.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/lib/oeqa/selftest/cases/liboe.py | 35 ++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

Comments

Mathieu Dubois-Briand June 5, 2025, 6:17 p.m. UTC | #1
On Wed Jun 4, 2025 at 4:03 PM CEST, Ross Burton via lists.openembedded.org wrote:
> This class has a monkey-patched CalledProcessError instance that extends
> the __str__ method. Add a test case to ensure that it behaves as
> expected.
>
> Signed-off-by: Ross Burton <ross.burton@arm.com>
> ---

Hi Ross,

I believe we have an issue with this series on selftests:

2025-06-05 11:58:18,605 - oe-selftest - INFO - setUpClass (liboe.CopyTreeTests) [ (subunit.RemotedTestCase)
2025-06-05 11:58:18,606 - oe-selftest - INFO -  ... ERROR
...
2025-06-05 11:58:18,606 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/srv/pokybuild/yocto-worker/oe-selftest-fedora/build/meta/lib/oeqa/core/case.py", line 39, in _oeSetUpClass
    clss.setUpClassMethod()
  File "/srv/pokybuild/yocto-worker/oe-selftest-fedora/build/meta/lib/oeqa/selftest/cases/liboe.py", line 16, in setUpClass
    super(LibOE, cls).setUpClass()
          ^^^^^
NameError: name 'LibOE' is not defined

https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/1644
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/1703
https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/1853
Ross Burton June 6, 2025, 10:27 a.m. UTC | #2
> On 5 Jun 2025, at 19:17, Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> wrote:
> I believe we have an issue with this series on selftests:
> 
> 2025-06-05 11:58:18,605 - oe-selftest - INFO - setUpClass (liboe.CopyTreeTests) [ (subunit.RemotedTestCase)
> 2025-06-05 11:58:18,606 - oe-selftest - INFO -  ... ERROR
> ...
> 2025-06-05 11:58:18,606 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
>  File "/srv/pokybuild/yocto-worker/oe-selftest-fedora/build/meta/lib/oeqa/core/case.py", line 39, in _oeSetUpClass
>    clss.setUpClassMethod()
>  File "/srv/pokybuild/yocto-worker/oe-selftest-fedora/build/meta/lib/oeqa/selftest/cases/liboe.py", line 16, in setUpClass
>    super(LibOE, cls).setUpClass()
>          ^^^^^
> NameError: name 'LibOE' is not defined

Yes, the v2 fixed this.

Ross
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/liboe.py b/meta/lib/oeqa/selftest/cases/liboe.py
index d5ffffdcb41..4eab9441435 100644
--- a/meta/lib/oeqa/selftest/cases/liboe.py
+++ b/meta/lib/oeqa/selftest/cases/liboe.py
@@ -9,7 +9,7 @@  from oeqa.utils.commands import get_bb_var, get_bb_vars, bitbake, runCmd
 import oe.path
 import os
 
-class LibOE(OESelftestTestCase):
+class CopyTreeTests(OESelftestTestCase):
 
     @classmethod
     def setUpClass(cls):
@@ -102,3 +102,36 @@  class LibOE(OESelftestTestCase):
         self.assertEqual(dstcnt, len(testfiles), "Number of files in dst (%s) differs from number of files in src(%s)." % (dstcnt, srccnt))
 
         oe.path.remove(testloc)
+
+class SubprocessTests(OESelftestTestCase):
+
+    def test_subprocess_tweak(self):
+        """
+        Test that the string representation of
+        oeqa.utils.subprocesstweak.OETestCalledProcessError includes stdout and
+        stderr, as expected.
+        """
+        script = """
+#! /bin/sh
+echo Ivn fgqbhg | tr '[a-zA-Z]' '[n-za-mN-ZA-M]'
+echo Ivn fgqree | tr '[a-zA-Z]' '[n-za-mN-ZA-M]' >&2
+exit 42
+        """
+
+        import subprocess
+        import unittest.mock
+        from oeqa.utils.subprocesstweak import OETestCalledProcessError
+
+        with self.assertRaises(OETestCalledProcessError) as cm:
+            with unittest.mock.patch("subprocess.CalledProcessError", OETestCalledProcessError):
+                subprocess.run(["bash", "-"], input=script, text=True, capture_output=True, check=True)
+
+        e = cm.exception
+        self.assertEqual(e.returncode, 42)
+        self.assertEqual("Via stdout\n", e.stdout)
+        self.assertEqual("Via stderr\n", e.stderr)
+
+        string = str(e)
+        self.assertIn("exit status 42", string)
+        self.assertIn("Standard Output: Via stdout", string)
+        self.assertIn("Standard Error: Via stderr", string)