Skip to content

Commit

Permalink
fix python3 string/bytes error when using --printLogs (#3005)
Browse files Browse the repository at this point in the history
* add test for issue #3004

Test to reproduce `TypeError: can only concatenate str (not "bytes") to str` error.

* printJobLog convert bytes to utf-8

Fix for problem raised in issue #3004

* improve printJobLog test method

* remove unused mock_open import
  • Loading branch information
johnbradley authored Mar 11, 2020
1 parent b058ff5 commit 2bd7920
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/toil/test/cwl/alwaysfails.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env cwl-runner
# Command that will always fail
cwlVersion: v1.0
class: CommandLineTool
baseCommand: invalidcommand
inputs:
message:
type: string
inputBinding:
position: 1
outputs: []
17 changes: 17 additions & 0 deletions src/toil/test/utils/utilsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from toil.common import Toil, Config
from toil.provisioners import clusterFactory
from toil.version import python
from mock import patch

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -387,6 +388,22 @@ def testGetStatusSuccessfulCWLWF(self):
wf.wait()
self.check_status('COMPLETED', status_fn=ToilStatus.getStatus)

@needs_cwl
@needs_docker
@patch('builtins.print')
def testPrintJobLog(self, mock_print):
"""Test that ToilStatus.printJobLog() reads the log from a failed command without error."""
# Run a workflow that will always fail
cmd = ['toil-cwl-runner', '--jobStore', self.toilDir, '--clean=never',
'src/toil/test/cwl/alwaysfails.cwl', '--message', 'Testing']
wf = subprocess.Popen(cmd)
wf.wait()
# print log and check output
status = ToilStatus(self.toilDir)
status.printJobLog()
args, kwargs = mock_print.call_args
self.assertIn('LOG_FILE_OF_JOB', args[0])


def printUnicodeCharacter():
# We want to get a unicode character to stdout but we can't print it directly because of
Expand Down
2 changes: 1 addition & 1 deletion src/toil/utils/toilStatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def printJobLog(self):
if job.logJobStoreFileID is not None:
msg = "LOG_FILE_OF_JOB:%s LOG: =======>\n" % job
with job.getLogFileHandle(self.jobStore) as fH:
msg += fH.read()
msg += fH.read().decode('utf-8')
msg += "<========="
else:
msg = "LOG_FILE_OF_JOB:%s LOG: Job has no log file" % job
Expand Down

0 comments on commit 2bd7920

Please sign in to comment.