From 9246a3d583785582742b7de4ce823fc02b908ea5 Mon Sep 17 00:00:00 2001 From: Aleksa Svitlica Date: Wed, 15 Feb 2023 12:15:46 -0500 Subject: [PATCH] fix(cloud): Replace PurePath with os.path.join In Python 3.5 open does not work correctly with PurePath. Switching to os.path.join to resolve this. --- britney2/policies/cloud.py | 7 +++---- tests/test_cloud.py | 11 +++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/britney2/policies/cloud.py b/britney2/policies/cloud.py index 292f55b..0c6c6f7 100644 --- a/britney2/policies/cloud.py +++ b/britney2/policies/cloud.py @@ -1,6 +1,5 @@ import json import os -from pathlib import PurePath import re import shutil import smtplib @@ -288,7 +287,7 @@ class CloudPolicy(BasePolicy): result = None try: - with open(PurePath(self.work_dir, self.TEST_LOG_FILE), "w") as file: + with open(os.path.join(self.work_dir, self.TEST_LOG_FILE), "w") as file: result = subprocess.run( params, cwd=self.work_dir, @@ -328,7 +327,7 @@ class CloudPolicy(BasePolicy): file_paths = [] for file in os.listdir(self.work_dir): if re.fullmatch(file_regex, file): - file_paths.append(PurePath(self.work_dir, file)) + file_paths.append(os.path.join(self.work_dir, file)) return file_paths @@ -428,7 +427,7 @@ class CloudPolicy(BasePolicy): :param package The name of the package to test """ possible_locations = [] - with open(PurePath(self.work_dir, self.TEST_LOG_FILE), "r") as file: + with open(os.path.join(self.work_dir, self.TEST_LOG_FILE), "r") as file: for line in file: if package not in line: continue diff --git a/tests/test_cloud.py b/tests/test_cloud.py index 2e859e7..3d34ea4 100644 --- a/tests/test_cloud.py +++ b/tests/test_cloud.py @@ -8,7 +8,6 @@ import os import json -import pathlib import sys from types import SimpleNamespace import unittest @@ -138,8 +137,8 @@ class T(unittest.TestCase): def test_finding_results_file(self): """Ensure result file output from Cloud Test Framework can be found""" - path = pathlib.PurePath(self.policy.work_dir, "TEST-FakeTests-20230101010101.xml") - path2 = pathlib.PurePath(self.policy.work_dir, "Test-OtherTests-20230101010101.xml") + path = os.path.join(self.policy.work_dir, "TEST-FakeTests-20230101010101.xml") + path2 = os.path.join(self.policy.work_dir, "Test-OtherTests-20230101010101.xml") with open(path, "a"): pass with open(path2, "a"): pass @@ -286,14 +285,14 @@ class T(unittest.TestCase): """ package = "tmux" - with open(pathlib.PurePath(self.policy.work_dir, self.policy.TEST_LOG_FILE), "w") as file: + with open(os.path.join(self.policy.work_dir, self.policy.TEST_LOG_FILE), "w") as file: file.write("Get: something \n".format(package)) file.write("Get: lib-{} \n".format(package)) install_source = self.policy._retrieve_package_install_source_from_test_output(package) self.assertIsNone(install_source) - with open(pathlib.PurePath(self.policy.work_dir, self.policy.TEST_LOG_FILE), "a") as file: + with open(os.path.join(self.policy.work_dir, self.policy.TEST_LOG_FILE), "a") as file: file.write("Get: {} \n".format(package)) install_source = self.policy._retrieve_package_install_source_from_test_output(package) @@ -325,7 +324,7 @@ class T(unittest.TestCase): Returns the path to the created file. """ os.makedirs(self.policy.work_dir, exist_ok=True) - path = pathlib.PurePath(self.policy.work_dir, "TEST-FakeTests-20230101010101.xml") + path = os.path.join(self.policy.work_dir, "TEST-FakeTests-20230101010101.xml") root = ET.Element("testsuite", attrib={"name": "FakeTests-1234567890"})