]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python:tests: Skip the source_chars test if not a git dir
authorAndreas Schneider <asn@samba.org>
Fri, 14 Apr 2023 19:05:18 +0000 (21:05 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 21 Apr 2023 13:59:29 +0000 (13:59 +0000)
This test doesn't work in release tarballs. Skip it if git fails.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: David Mulder <dmulder@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Fri Apr 21 13:59:29 UTC 2023 on atb-devel-224

python/samba/tests/source_chars.py

index 49733968e43692e208e59021a15b060eeba33f4b..e0acb38b8f70f408b5b1dc85298e352f5e29b2b1 100644 (file)
@@ -23,7 +23,7 @@ from collections import Counter
 from samba.colour import c_RED, c_GREEN, c_DARK_YELLOW, switch_colour_off
 import re
 import unicodedata as u
-from samba.tests import TestCase
+from samba.tests import TestCase, SkipTest
 
 if not sys.stdout.isatty():
     switch_colour_off()
@@ -35,10 +35,15 @@ def _find_root():
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            timeout=10)
-    except subprocess.SubprocessError as e:
-        print(c_RED(f"Error running git (is this a git tree?): {e}"))
-        print("This test is only useful in a git working tree")
-        sys.exit(1)
+    except subprocess.CalledProcessError as err:
+        print(c_RED("Error running git (is this a git tree?): %s" % (err)))
+
+        SkipTest("This test is only useful in a git working tree")
+        sys.exit(0)
+
+    if p.returncode != 0:
+        raise SkipTest("This test is only useful in a git working tree")
+        sys.exit(0)
 
     root = p.stdout.decode().strip()
 
@@ -54,8 +59,7 @@ def _find_root():
     return root
 
 
-ROOT = _find_root()
-
+ROOT = None
 
 IGNORED_FILES = (
     'examples/validchars/validchr.com',
@@ -202,6 +206,11 @@ def is_bad_char(c):
 
 
 class CharacterTests(TestCase):
+    def setUp(self):
+        global ROOT
+        if not ROOT:
+            ROOT = _find_root()
+
     def test_no_unexpected_format_chars(self):
         """This test tries to ensure that no source file has unicode control
         characters that can change the apparent order of other