|
| 1 | +# coding: utf-8 |
| 2 | +# Copyright (c) Jan Janssen |
| 3 | + |
| 4 | +import os |
| 5 | +import unittest |
| 6 | +import pandas |
| 7 | +from pysqa import QueueAdapter |
| 8 | + |
| 9 | + |
| 10 | +try: |
| 11 | + import flux |
| 12 | + skip_flux_test = False |
| 13 | +except ImportError: |
| 14 | + skip_flux_test = True |
| 15 | + |
| 16 | + |
| 17 | +@unittest.skipIf(skip_flux_test, "Flux is not installed, so the flux tests are skipped") |
| 18 | +class TestFluxQueueAdapter(unittest.TestCase): |
| 19 | + @classmethod |
| 20 | + def setUpClass(cls): |
| 21 | + cls.path = os.path.dirname(os.path.abspath(__file__)) |
| 22 | + cls.flux = QueueAdapter(directory=os.path.join(cls.path, "config/flux")) |
| 23 | + |
| 24 | + def test_config(self): |
| 25 | + self.assertEqual(self.flux.config["queue_type"], "FLUX") |
| 26 | + self.assertEqual(self.flux.config["queue_primary"], "flux") |
| 27 | + |
| 28 | + def test_list_clusters(self): |
| 29 | + self.assertEqual(self.flux.list_clusters(), ['default']) |
| 30 | + |
| 31 | + def test_remote_flag(self): |
| 32 | + self.assertFalse(self.flux._adapter.remote_flag) |
| 33 | + |
| 34 | + def test_ssh_delete_file_on_remote(self): |
| 35 | + self.assertEqual(self.flux.ssh_delete_file_on_remote, True) |
| 36 | + |
| 37 | + def test_interfaces(self): |
| 38 | + self.assertEqual( |
| 39 | + self.flux._adapter._commands.submit_job_command, ["flux", "batch"] |
| 40 | + ) |
| 41 | + self.assertEqual(self.flux._adapter._commands.delete_job_command, ["flux", "cancel"]) |
| 42 | + self.assertEqual( |
| 43 | + self.flux._adapter._commands.get_queue_status_command, |
| 44 | + ["flux", "jobs", "-a", "--no-header"], |
| 45 | + ) |
| 46 | + |
| 47 | + def test_convert_queue_status_slurm(self): |
| 48 | + with open(os.path.join(self.path, "config/flux", "flux_jobs"), "r") as f: |
| 49 | + content = f.read() |
| 50 | + df = pandas.DataFrame({ |
| 51 | + "jobid": [1125147213824, 1109007532032, 1092532305920], |
| 52 | + "user": ["dahn", "dahn", "dahn"], |
| 53 | + "jobname": ["sleep_batc", "sleep_batc", "sleep_batc"], |
| 54 | + "status": ["running", "running", "running"] |
| 55 | + }) |
| 56 | + self.assertTrue(df.equals(self.flux._adapter._commands.convert_queue_status( |
| 57 | + queue_status_output=content |
| 58 | + ))) |
| 59 | + |
| 60 | + def test_submit_job(self): |
| 61 | + def execute_command( |
| 62 | + commands, |
| 63 | + working_directory=None, |
| 64 | + split_output=True, |
| 65 | + shell=False, |
| 66 | + error_filename="pysqa.err", |
| 67 | + ): |
| 68 | + return "ƒWZEQa8X\n" |
| 69 | + |
| 70 | + flux_tmp = QueueAdapter( |
| 71 | + directory=os.path.join(self.path, "config/flux"), |
| 72 | + execute_command=execute_command |
| 73 | + ) |
| 74 | + self.assertEqual(flux_tmp.submit_job( |
| 75 | + queue="flux", |
| 76 | + job_name="test", |
| 77 | + working_directory=".", |
| 78 | + cores=4, |
| 79 | + command="echo hello" |
| 80 | + ), 1125147213824) |
| 81 | + with open("run_queue.sh") as f: |
| 82 | + output = f.read() |
| 83 | + content = """\ |
| 84 | +#!/bin/bash |
| 85 | +#flux: -n4 --job-name=test --env=CORES=4 --output=time.out --error=error.out |
| 86 | +echo hello""" |
| 87 | + self.assertEqual(content, output) |
| 88 | + os.remove("run_queue.sh") |
0 commit comments