Skip to content

Commit 7a3fefe

Browse files
committed
update test to get external file more flexible
1 parent e0a756b commit 7a3fefe

File tree

5 files changed

+41
-23
lines changed

5 files changed

+41
-23
lines changed

MANIFEST.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
include Makefile
2-
global-exclude *~
3-
global-exclude *.pyc
1+
include Makefile gittaggers.py
42
include tests/*
53
include tests/test-data/*
4+
global-exclude *~
5+
global-exclude *.pyc
6+

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ universal = 1
88

99
[tool:pytest]
1010
testpaths = tests
11+
12+
[aliases]
13+
test=pytest

tests/test_compare.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
import unittest
2+
from .util import get_data
23
from cwltest import CompareFail
34
from cwltest.utils import compare_file, compare
45

56

6-
class TestCompare(unittest.TestCase):
7-
8-
def compare_success(self, expected, actual):
9-
try:
10-
compare(expected, actual)
11-
except CompareFail:
12-
self.fail("Comparison failed unexpectedly")
13-
14-
15-
class TestCompareFile(TestCompare):
7+
class TestCompareFile(unittest.TestCase):
168

179
def test_compare_file(self):
1810
expected = {
1911
"location": "cores.txt",
2012
"size": 2,
2113
"class": "File",
2214
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a"
23-
}
15+
}
2416

2517
actual = {
2618
"basename": "cores.txt",
@@ -48,10 +40,10 @@ def test_compare_contents_success(self):
4840
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
4941
"class": "File",
5042
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
51-
"path": "tests/test-data/cores.txt",
43+
"path": get_data("tests/test-data/cores.txt"),
5244
"size": 2
5345
}
54-
self.compare_success(expected, actual)
46+
compare(expected, actual)
5547

5648
def test_compare_contents_failure(self):
5749
expected = {
@@ -66,7 +58,7 @@ def test_compare_contents_failure(self):
6658
"checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a",
6759
"class": "File",
6860
"location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt",
69-
"path": "tests/test-data/cores.txt",
61+
"path": get_data("tests/test-data/cores.txt"),
7062
"size": 2
7163
}
7264
with self.assertRaises(CompareFail):

tests/util.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from __future__ import absolute_import
2+
import os
3+
4+
from pkg_resources import (Requirement, ResolutionError, # type: ignore
5+
resource_filename)
6+
7+
8+
def get_data(filename):
9+
filename = os.path.normpath(
10+
filename) # normalizing path depending on OS or else it will cause problem when joining path
11+
filepath = None
12+
try:
13+
filepath = resource_filename(
14+
Requirement.parse("cwltest"), filename)
15+
except ResolutionError:
16+
pass
17+
if not filepath or not os.path.isfile(filepath):
18+
filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
19+
return filepath

tox.ini

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
#envlist = py35-lint,py34-lint,py33-lint,py27-lint,py35-unit,py34-unit,py33-unit,py27-unit
3-
envlist = py27-lint, py27-unit, py35-mypy{2,3}
3+
envlist = py27-lint, py{27,33,34,35}-unit, py35-mypy{2,3}
44
skipsdist = True
55

66
[travis]
@@ -12,7 +12,9 @@ python =
1212
3.5: py35-mypy{2,3}
1313

1414
[testenv]
15-
deps = -rrequirements.txt
15+
deps =
16+
pytest
17+
-rrequirements.txt
1618

1719
[testenv:py35-mypy2]
1820
commands = make mypy2
@@ -49,13 +51,14 @@ whitelist_externals = flake8
4951
deps = flake8
5052

5153
[testenv:py35-unit]
52-
commands = python setup.py test
54+
commands = pytest {posargs} # substitute with tox' positional arguments
5355

5456
[testenv:py34-unit]
55-
commands = python setup.py test
57+
commands = pytest {posargs} # substitute with tox' positional arguments
5658

5759
[testenv:py33-unit]
58-
commands = python setup.py test
60+
commands = pytest {posargs} # substitute with tox' positional arguments
5961

6062
[testenv:py27-unit]
61-
commands = python setup.py test
63+
commands = pytest {posargs} # substitute with tox' positional arguments
64+

0 commit comments

Comments
 (0)