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
|
|
@ -32,7 +32,8 @@ def test_package(mock_call, mock_which):
|
|||
capture = CaptureDockerfile()
|
||||
mock_call.side_effect = capture
|
||||
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, ["package", "test.db", "--secret", "sekrit"])
|
||||
assert 0 == result.exit_code
|
||||
mock_call.assert_has_calls([mock.call(["docker", "build", "."])])
|
||||
|
|
@ -47,7 +48,8 @@ def test_package_with_port(mock_call, mock_which):
|
|||
mock_call.side_effect = capture
|
||||
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, ["package", "test.db", "-p", "8080", "--secret", "sekrit"]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue