|
4 | 4 | import os
|
5 | 5 | import logging
|
6 | 6 | import subprocess
|
| 7 | +import sys |
7 | 8 |
|
8 |
| -from wes_client.util import expand_globs |
| 9 | +pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) # noqa |
| 10 | +sys.path.insert(0, pkg_root) # noqa |
| 11 | + |
| 12 | +from wes_client.util import expand_globs, wf_info |
9 | 13 |
|
10 | 14 | logging.basicConfig(level=logging.INFO)
|
11 | 15 |
|
@@ -35,5 +39,63 @@ def test_expand_globs(self):
|
35 | 39 | assert set(files) == glob_files, '\n' + str(set(files)) + '\n' + str(glob_files)
|
36 | 40 |
|
37 | 41 |
|
| 42 | +class WorkflowInfoTest(unittest.TestCase): |
| 43 | + |
| 44 | + local = {'cwl': 'file://' + os.path.join(os.getcwd() + '/testdata/md5sum.cwl'), |
| 45 | + 'wdl': 'file://' + os.path.join(os.getcwd() + '/testdata/md5sum.wdl'), |
| 46 | + 'py': 'file://' + os.path.join(os.getcwd() + '/test/test_integration.py'), |
| 47 | + 'unsupported': 'fake.txt'} |
| 48 | + |
| 49 | + remote = {'cwl': 'https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/md5sum.cwl', |
| 50 | + 'wdl': 'https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/md5sum.wdl', |
| 51 | + 'py': 'https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/test/test_integration.py', |
| 52 | + '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 |
| 53 | + 'unreachable': 'https://fake.py'} |
| 54 | + |
| 55 | + expected = {'cwl': ('v1.0', 'CWL'), |
| 56 | + 'wdl': ('draft-2', 'WDL'), |
| 57 | + 'py': ('2.7', 'PY'), |
| 58 | + 'pyWithPrefix': ('2.7', 'PY')} |
| 59 | + |
| 60 | + def testSupportedFormatChecking(self): |
| 61 | + """ |
| 62 | + Check that non-wdl, -python, -cwl files are rejected. |
| 63 | +
|
| 64 | + This test is run only on local files to avoid downloading and removing a new file. |
| 65 | + """ |
| 66 | + |
| 67 | + for format, location in self.local.items(): |
| 68 | + if format != 'unsupported': |
| 69 | + # Tests the behavior after receiving supported file types with and without the 'file://' prefix |
| 70 | + self.assertEquals(wf_info(location), self.expected[format]) |
| 71 | + self.assertEquals(wf_info(location[7:]), self.expected[format]) |
| 72 | + |
| 73 | + else: |
| 74 | + # Tests behavior after recieveing a non supported file type. |
| 75 | + with self.assertRaises(TypeError): |
| 76 | + wf_info(location) |
| 77 | + |
| 78 | + def testFileLocationChecking(self): |
| 79 | + """ |
| 80 | + Check that the function rejects unsupported file locations. |
| 81 | +
|
| 82 | + This test needs to be run on remote files to test the location checking functionality of wf_info(). |
| 83 | + """ |
| 84 | + |
| 85 | + for format, location in self.remote.items(): |
| 86 | + if format == 'unsupported': |
| 87 | + # Tests behavior after receiving a file hosted at an unsupported location. |
| 88 | + with self.assertRaises(NotImplementedError): |
| 89 | + wf_info(location) |
| 90 | + |
| 91 | + elif format == 'unreachable': |
| 92 | + # Tests behavior after receiving a non-existent file. |
| 93 | + with self.assertRaises(IOError): |
| 94 | + wf_info(location) |
| 95 | + |
| 96 | + else: |
| 97 | + self.assertEquals(wf_info(location), self.expected[format]) |
| 98 | + self.assertFalse(os.path.isfile(os.path.join(os.getcwd(), 'fetchedFromRemote.' + format))) |
| 99 | + |
38 | 100 | if __name__ == '__main__':
|
39 | 101 | unittest.main() # run all tests
|
0 commit comments