Skip to content

Commit 9565ad5

Browse files
committed
Formatting changes
1 parent 1e4224c commit 9565ad5

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

test/test_wesclient_utils.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
import unittest
22
import os
3+
import sys
4+
5+
pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) # noqa
6+
sys.path.insert(0, pkg_root) # noqa
7+
38
from wes_client.util import wf_info
49

10+
511
class WorkflowInfoTest(unittest.TestCase):
612

7-
local = {'cwl': 'file://' + os.path.join(os.getcwd() + '/workflow-service/testdata/md5sum.cwl'),
8-
'wdl': 'file://' + os.path.join(os.getcwd() + '/workflow-service/testdata/md5sum.wdl'),
9-
'py': 'file://' + os.path.join(os.getcwd() + '/workflow-service/test/test_integration.py'),
10-
'unsupported':'fake.txt'}
13+
local = {'cwl': 'file://' + os.path.join(os.getcwd() + '/testdata/md5sum.cwl'),
14+
'wdl': 'file://' + os.path.join(os.getcwd() + '/testdata/md5sum.wdl'),
15+
'py': 'file://' + os.path.join(os.getcwd() + '/test/test_integration.py'),
16+
'unsupported': 'fake.txt'}
1117

12-
remote = {'cwl':'https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/md5sum.cwl',
13-
'wdl':'https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/md5sum.wdl',
18+
remote = {'cwl': 'https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/md5sum.cwl',
19+
'wdl': 'https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/md5sum.wdl',
1420
'py': 'https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/test/test_integration.py',
1521
'unsupported': 'gs://topmed_workflow_testing/topmed_aligner/small_test_files_sbg/example_human_known_snp.py', # TODO: find real external file of .py, .cwl, .wdl
16-
'unreachable':'https://fake.py'}
22+
'unreachable': 'https://fake.py'}
1723

18-
expected = {'cwl':('v1.0', 'CWL'),
19-
'wdl':('draft-2','WDL'),
24+
expected = {'cwl': ('v1.0', 'CWL'),
25+
'wdl': ('draft-2','WDL'),
2026
'py': ('2.7','PY'),
21-
'pyWithPrefix' : ('2.7','PY')}
27+
'pyWithPrefix': ('2.7','PY')}
2228

2329
def testSupportedFormatChecking(self):
24-
"""Check that non-wdl, -python, -cwl files are rejected."""
30+
"""
31+
Check that non-wdl, -python, -cwl files are rejected.
32+
33+
This test is run only on local files to avoid downloading and removing a new file.
34+
"""
2535

26-
# The choice to run this on local files prevents the irrelevant steps of creating and removing a new file.
2736
for format, location in self.local.items():
2837
if format != 'unsupported':
2938
# Tests the behavior after receiving supported file types with and without the 'file://' prefix
@@ -37,17 +46,23 @@ def testSupportedFormatChecking(self):
3746

3847

3948
def testFileLocationChecking(self):
40-
"""Check that the function rejects unsupported file locations."""
41-
# This needs to be run on remote files to get to the location checking step.
49+
"""
50+
Check that the function rejects unsupported file locations.
51+
52+
This test needs to be run on remote files to test the location checking functionality of wf_info().
53+
"""
54+
4255
for format, location in self.remote.items():
4356
if format == 'unsupported':
44-
# Tests behavior after receiving a non-existant file.
57+
# Tests behavior after receiving a file hosted at an unsupported location.
4558
with self.assertRaises(NotImplementedError):
4659
wf_info(location)
60+
4761
elif format == 'unreachable':
48-
# Tests behavior after receiving a non-existant file.
62+
# Tests behavior after receiving a non-existent file.
4963
with self.assertRaises(IOError):
5064
wf_info(location)
65+
5166
else:
5267
self.assertEquals(wf_info(location), self.expected[format])
5368
self.assertFalse(os.path.isfile(os.path.join(os.getcwd(), 'fetchedFromRemote.' + format)))

wes_client/util.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _getVersion(extension, workflow_file):
2727
return 'draft-2'
2828

2929

30-
def wf_info(workflow_file):
30+
def wf_info(workflow_path):
3131
"""
3232
Returns the version of the file and the file extension.
3333
@@ -37,21 +37,22 @@ def wf_info(workflow_file):
3737
"""
3838

3939
supportedFormats = ['py', 'wdl', 'cwl']
40-
fileType = workflow_file.lower().split('.')[-1] # Grab the file extension
41-
workflow_file = workflow_file if ':' in workflow_file else 'file://' + workflow_file
40+
fileType = workflow_path.lower().split('.')[-1] # Grab the file extension
41+
workflow_path = workflow_path if ':' in workflow_path else 'file://' + workflow_path
4242

4343
if fileType in supportedFormats:
44-
if workflow_file.startswith('file://'):
45-
version = _getVersion(fileType, workflow_file[7:])
46-
elif workflow_file.startswith('https://') or workflow_file.startswith('http://'): # If file not local go fetch it.
47-
html = urlopen(workflow_file).read()
44+
if workflow_path.startswith('file://'):
45+
version = _getVersion(fileType, workflow_path[7:])
46+
elif workflow_path.startswith('https://') or workflow_path.startswith('http://'):
47+
# If file not local go fetch it.
48+
html = urlopen(workflow_path).read()
4849
localLoc = os.path.join(os.getcwd(), 'fetchedFromRemote.' + fileType)
4950
with open(localLoc, 'w') as f:
5051
f.write(html)
51-
version = wf_info('file://' + localLoc)[0] # Dont take the filetype here.
52+
version = wf_info('file://' + localLoc)[0] # Don't take the fileType here, found it above.
5253
os.remove(localLoc) # TODO: Find a way to avoid recreating file before version determination.
5354
else:
54-
raise NotImplementedError('Unsupported workflow file location: {}. Must be local or HTTP(S).'.format(workflow_file))
55+
raise NotImplementedError('Unsupported workflow file location: {}. Must be local or HTTP(S).'.format(workflow_path))
5556
else:
5657
raise TypeError('Unsupported workflow type: .{}. Must be {}.'.format(fileType, '.py, .cwl, or .wdl'))
5758
return version, fileType.upper()

0 commit comments

Comments
 (0)