diff --git a/eessi_bot_job_manager.py b/eessi_bot_job_manager.py index ddf90722..7d40b545 100644 --- a/eessi_bot_job_manager.py +++ b/eessi_bot_job_manager.py @@ -251,19 +251,6 @@ def determine_finished_jobs(self, known_jobs, current_jobs): return finished_jobs - def read_job_pr_metadata(self, job_metadata_path): - """ - Determine metadata od a job - - Args: - job_metadata_path (string): path to job metadata file - - Returns: - (ConfigParser): instance of ConfigParser corresponding to the 'PR' - section or None - """ - return read_job_metadata_from_file(job_metadata_path, self.logfile) - def read_job_result(self, job_result_file_path): """ Read job result file and return the contents of the 'RESULT' section. @@ -345,7 +332,7 @@ def process_new_job(self, new_job): # assuming that a bot job's working directory contains a metadata # file, its existence is used to check if the job belongs to the bot - metadata_pr = self.read_job_pr_metadata(job_metadata_path) + metadata_pr = read_job_metadata_from_file(job_metadata_path, self.logfile) if metadata_pr is None: log(f"No metadata file found at {job_metadata_path} for job {job_id}, so skipping it", @@ -441,7 +428,7 @@ def process_running_jobs(self, running_job): job_metadata_path = os.path.join(job_dir, metadata_file) # check if metadata file exist - metadata_pr = self.read_job_pr_metadata(job_metadata_path) + metadata_pr = read_job_metadata_from_file(job_metadata_path, self.logfile) if metadata_pr is None: raise Exception("Unable to find metadata file") @@ -586,7 +573,7 @@ def process_finished_job(self, finished_job): # obtain id of PR comment to be updated (from file '_bot_jobID.metadata') metadata_file = f"_bot_job{job_id}.metadata" job_metadata_path = os.path.join(new_symlink, metadata_file) - metadata_pr = self.read_job_pr_metadata(job_metadata_path) + metadata_pr = read_job_metadata_from_file(job_metadata_path, self.logfile) if metadata_pr is None: raise Exception("Unable to find metadata file ... skip updating PR comment") diff --git a/tests/test_eessi_bot_job_manager.py b/tests/test_eessi_bot_job_manager.py index c04033b5..2843069a 100644 --- a/tests/test_eessi_bot_job_manager.py +++ b/tests/test_eessi_bot_job_manager.py @@ -10,34 +10,10 @@ # # license: GPLv2 # -import os -import shutil from eessi_bot_job_manager import EESSIBotSoftwareLayerJobManager -def test_read_job_pr_metadata(tmpdir): - # copy needed app.cfg from tests directory - shutil.copyfile("tests/test_app.cfg", "app.cfg") - - # if metadata file does not exist, we should get None as return value - job_manager = EESSIBotSoftwareLayerJobManager() - path = os.path.join(tmpdir, 'test.metadata') - assert job_manager.read_job_pr_metadata(path) is None - - with open(path, 'w') as fp: - fp.write('''[PR] - repo=test - pr_number=12345''') - - metadata_pr = job_manager.read_job_pr_metadata(path) - expected = { - "repo": "test", - "pr_number": "12345", - } - assert metadata_pr == expected - - def test_determine_running_jobs(): job_manager = EESSIBotSoftwareLayerJobManager() diff --git a/tests/test_tools_job_metadata.py b/tests/test_tools_job_metadata.py new file mode 100644 index 00000000..d667cae0 --- /dev/null +++ b/tests/test_tools_job_metadata.py @@ -0,0 +1,34 @@ +# Tests for 'tools/job_metadata.py' of the EESSI build-and-deploy bot, +# see https://github.com/EESSI/eessi-bot-software-layer +# +# The bot helps with requests to add software installations to the +# EESSI software layer, see https://github.com/EESSI/software-layer +# +# author: Thomas Roeblitz (@trz42) +# +# license: GPLv2 +# + +import os +import shutil + +from tools.job_metadata import read_job_metadata_from_file + + +def test_read_job_metadata_from_file(tmpdir): + logfile = os.path.join(tmpdir, 'test_read_job_metadata_from_file.log') + # if metadata file does not exist, we should get None as return value + path = os.path.join(tmpdir, 'test.metadata') + assert read_job_metadata_from_file(path, logfile) is None + + with open(path, 'w') as fp: + fp.write('''[PR] + repo=test + pr_number=12345''') + + metadata_pr = read_job_metadata_from_file(path, logfile) + expected = { + "repo": "test", + "pr_number": "12345", + } + assert metadata_pr == expected