Skip to content

Commit

Permalink
more python2/python3 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Trimble committed Sep 5, 2019
1 parent 721aaf2 commit 4909cd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
23 changes: 15 additions & 8 deletions CWL/Tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test(self):
# execute tool
session = subprocess.Popen([cwlTool, '--outdir', outputDir, docker, toolDir + tool, job], stdin=None, stdout=PIPE, stderr=PIPE, shell=False)
stdout, stderr = session.communicate()

stdout = stdout.decode("utf-8") # have to explicitly decode bytes since python2 subprocess.Popen does not take encoding
stderr = stderr.decode("utf-8")
if stderr and debug:
print('ERROR:')
print(stderr)
Expand All @@ -87,15 +88,16 @@ def test(self):
print('Baseline:')
print(baseline)
print('Output:' + stdout)
self.assertTrue(cmp_cwl_receipts(baseline, stdout), msg=" ".join(['cwl-runner', '--outdir ' + outputDir, docker, toolDir + tool, job, "\n", stderr]))
testresult = cmp_cwl_receipts(baseline, stdout)
self.assertTrue(testresult, msg=" ".join(['cwl-runner', '--outdir ' + outputDir, docker, toolDir + tool, job, "\n", stderr]))

return test
return testresult

def cmp_cwl_receipts(json_a, json_b):

identical = 1
assert type(json_a) is str
assert type(json_b) is str
assert type(json_a) is str or type(json_a) is unicode
assert type(json_b) is str or type(json_b) is unicode

try:
a = json.loads(json_a)
Expand All @@ -104,7 +106,7 @@ def cmp_cwl_receipts(json_a, json_b):
sys.stderr.write("Can't parse json strings ... " + repr(e) + " ... ")
identical = 0
return
for k, v in a.iteritems():
for k, v in a.items():
if 'format' in v:
if debug:
sys.stderr.write('Found \'format\' key.\n')
Expand Down Expand Up @@ -166,6 +168,8 @@ def setUp(self):

session = subprocess.Popen([cwlTool, '--version'], stdout=PIPE, stderr=PIPE)
stdout, stderr = session.communicate()
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")

if stderr:
raise Exception("Error "+str(stderr))
Expand Down Expand Up @@ -193,7 +197,7 @@ def tearDown(self):
pass

def test_cwl_drisee(self):
"""Is receipt for drisee identical to baseline receipt"""
"""Is receipt for drisee identical to baseline receipt"""


if debug:
Expand All @@ -204,6 +208,8 @@ def test_cwl_drisee(self):

session = subprocess.Popen([cwlTool, '--outdir', outputDir, docker, toolDir + 'drisee.tool.cwl', toolDir + 'drisee.job.yaml'], stdin=None, stdout=PIPE, stderr=PIPE, shell=False)
stdout, stderr = session.communicate()
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")

if stderr and debug:
print('ERROR:')
Expand Down Expand Up @@ -238,6 +244,8 @@ def test_cwl_kmer_tool(self):

session = subprocess.Popen([cwlTool, '--outdir', outputDir, docker, toolDir + 'kmer-tool.tool.cwl', toolDir + 'kmer-tool.job.yaml'], stdin=None, stdout=PIPE, stderr=PIPE, shell=False)
stdout, stderr = session.communicate()
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")

if stderr and debug:
print('ERROR:')
Expand Down Expand Up @@ -270,7 +278,6 @@ class TestCwlTool(unittest.TestCase): pass
m = re.split("/", f)
tool = m.pop()
[name, cwl_type, suffix] = tool.split(".")

# test tool exists - should be always true for obvious reasons
test_name = 'test_cwl_tool_%s' % name
test = generate_check_exists_tool(tool, name, f)
Expand Down
6 changes: 5 additions & 1 deletion CWL/Tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def test(self):
# execute tool
session = subprocess.Popen([cwlTool, '--outdir', outputDir, docker, workflowDir + tool, job], stdin=None, stdout=PIPE, stderr=PIPE, shell=False)
stdout, stderr = session.communicate()
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")
setattr(self, name, stdout)

success = re.search("Final process status is success", stderr)
Expand Down Expand Up @@ -123,7 +125,7 @@ def cmp_cwl_receipts(json_a, json_b):
sys.stderr.write("Can't parse json strings ... " + repr(e) + " ... " + "a=" + str(type(json_a)) + " b=" + str(type(json_b)) + " ...")

try:
for k, v in a.iteritems():
for k, v in a.items():
if 'format' in v:
if debug:
sys.stderr.write('Found \'format\' key.\n')
Expand Down Expand Up @@ -160,6 +162,8 @@ def setUp(self):

session = subprocess.Popen([cwlTool, '--version'], stdout=PIPE, stderr=PIPE)
stdout, stderr = session.communicate()
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")

if stderr:
raise Exception("Error "+str(stderr))
Expand Down

0 comments on commit 4909cd7

Please sign in to comment.