Replace all uses of runner.isolated_filesystem, refs #1406

This commit is contained in:
Simon Willison 2021-07-31 11:49:08 -07:00
commit ff253f5242
3 changed files with 284 additions and 292 deletions

View file

@ -1,6 +1,7 @@
from click.testing import CliRunner
from datasette import cli
from unittest import mock
import os
import pathlib
import pytest
@ -32,12 +33,12 @@ def test_package(mock_call, mock_which, tmp_path_factory):
runner = CliRunner()
capture = CaptureDockerfile()
mock_call.side_effect = capture
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(cli.cli, ["package", "test.db", "--secret", "sekrit"])
assert 0 == result.exit_code
mock_call.assert_has_calls([mock.call(["docker", "build", "."])])
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(cli.cli, ["package", "test.db", "--secret", "sekrit"])
assert 0 == result.exit_code
mock_call.assert_has_calls([mock.call(["docker", "build", "."])])
assert EXPECTED_DOCKERFILE.format(port=8001) == capture.captured
@ -48,11 +49,11 @@ def test_package_with_port(mock_call, mock_which, tmp_path_factory):
capture = CaptureDockerfile()
mock_call.side_effect = capture
runner = CliRunner()
with runner.isolated_filesystem(tmp_path_factory.mktemp("runner")):
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(
cli.cli, ["package", "test.db", "-p", "8080", "--secret", "sekrit"]
)
assert 0 == result.exit_code
os.chdir(tmp_path_factory.mktemp("runner"))
with open("test.db", "w") as fp:
fp.write("data")
result = runner.invoke(
cli.cli, ["package", "test.db", "-p", "8080", "--secret", "sekrit"]
)
assert 0 == result.exit_code
assert EXPECTED_DOCKERFILE.format(port=8080) == capture.captured