From 21ceac423f087e7e21a867824f1855fae4984424 Mon Sep 17 00:00:00 2001 From: Feng Chao Date: Thu, 7 Nov 2024 15:14:47 +0800 Subject: [PATCH] Update test_passwd.py to remove make operation --- tests/army/user/test_passwd.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/army/user/test_passwd.py b/tests/army/user/test_passwd.py index 62dc5782b7..08445b4523 100644 --- a/tests/army/user/test_passwd.py +++ b/tests/army/user/test_passwd.py @@ -1,3 +1,4 @@ +import os import subprocess from frame.log import * from frame.cases import * @@ -10,11 +11,11 @@ class TDTestCase(TBase): def apiPath(self): apiPath = None currentFilePath = os.path.dirname(os.path.realpath(__file__)) - if ("community/tests" in currentFilePath): - testFilePath = currentFilePath[:currentFilePath.find("community/tests")] + if (os.sep.join(["community", "tests"]) in currentFilePath): + testFilePath = currentFilePath[:currentFilePath.find(os.sep.join(["community", "tests"]))] else: - testFilePath = currentFilePath[:currentFilePath.find("TDengine/tests")] - + testFilePath = currentFilePath[:currentFilePath.find(os.sep.join(["TDengine", "tests"]))] + for root, dirs, files in os.walk(testFilePath): if ("passwdTest.c" in files): apiPath = root @@ -25,21 +26,20 @@ class TDTestCase(TBase): apiPath = self.apiPath() tdLog.info(f"api path: {apiPath}") if apiPath: - p = subprocess.Popen(f"cd {apiPath} && make", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() - if 0 != p.returncode: - tdLog.info(f"Test script passwdTest.c make failed with error: {err}") test_file_cmd = os.sep.join([apiPath, "passwdTest localhost"]) + try: + p = subprocess.Popen(test_file_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + if 0 != p.returncode: + tdLog.exit("Failed to run passwd test with output: %s \n error: %s" % (out, err)) + else: + tdLog.info(out) + tdLog.success(f"{__file__} successfully executed") + except Exception as e: + tdLog.exit(f"Failed to execute {__file__} with error: {e}") else: tdLog.exit("passwdTest.c not found") - try: - p = subprocess.Popen(test_file_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() - if 0 != p.returncode: - tdLog.exit("Failed to run passwd test with output: %s \n error: %s" % (out, err)) - tdLog.success(f"{__file__} successfully executed") - except Exception as e: - tdLog.exit(f"Failed to execute {__file__} with error: {e}") + tdCases.addLinux(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase())