@@ -33,14 +33,19 @@ class TestSubmissionCommands(unittest.TestCase):
3333 # which chunk to run
3434 chunk_index = 1
3535
36- def setUp (self ):
36+ out_f = None
37+ results = {}
38+ exec_status = {}
39+
40+ @classmethod
41+ def setUpClass (cls ):
3742 """
38- Grabs files from the examples folder
43+ Class-level setup: Grabs files from the examples folder, discover & rewrite example commands, then execute them once.
3944 """
4045 submissions = glob .glob (f"{ script_dir } /../examples/*.sh" )
4146 # get datetime for output folder, in YYYY_MM_DD_HH_MM_SS format
42- chunks = self . __class__ .total_chunks
43- idx = self . __class__ .chunk_index
47+ chunks = cls .total_chunks
48+ idx = cls .chunk_index
4449 if chunks < 1 :
4550 raise ValueError ("total_chunks must be at least 1" )
4651 if idx < 1 or idx > chunks :
@@ -61,8 +66,8 @@ def setUp(self):
6166
6267 now = datetime .datetime .now ()
6368 now = now .strftime ("%Y_%m_%d_%H_%M_%S" )
64- self .out_f = f"{ script_dir } /tests_{ now } _{ idx } "
65- os .mkdir (self .out_f )
69+ cls .out_f = f"{ script_dir } /tests_{ now } _{ idx } "
70+ os .mkdir (cls .out_f )
6671
6772 # Make sure we have access to all the relevant files
6873 exclude_dirs = ["outputs" , "example_outputs" ]
@@ -78,26 +83,26 @@ def setUp(self):
7883 )
7984
8085 for submission in submissions :
81- self ._write_command (submission , self .out_f )
86+ cls ._write_command (submission , cls .out_f )
8287
8388 print (
84- f"Running commands in { self .out_f } , two steps of diffusion, deterministic=True"
89+ f"Running commands in { cls .out_f } , two steps of diffusion, deterministic=True"
8590 )
8691
87- self .results = {}
88- self .exec_status = {}
92+ cls .results = {}
93+ cls .exec_status = {}
8994
90- for bash_file in sorted (glob .glob (f"{ self .out_f } /*.sh" ), reverse = False ):
95+ for bash_file in sorted (glob .glob (f"{ cls .out_f } /*.sh" ), reverse = False ):
9196 test_name = os .path .basename (bash_file )[: - len (".sh" )]
9297 res , output = execute (
9398 f"Running { test_name } " ,
9499 f"bash { bash_file } " ,
95100 return_ = "tuple" ,
96101 add_message_and_command_line_to_output = True ,
97102 )
98- self .exec_status [test_name ] = (res , output )
103+ cls .exec_status [test_name ] = (res , output )
99104
100- self .results [test_name ] = dict (
105+ cls .results [test_name ] = dict (
101106 state = "failed" if res else "passed" ,
102107 log = output ,
103108 )
@@ -106,7 +111,7 @@ def setUp(self):
106111 # subprocess.run(["bash", bash_file])
107112
108113 def test_examples_run_without_errors (self ):
109- for name , (exit_code , output ) in sorted (self .exec_status .items ()):
114+ for name , (exit_code , output ) in sorted (self .__class__ . exec_status .items ()):
110115 with self .subTest (example = name ):
111116 if exit_code != 0 :
112117 self .__class__ .failed_tests .append (f"{ name } " )
@@ -128,8 +133,8 @@ def test_commands(self):
128133 """
129134 reference = f"{ script_dir } /reference_outputs"
130135 os .makedirs (reference , exist_ok = True )
131- test_files = glob .glob (f"{ self .out_f } /example_outputs/*pdb" )
132- print (f"{ self .out_f = } { test_files = } " )
136+ test_files = glob .glob (f"{ self .__class__ . out_f } /example_outputs/*pdb" )
137+ print (f"{ self .__class__ . out_f = } { test_files = } " )
133138
134139 # first check that we have the right number of outputs
135140 # self.assertEqual(len(test_files), len(glob.glob(f"{self.out_f}/*.sh"))), "One or more of the example commands didn't produce an output (check the example command is formatted correctly)"
@@ -173,7 +178,8 @@ def test_commands(self):
173178
174179 self .assertTrue (result .wasSuccessful (), "One or more subtests failed" )
175180
176- def _write_command (self , bash_file , test_f ) -> None :
181+ @classmethod
182+ def _write_command (cls , bash_file , test_f ) -> None :
177183 """
178184 Takes a bash file from the examples folder, and writes
179185 a version of it to the test_f folder.
@@ -219,7 +225,7 @@ def _write_command(self, bash_file, test_f) -> None:
219225 else :
220226 output_command = f"{ output_command } inference.num_designs=1"
221227 # replace 'example_outputs' with f'{self.out_f}/example_outputs'
222- output_command = f'{ output_command .split ("example_outputs" )[0 ]} { self .out_f } /example_outputs{ output_command .split ("example_outputs" )[1 ]} '
228+ output_command = f'{ output_command .split ("example_outputs" )[0 ]} { cls .out_f } /example_outputs{ output_command .split ("example_outputs" )[1 ]} '
223229
224230 # write the new command
225231 with open (f"{ test_f } /{ os .path .basename (bash_file )} " , "w" ) as f :
0 commit comments