mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-27 20:34:12 +02:00
Use context managers for file writes in tests
This removes the need to explicitly close files and avoids accidental unclosed files
This commit is contained in:
parent
17eb8184d2
commit
2fc480adae
1 changed files with 8 additions and 10 deletions
|
|
@ -2082,11 +2082,10 @@ def test_schema(tmpdir, options, expected):
|
||||||
def test_long_csv_column_value(tmpdir):
|
def test_long_csv_column_value(tmpdir):
|
||||||
db_path = str(tmpdir / "test.db")
|
db_path = str(tmpdir / "test.db")
|
||||||
csv_path = str(tmpdir / "test.csv")
|
csv_path = str(tmpdir / "test.csv")
|
||||||
csv_file = open(csv_path, "w")
|
with open(csv_path, "w") as csv_file:
|
||||||
long_string = "a" * 131073
|
long_string = "a" * 131073
|
||||||
csv_file.write("id,text\n")
|
csv_file.write("id,text\n")
|
||||||
csv_file.write("1,{}\n".format(long_string))
|
csv_file.write("1,{}\n".format(long_string))
|
||||||
csv_file.close()
|
|
||||||
result = CliRunner().invoke(
|
result = CliRunner().invoke(
|
||||||
cli.cli,
|
cli.cli,
|
||||||
["insert", db_path, "bigtable", csv_path, "--csv"],
|
["insert", db_path, "bigtable", csv_path, "--csv"],
|
||||||
|
|
@ -2110,11 +2109,10 @@ def test_long_csv_column_value(tmpdir):
|
||||||
def test_import_no_headers(tmpdir, args, tsv):
|
def test_import_no_headers(tmpdir, args, tsv):
|
||||||
db_path = str(tmpdir / "test.db")
|
db_path = str(tmpdir / "test.db")
|
||||||
csv_path = str(tmpdir / "test.csv")
|
csv_path = str(tmpdir / "test.csv")
|
||||||
csv_file = open(csv_path, "w")
|
with open(csv_path, "w") as csv_file:
|
||||||
sep = "\t" if tsv else ","
|
sep = "\t" if tsv else ","
|
||||||
csv_file.write("Cleo{sep}Dog{sep}5\n".format(sep=sep))
|
csv_file.write("Cleo{sep}Dog{sep}5\n".format(sep=sep))
|
||||||
csv_file.write("Tracy{sep}Spider{sep}7\n".format(sep=sep))
|
csv_file.write("Tracy{sep}Spider{sep}7\n".format(sep=sep))
|
||||||
csv_file.close()
|
|
||||||
result = CliRunner().invoke(
|
result = CliRunner().invoke(
|
||||||
cli.cli,
|
cli.cli,
|
||||||
["insert", db_path, "creatures", csv_path] + args,
|
["insert", db_path, "creatures", csv_path] + args,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue