Skip to content

Commit

Permalink
test: Simplify confest fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 24, 2024
1 parent 51190aa commit bcdabe2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
40 changes: 14 additions & 26 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,31 @@ def chdir(monkeypatch, tmp_path):
return tmp_path


@pytest.fixture(
params=[
None,
(Config.SECTION, "items_dir", "items"),
"scrapy.cfg",
],
ids=["default", "items_dir", "settings"],
)
def app(request, chdir):
if request.param == "scrapy.cfg":
shutil.copytree(os.path.join(BASEDIR, "fixtures", "filesystem"), chdir, dirs_exist_ok=True)

config = Config()
if isinstance(request.param, tuple):
config.cp.set(*request.param)

return application(config)


@pytest.fixture(
params=[
None,
(("items_dir", "items"), ("jobstorage", "scrapyd.jobstorage.SqliteJobStorage")),
"scrapy.cfg",
],
ids=["default", "config", "settings"],
ids=["default", "custom"],
)
def root(request, chdir):
if request.param == "scrapy.cfg":
def config(request, chdir):
if request.param:
shutil.copytree(os.path.join(BASEDIR, "fixtures", "filesystem"), chdir, dirs_exist_ok=True)

config = Config()
if isinstance(request.param, tuple):
if request.param:
for key, value in request.param:
config.cp.set(Config.SECTION, key, value)
return config

return Root(config, application(config))

@pytest.fixture()
def app(config):
return application(config)


@pytest.fixture()
def root(config, app):
return Root(config, app)


@pytest.fixture()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ def test_render_jobs(txrequest, root_with_egg):
content = root_with_egg.children[b"jobs"].render(txrequest)
expect_headers = {
b"Content-Type": [b"text/html; charset=utf-8"],
b"Content-Length": [b"1744"],
b"Content-Length": [b"1702" if root_with_egg.local_items else b"1744"],
}
if root_with_egg.local_items:
expect_headers[b"Content-Length"] = [b"1702"]

headers = dict(txrequest.responseHeaders.getAllRawHeaders())

Expand All @@ -78,10 +76,8 @@ def test_render_home(txrequest, root_with_egg):
content = root_with_egg.children[b""].render_GET(txrequest)
expect_headers = {
b"Content-Type": [b"text/html; charset=utf-8"],
b"Content-Length": [b"736" if has_settings() else b"714"],
b"Content-Length": [b"773" if root_with_egg.local_items else b"714"],
}
if root_with_egg.local_items:
expect_headers[b"Content-Length"] = [b"751"]

headers = dict(txrequest.responseHeaders.getAllRawHeaders())

Expand All @@ -91,3 +87,7 @@ def test_render_home(txrequest, root_with_egg):
assert b"Items" in content
else:
assert b"Items" not in content
if has_settings():
assert b"localproject" in content
else:
assert b"localproject" not in content

0 comments on commit bcdabe2

Please sign in to comment.