@@ -11,12 +11,11 @@ class TestCMD(unittest.TestCase):
1111 def setUpClass (cls ):
1212 cls .test_dir = os .path .abspath (os .path .dirname (__file__ ))
1313
14- @unittest .mock .patch ('sys.stdout' , new_callable = io .StringIO )
15- def assert_stdout_command_line (self , cmd_args , execute_command , expected_output , mock_stdout ):
16- command_line (
17- arguments_lst = cmd_args ,
18- execute_command = execute_command
19- )
14+ @unittest .mock .patch ("sys.stdout" , new_callable = io .StringIO )
15+ def assert_stdout_command_line (
16+ self , cmd_args , execute_command , expected_output , mock_stdout
17+ ):
18+ command_line (arguments_lst = cmd_args , execute_command = execute_command )
2019 self .assertEqual (mock_stdout .getvalue (), expected_output )
2120
2221 def test_help (self ):
@@ -45,33 +44,41 @@ def execute_command(
4544
4645 self .assert_stdout_command_line (
4746 [
48- "--config_directory" , os .path .join (self .test_dir , "config" , "slurm" ),
47+ "--config_directory" ,
48+ os .path .join (self .test_dir , "config" , "slurm" ),
4949 "--submit" ,
50- "--queue" , "slurm" ,
51- "--job_name" , "test" ,
52- "--working_directory" , "." ,
53- "--cores" , "2" ,
54- "--memory" , "1GB" ,
55- "--run_time" , "10" ,
56- "--command" , "echo hello"
50+ "--queue" ,
51+ "slurm" ,
52+ "--job_name" ,
53+ "test" ,
54+ "--working_directory" ,
55+ "." ,
56+ "--cores" ,
57+ "2" ,
58+ "--memory" ,
59+ "1GB" ,
60+ "--run_time" ,
61+ "10" ,
62+ "--command" ,
63+ "echo hello" ,
5764 ],
5865 execute_command ,
5966 "1\n " ,
6067 )
6168 with open ("run_queue.sh" ) as f :
6269 output = f .readlines ()
6370 content = [
64- ' #!/bin/bash\n ' ,
65- ' #SBATCH --output=time.out\n ' ,
66- ' #SBATCH --job-name=test\n ' ,
67- ' #SBATCH --chdir=.\n ' ,
68- ' #SBATCH --get-user-env=L\n ' ,
69- ' #SBATCH --partition=slurm\n ' ,
70- ' #SBATCH --time=4320\n ' ,
71- ' #SBATCH --mem=1GBG\n ' ,
72- ' #SBATCH --cpus-per-task=10\n ' ,
73- ' \n ' ,
74- ' echo hello'
71+ " #!/bin/bash\n " ,
72+ " #SBATCH --output=time.out\n " ,
73+ " #SBATCH --job-name=test\n " ,
74+ " #SBATCH --chdir=.\n " ,
75+ " #SBATCH --get-user-env=L\n " ,
76+ " #SBATCH --partition=slurm\n " ,
77+ " #SBATCH --time=4320\n " ,
78+ " #SBATCH --mem=1GBG\n " ,
79+ " #SBATCH --cpus-per-task=10\n " ,
80+ " \n " ,
81+ " echo hello" ,
7582 ]
7683 self .assertEqual (output , content )
7784 os .remove ("run_queue.sh" )
@@ -88,12 +95,14 @@ def execute_command(
8895
8996 self .assert_stdout_command_line (
9097 [
91- "--config_directory" , os .path .join (self .test_dir , "config" , "slurm" ),
98+ "--config_directory" ,
99+ os .path .join (self .test_dir , "config" , "slurm" ),
92100 "--delete" ,
93- "--id" , "1"
101+ "--id" ,
102+ "1" ,
94103 ],
95104 execute_command ,
96- "S\n "
105+ "S\n " ,
97106 )
98107
99108 def test_status (self ):
@@ -104,27 +113,40 @@ def execute_command(
104113 shell = False ,
105114 error_filename = "pysqa.err" ,
106115 ):
107- with open (os .path .join (self .test_dir , "config" , "slurm" , "squeue_output" )) as f :
116+ with open (
117+ os .path .join (self .test_dir , "config" , "slurm" , "squeue_output" )
118+ ) as f :
108119 return f .read ()
109120
110121 self .assert_stdout_command_line (
111122 [
112- "--config_directory" , os .path .join (self .test_dir , "config" , "slurm" ),
113- "--status"
123+ "--config_directory" ,
124+ os .path .join (self .test_dir , "config" , "slurm" ),
125+ "--status" ,
114126 ],
115127 execute_command ,
116- json .dumps ({
117- "jobid" : [5322019 , 5322016 , 5322017 , 5322018 , 5322013 ], "user" : ["janj" , "janj" , "janj" , "janj" , "maxi" ],
118- "jobname" : ["pi_19576488" , "pi_19576485" , "pi_19576486" , "pi_19576487" , "pi_19576482" ],
119- "status" : ["running" , "running" , "running" , "running" , "running" ],
120- "working_directory" : [
121- "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_1" ,
122- "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_2" ,
123- "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_3" ,
124- "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_4" ,
125- "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_5"
126- ]
127- }) + "\n "
128+ json .dumps (
129+ {
130+ "jobid" : [5322019 , 5322016 , 5322017 , 5322018 , 5322013 ],
131+ "user" : ["janj" , "janj" , "janj" , "janj" , "maxi" ],
132+ "jobname" : [
133+ "pi_19576488" ,
134+ "pi_19576485" ,
135+ "pi_19576486" ,
136+ "pi_19576487" ,
137+ "pi_19576482" ,
138+ ],
139+ "status" : ["running" , "running" , "running" , "running" , "running" ],
140+ "working_directory" : [
141+ "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_1" ,
142+ "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_2" ,
143+ "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_3" ,
144+ "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_4" ,
145+ "/cmmc/u/janj/pyiron/projects/2023/2023-04-19-dft-test/job_5" ,
146+ ],
147+ }
148+ )
149+ + "\n " ,
128150 )
129151
130152 def test_list (self ):
@@ -139,19 +161,31 @@ def execute_command(
139161
140162 self .assert_stdout_command_line (
141163 [
142- "--config_directory" , os .path .join (self .test_dir , "config" , "slurm" ),
164+ "--config_directory" ,
165+ os .path .join (self .test_dir , "config" , "slurm" ),
143166 "--list" ,
144- "--working_directory" , os . path . join ( self . test_dir , "config" , "slurm" ),
145-
167+ "--working_directory" ,
168+ os . path . join ( self . test_dir , "config" , "slurm" ),
146169 ],
147170 execute_command ,
148- json .dumps ({
149- "dirs" : [os .path .join (self .test_dir , "config" , "slurm" )],
150- "files" : sorted ([
151- os .path .join (self .test_dir , "config" , "slurm" , "squeue_output" ),
152- os .path .join (self .test_dir , "config" , "slurm" , "slurm_extra.sh" ),
153- os .path .join (self .test_dir , "config" , "slurm" , "slurm.sh" ),
154- os .path .join (self .test_dir , "config" , "slurm" , "queue.yaml" ),
155- ])
156- }) + "\n "
171+ json .dumps (
172+ {
173+ "dirs" : [os .path .join (self .test_dir , "config" , "slurm" )],
174+ "files" : sorted (
175+ [
176+ os .path .join (
177+ self .test_dir , "config" , "slurm" , "squeue_output"
178+ ),
179+ os .path .join (
180+ self .test_dir , "config" , "slurm" , "slurm_extra.sh"
181+ ),
182+ os .path .join (self .test_dir , "config" , "slurm" , "slurm.sh" ),
183+ os .path .join (
184+ self .test_dir , "config" , "slurm" , "queue.yaml"
185+ ),
186+ ]
187+ ),
188+ }
189+ )
190+ + "\n " ,
157191 )
0 commit comments