mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Use context manager instead of plain open (#1211)
Context manager with open closes the files after usage. When the object is already a pathlib.Path i used read_text write_text functions In some cases pathlib.Path.open were used in context manager, it is basically the same as builtin open. Thanks, Konstantin Baikov!
This commit is contained in:
parent
a1bcd2fbe5
commit
8e18c79431
17 changed files with 93 additions and 63 deletions
|
|
@ -8,7 +8,8 @@ def test_publish_heroku_requires_heroku(mock_which):
|
|||
mock_which.return_value = False
|
||||
runner = CliRunner()
|
||||
with runner.isolated_filesystem():
|
||||
open("test.db", "w").write("data")
|
||||
with open("test.db", "w") as fp:
|
||||
fp.write("data")
|
||||
result = runner.invoke(cli.cli, ["publish", "heroku", "test.db"])
|
||||
assert result.exit_code == 1
|
||||
assert "Publishing to Heroku requires heroku" in result.output
|
||||
|
|
@ -22,7 +23,8 @@ def test_publish_heroku_installs_plugin(mock_call, mock_check_output, mock_which
|
|||
mock_check_output.side_effect = lambda s: {"['heroku', 'plugins']": b""}[repr(s)]
|
||||
runner = CliRunner()
|
||||
with runner.isolated_filesystem():
|
||||
open("t.db", "w").write("data")
|
||||
with open("t.db", "w") as fp:
|
||||
fp.write("data")
|
||||
result = runner.invoke(cli.cli, ["publish", "heroku", "t.db"], input="y\n")
|
||||
assert 0 != result.exit_code
|
||||
mock_check_output.assert_has_calls(
|
||||
|
|
@ -54,7 +56,8 @@ def test_publish_heroku(mock_call, mock_check_output, mock_which):
|
|||
}[repr(s)]
|
||||
runner = CliRunner()
|
||||
with runner.isolated_filesystem():
|
||||
open("test.db", "w").write("data")
|
||||
with open("test.db", "w") as fp:
|
||||
fp.write("data")
|
||||
result = runner.invoke(
|
||||
cli.cli, ["publish", "heroku", "test.db", "--tar", "gtar"]
|
||||
)
|
||||
|
|
@ -88,7 +91,8 @@ def test_publish_heroku_plugin_secrets(mock_call, mock_check_output, mock_which)
|
|||
}[repr(s)]
|
||||
runner = CliRunner()
|
||||
with runner.isolated_filesystem():
|
||||
open("test.db", "w").write("data")
|
||||
with open("test.db", "w") as fp:
|
||||
fp.write("data")
|
||||
result = runner.invoke(
|
||||
cli.cli,
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue