Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_csv_utf8(tmpdir):
"""CSV with quotes and commas."""
database_path = Path(tmpdir/"database.csv")
database_path.write_text(textwrap.dedent(u"""\
email,message
Laȝamon ,Laȝamon emoji \xf0\x9f\x98\x80 klâwen
"""))
row = next(mailmerge.__main__.read_csv_database(database_path))
assert row["email"] == u"Laȝamon "
assert row["message"] == u"Laȝamon emoji \xf0\x9f\x98\x80 klâwen"
def test_csv_bad(tmpdir):
"""Bad CSV includes includes filename and line number."""
# CSV with unmatched quote
database_path = Path(tmpdir/"database.csv")
database_path.write_text(textwrap.dedent(u"""\
a,b
1,"2
"""))
# The first line of data triggers an error
with pytest.raises(csv.Error):
next(mailmerge.__main__.read_csv_database(database_path))