Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit d4b5168

Browse files
committed
Move get_data from tests to cwltool
1 parent c4a6f16 commit d4b5168

14 files changed

+34
-45
lines changed

cwltool/utils.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from __future__ import absolute_import
22

3-
# no imports from cwltool allowed
4-
53
import os
64
import shutil
75
import stat
6+
from typing import Any, Callable, Dict, List, Text, Tuple, Union
7+
88
import six
9-
from six.moves import urllib
10-
from six.moves import zip_longest
11-
from typing import Any,Callable, Dict, List, Tuple, Text, Union
9+
from pkg_resources import (Requirement, ResolutionError, # type: ignore
10+
resource_filename)
11+
12+
from six.moves import urllib, zip_longest
13+
14+
# no imports from cwltool allowed
1215

1316
windows_default_container_id = "frolvlad/alpine-bash"
1417

@@ -172,3 +175,17 @@ def bytes2str_in_dicts(a):
172175

173176
# simply return elements itself
174177
return a
178+
179+
def get_data(filename):
180+
# type: (Text) -> Text
181+
filename = os.path.normpath(
182+
filename) # normalizing path depending on OS or else it will cause problem when joining path
183+
filepath = None
184+
try:
185+
filepath = resource_filename(
186+
Requirement.parse("cwltool"), filename)
187+
except ResolutionError:
188+
pass
189+
if not filepath or not os.path.isfile(filepath):
190+
filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
191+
return filepath

tests/test_check.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import cwltool.workflow
99
import pytest
1010
from cwltool.main import main
11-
from cwltool.utils import onWindows
12-
13-
from .util import get_data
14-
11+
from cwltool.utils import onWindows, get_data
1512

1613
class TestCheck(unittest.TestCase):
1714
@pytest.mark.skipif(onWindows(),

tests/test_cwl_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from cwltool.main import main
55

6-
from .util import get_data
6+
from cwltool.utils import get_data
77

88
class CWL_Version_Checks(unittest.TestCase):
99
# no cwlVersion in the workflow

tests/test_default_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from cwltool.load_tool import fetch_document, validate_document
3-
from .util import get_data
3+
from cwltool.utils import get_data
44
from schema_salad.ref_resolver import Loader
55

66
class TestDefaultPath(unittest.TestCase):

tests/test_examples.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from io import StringIO
99

1010
from cwltool.errors import WorkflowException
11-
from cwltool.utils import onWindows
11+
from cwltool.utils import onWindows, get_data
1212

1313
try:
1414
reload
@@ -26,7 +26,6 @@
2626
import schema_salad.validate
2727
from cwltool.main import main
2828

29-
from .util import get_data
3029

3130
sys.argv = ['']
3231

tests/test_ext.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import cwltool.process
1111
import cwltool.workflow
1212
from cwltool.main import main
13-
from cwltool.utils import onWindows
14-
from .util import get_data
13+
from cwltool.utils import onWindows, get_data
1514

1615

1716
@pytest.mark.skipif(onWindows(),

tests/test_iwdr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import cwltool
44
import cwltool.factory
5-
from .util import get_data
5+
from cwltool.utils import get_data
66

77

88
class TestInitialWorkDir(unittest.TestCase):

tests/test_js_sandbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# we should modify the subprocess imported from cwltool.sandboxjs
1010
from cwltool.sandboxjs import (check_js_threshold_version,
1111
subprocess)
12-
from .util import get_data
12+
from cwltool.utils import get_data
1313

1414

1515
class Javascript_Sanity_Checks(unittest.TestCase):

tests/test_override.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from cwltool.utils import onWindows
1212
from six import StringIO
1313

14-
from .util import get_data
14+
from cwltool.utils import get_data
1515

1616

1717
class TestOverride(unittest.TestCase):

tests/test_pack.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
from cwltool.load_tool import fetch_document, validate_document
1818
from cwltool.main import makeRelative, main, print_pack
1919
from cwltool.pathmapper import adjustDirObjs, adjustFileObjs
20-
from cwltool.utils import onWindows
21-
from .util import get_data
20+
from cwltool.utils import onWindows, get_data
2221

2322

2423
class TestPack(unittest.TestCase):

0 commit comments

Comments
 (0)