Skip to content

Commit 7a1d8cd

Browse files
committed
Use os.path where possible
1 parent 3e88c79 commit 7a1d8cd

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

cortexutils/analyzer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def get_param(self, name, default=None, message=None):
3737
and self.data_type == "file"
3838
and self.job_directory is not None
3939
):
40-
path = f"{self.job_directory}/input/{data}"
41-
if os.path.isfile(path):
42-
return path
40+
input_path = os.path.join(self.job_directory, "input", data)
41+
if os.path.isfile(input_path):
42+
return input_path
4343
else:
4444
return data
4545

cortexutils/worker.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ def __init__(self, job_directory, secret_phrases):
1717
if len(sys.argv) > 1:
1818
job_directory = sys.argv[1]
1919
else:
20-
job_directory = "/job"
20+
job_directory = os.path.join(job_directory, "job")
2121
self.job_directory = job_directory
2222
if secret_phrases is None:
2323
self.secret_phrases = DEFAULT_SECRET_PHRASES
2424
else:
2525
self.secret_phrases = secret_phrases
2626
# Load input
2727
self._input = {}
28-
input_path = f"{self.job_directory}/input/input.json"
28+
input_path = os.path.join(self.job_directory, "input", "input.json")
2929
if os.path.isfile(input_path):
3030
with open(input_path) as f_input:
3131
self._input = json.load(f_input)
@@ -118,9 +118,10 @@ def __write_output(self, data, ensure_ascii=False):
118118
if self.job_directory is None:
119119
json.dump(data, sys.stdout, ensure_ascii=ensure_ascii)
120120
else:
121-
output_path = f"{self.job_directory}/output"
122-
os.makedirs(output_path, exist_ok=True)
123-
with open(f"{output_path}/output.json", mode="w") as f_output:
121+
output_dir = os.path.join(self.job_directory, "output")
122+
os.makedirs(output_dir, exist_ok=True)
123+
output_path = os.path.join(output_dir, "output.json")
124+
with open(output_path, mode="w") as f_output:
124125
json.dump(data, f_output, ensure_ascii=ensure_ascii)
125126

126127
def get_data(self):

tests/test_suite_analyzer.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212

1313

1414
def load_test_fixture(fixture_path):
15-
path = os.path.dirname(os.path.abspath(__file__))
16-
with open(path + "/" + fixture_path) as fixture_file:
15+
tests_dir = os.path.dirname(os.path.abspath(__file__))
16+
file_path = os.path.join(tests_dir, fixture_path)
17+
with open(file_path) as fixture_file:
1718
input = fixture_file.read()
1819
sys.stdin = StringIO(input)
1920
sys.stdout = StringIO()
2021

2122

2223
class TestMinimalConfig(unittest.TestCase):
2324
def setUp(self):
24-
load_test_fixture("fixtures/test-minimal-config.json")
25+
fixture_path = os.path.join("fixtures", "test-minimal-config.json")
26+
load_test_fixture(fixture_path)
2527
self.analyzer = Analyzer()
2628

2729
def test_default_config(self):
@@ -43,7 +45,8 @@ def test_params_data(self):
4345

4446
class TestProxyConfig(unittest.TestCase):
4547
def setUp(self):
46-
load_test_fixture("fixtures/test-proxy-config.json")
48+
fixture_path = os.path.join("fixtures", "test-proxy-config.json")
49+
load_test_fixture(fixture_path)
4750
self.analyzer = Analyzer()
4851

4952
def test_proxy_config(self):
@@ -58,7 +61,8 @@ def test_proxy_config(self):
5861

5962
class TestTlpConfig(unittest.TestCase):
6063
def setUp(self):
61-
load_test_fixture("fixtures/test-tlp-config.json")
64+
fixture_path = os.path.join("fixtures", "test-tlp-config.json")
65+
load_test_fixture(fixture_path)
6266
self.analyzer = Analyzer()
6367

6468
def test_check_tlp_disabled(self):
@@ -89,7 +93,8 @@ def test_check_tlp_ok(self):
8993

9094
class TestErrorResponse(unittest.TestCase):
9195
def setUp(self):
92-
load_test_fixture("fixtures/test-error-response.json")
96+
fixture_path = os.path.join("fixtures", "test-error-response.json")
97+
load_test_fixture(fixture_path)
9398
self.analyzer = Analyzer()
9499

95100
def test_error_response(self):
@@ -124,7 +129,8 @@ def test_error_response(self):
124129

125130
class TestReportResponse(unittest.TestCase):
126131
def setUp(self):
127-
load_test_fixture("fixtures/test-report-response.json")
132+
fixture_path = os.path.join("fixtures", "test-report-response.json")
133+
load_test_fixture(fixture_path)
128134
self.analyzer = Analyzer()
129135

130136
def test_report_response(self):

0 commit comments

Comments
 (0)