@@ -31,6 +31,9 @@ def tearDown(self):
3131 def test_main (self ):
3232 command = ["smart_worker.py" , self .command_manager ._commands_filename , self .logs_dir ]
3333 assert_equal (call (command ), 0 )
34+ # Simulate a resume, i.e. re-run the command, the output/error should be concatenated.
35+ self .command_manager .set_commands_to_run (self .commands )
36+ assert_equal (call (command ), 0 )
3437
3538 # Check output logs
3639 filenames = os .listdir (self .logs_dir )
@@ -41,13 +44,22 @@ def test_main(self):
4144 uid = os .path .splitext (os .path .basename (log_filename ))[0 ]
4245 executed_command = self .commands [self .commands_uid .index (uid )]
4346
44- # First line is the executed command in comment
45- header = logfile .readline ().strip ()
46- assert_equal (header , "# " + executed_command )
47+ # Since the command was run twice.
48+ for _ in range (2 ):
49+ # First line is the datetime of the executed command in comment.
50+ line = logfile .readline ().strip ()
51+ assert_true (time .strftime ("## %Y-%m-%d %H:%M:" ) in line ) # Don't check seconds.
52+
53+ # Second line is the executed command in comment.
54+ line = logfile .readline ().strip ()
55+ assert_equal (line , "# " + executed_command )
4756
48- # Next should be the command's output
49- output = logfile .readline ().strip ()
50- assert_equal (output , executed_command [- 1 ]) # We know those are 'echo' of a digit
57+ # Next should be the command's output
58+ line = logfile .readline ().strip ()
59+ assert_equal (line , executed_command [- 1 ]) # We know those are 'echo' of a digit
60+
61+ # Empty line
62+ assert_equal (logfile .readline ().strip (), "" )
5163
5264 # Log should be empty now
5365 assert_equal ("" , logfile .read ())
@@ -60,9 +72,18 @@ def test_main(self):
6072 uid = os .path .splitext (os .path .basename (log_filename ))[0 ]
6173 executed_command = self .commands [self .commands_uid .index (uid )]
6274
63- # First line is the executed command in comment
64- header = logfile .readline ().strip ()
65- assert_equal (header , "# " + executed_command )
75+ # Since the command was run twice.
76+ for _ in range (2 ):
77+ # First line is the datetime of the executed command in comment.
78+ line = logfile .readline ().strip ()
79+ assert_true (time .strftime ("## %Y-%m-%d %H:%M:" ) in line ) # Don't check seconds.
80+
81+ # Second line is the executed command in comment.
82+ line = logfile .readline ().strip ()
83+ assert_equal (line , "# " + executed_command )
84+
85+ # Empty line
86+ assert_equal (logfile .readline ().strip (), "" )
6687
6788 # Log should be empty now
6889 assert_equal ("" , logfile .read ())
0 commit comments