From af5bafad561fc1079c08319361b0875fe42b28d2 Mon Sep 17 00:00:00 2001 From: Archana Pandey Date: Tue, 6 Aug 2024 13:55:55 +0530 Subject: [PATCH] feat: added property to return rhc version Signed-off-by: Archana Pandey --- pytest_client_tools/rhc.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pytest_client_tools/rhc.py b/pytest_client_tools/rhc.py index 4fec3d3..2d5f898 100644 --- a/pytest_client_tools/rhc.py +++ b/pytest_client_tools/rhc.py @@ -3,9 +3,10 @@ import json import pathlib +import re import subprocess -from .util import SavedFile, logged_run +from .util import SavedFile, logged_run, Version RHC_FILES_TO_SAVE = ( @@ -36,6 +37,20 @@ def is_registered(self): doc = json.loads(proc.stdout) return doc["rhsm_connected"] + @property + def version(self): + """ + Return the version of rhc as + [`Version`][pytest_client_tools.util.Version] object. + + :return: The version of the rhc in use. + :rtype: pytest_client_tools.util.Version + """ + proc = self.run("--version") + m = re.search(r"^rhc version (.+)$", proc.stdout, re.MULTILINE) + assert m + return Version(m.group(1)) + def run(self, *args, check=True, text=True): """ Run `rhc` with the specified arguments.