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:
Konstantin Baikov 2021-03-11 17:15:49 +01:00 committed by GitHub
commit 8e18c79431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 93 additions and 63 deletions

View file

@ -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,
[