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.
sil2100/source-and-binaries
Aleksa Svitlica 2 years ago
parent bea7377396
commit 9246a3d583

@ -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

@ -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"})

Loading…
Cancel
Save