diff --git a/tests/config/gent/gent_output b/tests/config/gent/gent_output new file mode 100644 index 00000000..20550534 --- /dev/null +++ b/tests/config/gent/gent_output @@ -0,0 +1,6 @@ +cluster:Mycluster +5322019|janj|R|pi_19576488 +5322016|janj|R|pi_19576485 +5322017|janj|R|pi_19576486 +5322018|janj|R|pi_19576487 +5322013|janj|R|pi_19576482 \ No newline at end of file diff --git a/tests/config/slurm/squeue_output b/tests/config/slurm/squeue_output index 5d1b44b9..e11334c7 100644 --- a/tests/config/slurm/squeue_output +++ b/tests/config/slurm/squeue_output @@ -2,4 +2,4 @@ 5322016|janj|R|pi_19576485|/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_2 5322017|janj|R|pi_19576486|/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_3 5322018|janj|R|pi_19576487|/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_4 -5322013|janj|R|pi_19576482|/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_5 \ No newline at end of file +5322013|maxi|R|pi_19576482|/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_5 \ No newline at end of file diff --git a/tests/test_basic.py b/tests/test_basic.py index 0ee675a6..a83ebae7 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -27,6 +27,10 @@ def test_missing_config(self): class TestBasisQueueAdapter(unittest.TestCase): + def test_bad_queue_type(self): + with self.assertRaises(ValueError): + BasisQueueAdapter(config={"queue_type": "error", "queues": {}}) + def test_memory_string_comparison(self): self.assertEqual(BasisQueueAdapter._value_in_range(1023, value_min="1K"), "1K") self.assertEqual(BasisQueueAdapter._value_in_range(1035, value_min="1K"), 1035) diff --git a/tests/test_cmd.py b/tests/test_cmd.py index 5d53f530..4d19c3e2 100644 --- a/tests/test_cmd.py +++ b/tests/test_cmd.py @@ -4,6 +4,10 @@ class TestCMD(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.test_dir = os.path.abspath(os.path.dirname(__file__)) + def test_help(self): with self.assertRaises(SystemExit): command_line(["--help"]) @@ -22,11 +26,10 @@ def execute_command( ): return "1\n" - test_dir = os.path.abspath(os.path.dirname(__file__)) with self.assertRaises(SystemExit): command_line( [ - "--config_directory", os.path.join(test_dir, "config", "slurm"), + "--config_directory", os.path.join(self.test_dir, "config", "slurm"), "--submit", "--queue", "slurm", "--job_name", "test", @@ -55,3 +58,65 @@ def execute_command( ] self.assertEqual(output, content) os.remove("run_queue.sh") + + def test_delete(self): + def execute_command( + commands, + working_directory=None, + split_output=True, + shell=False, + error_filename="pysqa.err", + ): + return "Success\n" + + with self.assertRaises(SystemExit): + command_line( + [ + "--config_directory", os.path.join(self.test_dir, "config", "slurm"), + "--delete", + "--id", "1", + ], + execute_command=execute_command + ) + + def test_status(self): + + def execute_command( + commands, + working_directory=None, + split_output=True, + shell=False, + error_filename="pysqa.err", + ): + with open(os.path.join(self.test_dir, "config", "slurm", "squeue_output")) as f: + return f.read() + + with self.assertRaises(SystemExit): + command_line( + [ + "--config_directory", os.path.join(self.test_dir, "config", "slurm"), + "--status" + ], + execute_command=execute_command + ) + + def test_list(self): + def execute_command( + commands, + working_directory=None, + split_output=True, + shell=False, + error_filename="pysqa.err", + ): + pass + + with self.assertRaises(SystemExit): + command_line( + [ + "--config_directory", os.path.join(self.test_dir, "config", "slurm"), + "--list", + "--working_directory", os.path.join(self.test_dir, "config", "slurm"), + + ], + execute_command=execute_command + ) diff --git a/tests/test_gent.py b/tests/test_gent.py index fe749c06..adac0974 100644 --- a/tests/test_gent.py +++ b/tests/test_gent.py @@ -2,6 +2,7 @@ # Copyright (c) Jan Janssen import os +import pandas import unittest from pysqa import QueueAdapter @@ -49,3 +50,29 @@ def test__list_command_to_be_executed(self): [], "here", ) + + def test_get_job_id_from_output(self): + self.assertEqual(self.gent._adapter._commands.get_job_id_from_output("123;MyQueue"), 123) + + def test_get_queue_from_output(self): + self.assertEqual(self.gent._adapter._commands.get_queue_from_output("123;MyQueue"), "MyQueue") + + def test_convert_queue_status_slurm(self): + with open(os.path.join(self.path, "config/gent", "gent_output"), "r") as f: + content = f.read() + df_verify = pandas.DataFrame( + { + "cluster": ["Mycluster", "Mycluster", "Mycluster", "Mycluster", "Mycluster"], + "jobid": [5322019, 5322016, 5322017, 5322018, 5322013], + "user": ["janj", "janj", "janj", "janj", "janj"], + "jobname": ["pi_19576488", "pi_19576485", "pi_19576486", "pi_19576487", "pi_19576482"], + "status": ["r", "r", "r", "r", "r"], + } + ) + self.assertTrue( + df_verify.equals( + self.gent._adapter._commands.convert_queue_status( + queue_status_output=content + ) + ) + ) diff --git a/tests/test_remote.py b/tests/test_remote.py index 41f83bc4..98a5dfa9 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -27,6 +27,9 @@ def test_config(self): def test_list_clusters(self): self.assertEqual(self.remote.list_clusters(), ['default']) + def test_remote_flag(self): + self.assertTrue(self.remote._adapter.remote_flag) + def test_ssh_delete_file_on_remote(self): self.assertEqual(self.remote.ssh_delete_file_on_remote, False) diff --git a/tests/test_scheduler_commands.py b/tests/test_scheduler_commands.py new file mode 100644 index 00000000..4b06d4a0 --- /dev/null +++ b/tests/test_scheduler_commands.py @@ -0,0 +1,65 @@ +import unittest +from pysqa.wrapper.generic import SchedulerCommands + + +class TmpSchedularCommands(SchedulerCommands): + def delete_job_command(self): + pass + + def get_queue_status_command(self): + pass + + def submit_job_command(self): + pass + + +class TestSchedulerCommands(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.commands = TmpSchedularCommands() + + def test_enable_reservation_command(self): + with self.assertRaises(NotImplementedError): + self.commands.enable_reservation_command() + + def test_get_job_id_from_output(self): + with self.assertRaises(NotImplementedError): + self.commands.get_job_id_from_output("test") + + def test_convert_queue_status(self): + with self.assertRaises(NotImplementedError): + self.commands.convert_queue_status("test") + + def test_no_delete_job_command(self): + class NoDelteteSchedularCommands(SchedulerCommands): + + def get_queue_status_command(self): + pass + + def submit_job_command(self): + pass + + with self.assertRaises(TypeError): + NoDelteteSchedularCommands() + + def test_get_queue_status_command(self): + class NoQueueStatusSchedularCommands(SchedulerCommands): + def delete_job_command(self): + pass + + def submit_job_command(self): + pass + + with self.assertRaises(TypeError): + NoQueueStatusSchedularCommands() + + def test_submit_job_command(self): + class NoSubmitSchedularCommands(SchedulerCommands): + def delete_job_command(self): + pass + + def get_queue_status_command(self): + pass + + with self.assertRaises(TypeError): + NoSubmitSchedularCommands() diff --git a/tests/test_slurm.py b/tests/test_slurm.py index c80f8725..0e4bce99 100644 --- a/tests/test_slurm.py +++ b/tests/test_slurm.py @@ -29,6 +29,9 @@ def test_config(self): def test_list_clusters(self): self.assertEqual(self.slurm.list_clusters(), ['default']) + def test_remote_flag(self): + self.assertFalse(self.slurm._adapter.remote_flag) + def test_ssh_delete_file_on_remote(self): self.assertEqual(self.slurm.ssh_delete_file_on_remote, True) @@ -65,7 +68,7 @@ def test_convert_queue_status_slurm(self): df_verify = pandas.DataFrame( { "jobid": [5322019, 5322016, 5322017, 5322018, 5322013], - "user": ["janj", "janj", "janj", "janj", "janj"], + "user": ["janj", "janj", "janj", "janj", "maxi"], "jobname": ["pi_19576488", "pi_19576485", "pi_19576486", "pi_19576487", "pi_19576482"], "status": ["running", "running", "running", "running", "running"], "working_directory": [ @@ -158,3 +161,25 @@ def test_write_queue_extra_keywords(self): echo \"hello\"""" self.assertEqual(content, output) os.remove("run_queue.sh") + + def test_no_queue_id_returned(self): + def execute_command( + commands, + working_directory=None, + split_output=True, + shell=False, + error_filename="pysqa.err", + ): + pass + + slurm_tmp = QueueAdapter( + directory=os.path.join(self.path, "config/slurm"), + execute_command=execute_command + ) + self.assertIsNone(slurm_tmp.submit_job( + queue="slurm", + job_name="test", + working_directory=".", + command="echo hello" + )) + self.assertIsNone(slurm_tmp.delete_job(process_id=123))