Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/config/gent/gent_output
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/config/slurm/squeue_output
Original file line number Diff line number Diff line change
Expand Up @@ -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
5322013|maxi|R|pi_19576482|/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_5
4 changes: 4 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
69 changes: 67 additions & 2 deletions tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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",
Expand Down Expand Up @@ -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
)
27 changes: 27 additions & 0 deletions tests/test_gent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) Jan Janssen

import os
import pandas
import unittest
from pysqa import QueueAdapter

Expand Down Expand Up @@ -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
)
)
)
3 changes: 3 additions & 0 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
65 changes: 65 additions & 0 deletions tests/test_scheduler_commands.py
Original file line number Diff line number Diff line change
@@ -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()
27 changes: 26 additions & 1 deletion tests/test_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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))