]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
test/test_repo_utils: correctly parse system git version 1993/head
authorKyr Shatskyy <kyrylo.shatskyy@clyso.com>
Sat, 3 Aug 2024 15:12:22 +0000 (17:12 +0200)
committerKyr Shatskyy <kyrylo.shatskyy@clyso.com>
Sun, 4 Aug 2024 23:10:13 +0000 (01:10 +0200)
On macos there are bunch of tests fails because system
git version output cannot be parsed because of extra ending.

Output example for macos:
   git version 2.39.3 (Apple Git-146)
Output example for linux:
   git version 2.45.2

Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
teuthology/test/test_repo_utils.py

index a155fd410ef608ed1b91aae915b4248dbae725f9..969f82513857511d2338cfd92f51a54628ae80f2 100644 (file)
@@ -3,6 +3,7 @@ import unittest.mock as mock
 import os
 import os.path
 from pytest import raises, mark
+import re
 import shutil
 import subprocess
 import tempfile
@@ -29,14 +30,21 @@ class TestRepoUtils(object):
             cls.repo_url = 'file://' + cls.src_path
             cls.commit = None
 
-        cls.git_version = parse(
-            subprocess.check_output(('git', 'version')
-        ).decode().strip().split(' ')[-1])
+        cls.git_version = parse(cls.get_system_git_version())
 
     @classmethod
     def teardown_class(cls):
         shutil.rmtree(cls.temp_path)
 
+    @classmethod
+    def get_system_git_version(cls):
+        # parsing following patterns
+        # 1) git version 2.45.2
+        # 2) git version 2.39.3 (Apple Git-146)
+        git_version = subprocess.check_output(('git', 'version')).decode()
+        m = re.match(r"git version (?P<ver>\d+.\d+.\d+) ?", git_version)
+        return m['ver']
+
     def setup_method(self, method):
         # In git 2.28.0, the --initial-branch flag was added.
         if self.git_version >= parse("2.28.0"):
@@ -239,4 +247,4 @@ class TestRepoUtils(object):
 
     def test_current_branch(self):
         repo_utils.clone_repo(self.repo_url, self.dest_path, 'main', self.commit)
-        assert repo_utils.current_branch(self.dest_path) == "main"
\ No newline at end of file
+        assert repo_utils.current_branch(self.dest_path) == "main"