Skip to content

Commit b115386

Browse files
committed
maintenance: remove unittest from test_pathmapper
1 parent 027be5d commit b115386

File tree

1 file changed

+80
-86
lines changed

1 file changed

+80
-86
lines changed

tests/test_pathmapper.py

Lines changed: 80 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,90 @@
1-
from __future__ import absolute_import
2-
3-
import unittest
1+
import pytest
42

53
from cwltool.pathmapper import PathMapper, normalizeFilesDirs
64

75

8-
class TestPathMapper(unittest.TestCase):
9-
def test_subclass(self):
10-
class SubPathMapper(PathMapper):
11-
def __init__(self, referenced_files, basedir, stagedir, new):
12-
super(SubPathMapper, self).__init__(referenced_files, basedir, stagedir)
13-
self.new = new
14-
15-
a = SubPathMapper([], '', '', "new")
16-
self.assertTrue(a.new, "new")
17-
18-
def test_strip_trailing(self):
19-
d = {
20-
"class": "Directory",
21-
"location": "/foo/bar/"
22-
}
23-
normalizeFilesDirs(d)
24-
self.assertEqual(
25-
{
26-
"class": "Directory",
27-
"location": "/foo/bar",
28-
"basename": "bar"
29-
},
30-
d)
31-
32-
def test_basename_field_generation(self):
33-
base_file = {
34-
"class": "File",
35-
"location": "/foo/"
36-
}
37-
# (filename, expected: (nameroot, nameext))
38-
testdata = [
39-
("foo.bar", ("foo", ".bar")),
40-
("foo", ("foo", '')),
41-
(".foo", (".foo", '')),
42-
("foo.", ("foo", '.')),
43-
("foo.bar.baz", ("foo.bar", ".baz"))
44-
]
6+
def test_subclass():
7+
class SubPathMapper(PathMapper):
8+
def __init__(self, referenced_files, basedir, stagedir, new):
9+
super(SubPathMapper, self).__init__(referenced_files, basedir, stagedir)
10+
self.new = new
4511

46-
for filename, (nameroot, nameext) in testdata:
47-
file = dict(base_file)
48-
file["location"] = file["location"] + filename
12+
pathmap = SubPathMapper([], '', '', 'new')
13+
assert pathmap.new is not None, 'new'
4914

50-
expected = dict(file)
51-
expected["basename"] = filename
52-
expected["nameroot"] = nameroot
53-
expected["nameext"] = nameext
15+
normalization_parameters = [
16+
('strip trailing slashes',
17+
{'class': 'Directory',
18+
'location': '/foo/bar/'
19+
},
20+
{'class': 'Directory',
21+
'location': '/foo/bar',
22+
'basename': 'bar'
23+
}
24+
),
25+
('file',
26+
{'class': 'File',
27+
'location': 'file1.txt'
28+
},
29+
{'class': 'File',
30+
'location': 'file1.txt',
31+
'basename': 'file1.txt',
32+
'nameext': '.txt',
33+
'nameroot': 'file1'
34+
}
35+
),
36+
('file with local uri',
37+
{'class': 'File',
38+
'location': 'file:///foo/file1.txt'
39+
},
40+
{'class': 'File',
41+
'location': 'file:///foo/file1.txt',
42+
'basename': 'file1.txt',
43+
'nameext': '.txt',
44+
'nameroot': 'file1'
45+
}
46+
),
47+
('file with http url',
48+
{'class': 'File',
49+
'location': 'http://example.com/file1.txt'
50+
},
51+
{'class': 'File',
52+
'location': 'http://example.com/file1.txt',
53+
'basename': 'file1.txt',
54+
'nameext': '.txt',
55+
'nameroot': 'file1'
56+
}
57+
)
58+
]
5459

55-
normalizeFilesDirs(file)
56-
self.assertEqual(file, expected)
60+
@pytest.mark.parametrize('name,file_dir,expected', normalization_parameters)
61+
def test_normalizeFilesDirs(name, file_dir, expected):
62+
normalizeFilesDirs(file_dir)
63+
assert file_dir == expected, name
5764

58-
def test_normalizeFilesDirs(self):
59-
n = {
60-
"class": "File",
61-
"location": "file1.txt"
62-
}
63-
normalizeFilesDirs(n)
64-
self.assertEqual(n, {
65-
"class": "File",
66-
"location": "file1.txt",
67-
'basename': 'file1.txt',
68-
'nameext': '.txt',
69-
'nameroot': 'file1'
70-
})
65+
# (filename, expected: (nameroot, nameext))
66+
basename_generation_parameters = [
67+
('foo.bar', ('foo', '.bar')),
68+
('foo', ('foo', '')),
69+
('.foo', ('.foo', '')),
70+
('foo.', ('foo', '.')),
71+
('foo.bar.baz', ('foo.bar', '.baz'))
72+
]
73+
@pytest.mark.parametrize('filename,expected', basename_generation_parameters)
74+
def test_basename_field_generation(filename, expected):
75+
nameroot, nameext = expected
76+
expected = {
77+
'class': 'File',
78+
'location': '/foo/' + filename,
79+
'basename': filename,
80+
'nameroot': nameroot,
81+
'nameext': nameext
82+
}
7183

72-
n = {
73-
"class": "File",
74-
"location": "file:///foo/file1.txt"
75-
}
76-
normalizeFilesDirs(n)
77-
self.assertEqual(n, {
78-
"class": "File",
79-
"location": "file:///foo/file1.txt",
80-
'basename': 'file1.txt',
81-
'nameext': '.txt',
82-
'nameroot': 'file1'
83-
})
84+
file = {
85+
'class': 'File',
86+
'location': '/foo/' + filename
87+
}
8488

85-
n = {
86-
"class": "File",
87-
"location": "http://example.com/file1.txt"
88-
}
89-
normalizeFilesDirs(n)
90-
self.assertEqual(n, {
91-
"class": "File",
92-
"location": "http://example.com/file1.txt",
93-
'basename': 'file1.txt',
94-
'nameext': '.txt',
95-
'nameroot': 'file1'
96-
})
89+
normalizeFilesDirs(file)
90+
assert file == expected

0 commit comments

Comments
 (0)