Skip to content

Commit 47f07a4

Browse files
committed
paramaterize (un)hidden file tests
1 parent 02579a7 commit 47f07a4

File tree

2 files changed

+40
-60
lines changed

2 files changed

+40
-60
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
pip check
4848
- name: Run the tests
4949
run: |
50-
pytest -vv --cov=nbformat
50+
pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
5151
- name: Install the Python dependencies for the examples
5252
run: |
5353
cd examples/simple && pip install -e .

tests/test_files.py

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import pytest
3+
from pathlib import Path
34
import tornado
45

56
from .utils import expected_http_error
@@ -10,68 +11,47 @@
1011
new_output)
1112

1213

13-
async def test_hidden_files(jp_fetch, jp_serverapp, jp_root_dir):
14-
not_hidden = [
15-
u'å b',
16-
u'å b/ç. d',
17-
]
18-
hidden = [
19-
u'.å b',
20-
u'å b/.ç d',
21-
]
22-
dirs = not_hidden + hidden
23-
24-
for d in dirs:
25-
path = jp_root_dir / d.replace('/', os.sep)
26-
path.mkdir(parents=True, exist_ok=True)
27-
path.joinpath('foo').write_text('foo')
28-
path.joinpath('.foo').write_text('.foo')
29-
30-
for d in not_hidden:
31-
r = await jp_fetch(
32-
'files', d, 'foo',
33-
method='GET'
34-
)
35-
assert r.body.decode() == 'foo'
36-
37-
with pytest.raises(tornado.httpclient.HTTPClientError) as e:
38-
await jp_fetch(
39-
'files', d, '.foo',
40-
method='GET'
41-
)
42-
assert expected_http_error(e, 404)
43-
44-
for d in hidden:
45-
for foo in ('foo', '.foo'):
46-
with pytest.raises(tornado.httpclient.HTTPClientError) as e:
47-
await jp_fetch(
48-
'files', d, foo,
49-
method='GET'
50-
)
51-
assert expected_http_error(e, 404)
14+
@pytest.fixture(params=[
15+
[False, ['å b']],
16+
[False, ['å b', 'ç. d']],
17+
[True, ['.å b']],
18+
[True, ['å b', '.ç d']]
19+
])
20+
def maybe_hidden(request):
21+
return request.param
22+
23+
24+
async def fetch_expect_200(jp_fetch, *path_parts):
25+
r = await jp_fetch('files', *path_parts, method='GET')
26+
assert (r.body.decode() == path_parts[-1]), path_parts
27+
28+
29+
async def fetch_expect_404(jp_fetch, *path_parts):
30+
with pytest.raises(tornado.httpclient.HTTPClientError) as e:
31+
await jp_fetch('files', *path_parts, method='GET')
32+
assert expected_http_error(e, 404), path_parts
33+
34+
35+
async def test_hidden_files(jp_fetch, jp_serverapp, jp_root_dir, maybe_hidden):
36+
is_hidden, path_parts = maybe_hidden
37+
path = Path(jp_root_dir, *path_parts)
38+
path.mkdir(parents=True, exist_ok=True)
39+
40+
foos = ['foo', '.foo']
41+
for foo in foos:
42+
(path / foo).write_text(foo)
43+
44+
if is_hidden:
45+
for foo in foos:
46+
await fetch_expect_404(jp_fetch, *path_parts, foo)
47+
else:
48+
await fetch_expect_404(jp_fetch, *path_parts, '.foo')
49+
await fetch_expect_200(jp_fetch, *path_parts, 'foo')
5250

5351
jp_serverapp.contents_manager.allow_hidden = True
5452

55-
for d in not_hidden:
56-
r = await jp_fetch(
57-
'files', d, 'foo',
58-
method='GET'
59-
)
60-
assert r.body.decode() == 'foo'
61-
62-
r = await jp_fetch(
63-
'files', d, '.foo',
64-
method='GET'
65-
)
66-
assert r.body.decode() == '.foo'
67-
68-
for d in hidden:
69-
for foo in ('foo', '.foo'):
70-
r = await jp_fetch(
71-
'files', d, foo,
72-
method='GET'
73-
)
74-
assert r.body.decode() == foo
53+
for foo in foos:
54+
await fetch_expect_200(jp_fetch, *path_parts, foo)
7555

7656

7757
async def test_contents_manager(jp_fetch, jp_serverapp, jp_root_dir):

0 commit comments

Comments
 (0)