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 json
import os import os
from pathlib import PurePath
import re import re
import shutil import shutil
import smtplib import smtplib
@ -288,7 +287,7 @@ class CloudPolicy(BasePolicy):
result = None result = None
try: 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( result = subprocess.run(
params, params,
cwd=self.work_dir, cwd=self.work_dir,
@ -328,7 +327,7 @@ class CloudPolicy(BasePolicy):
file_paths = [] file_paths = []
for file in os.listdir(self.work_dir): for file in os.listdir(self.work_dir):
if re.fullmatch(file_regex, file): 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 return file_paths
@ -428,7 +427,7 @@ class CloudPolicy(BasePolicy):
:param package The name of the package to test :param package The name of the package to test
""" """
possible_locations = [] 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: for line in file:
if package not in line: if package not in line:
continue continue

@ -8,7 +8,6 @@
import os import os
import json import json
import pathlib
import sys import sys
from types import SimpleNamespace from types import SimpleNamespace
import unittest import unittest
@ -138,8 +137,8 @@ class T(unittest.TestCase):
def test_finding_results_file(self): def test_finding_results_file(self):
"""Ensure result file output from Cloud Test Framework can be found""" """Ensure result file output from Cloud Test Framework can be found"""
path = pathlib.PurePath(self.policy.work_dir, "TEST-FakeTests-20230101010101.xml") path = os.path.join(self.policy.work_dir, "TEST-FakeTests-20230101010101.xml")
path2 = pathlib.PurePath(self.policy.work_dir, "Test-OtherTests-20230101010101.xml") path2 = os.path.join(self.policy.work_dir, "Test-OtherTests-20230101010101.xml")
with open(path, "a"): pass with open(path, "a"): pass
with open(path2, "a"): pass with open(path2, "a"): pass
@ -286,14 +285,14 @@ class T(unittest.TestCase):
""" """
package = "tmux" 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: something \n".format(package))
file.write("Get: lib-{} \n".format(package)) file.write("Get: lib-{} \n".format(package))
install_source = self.policy._retrieve_package_install_source_from_test_output(package) install_source = self.policy._retrieve_package_install_source_from_test_output(package)
self.assertIsNone(install_source) 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)) file.write("Get: {} \n".format(package))
install_source = self.policy._retrieve_package_install_source_from_test_output(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. Returns the path to the created file.
""" """
os.makedirs(self.policy.work_dir, exist_ok=True) 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"}) root = ET.Element("testsuite", attrib={"name": "FakeTests-1234567890"})

Loading…
Cancel
Save