Skip to content

Commit

Permalink
add detected encoding assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdesbas committed Nov 29, 2023
1 parent e293cae commit ac55544
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/test_unit/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from clevercsv._types import _DialectLike
from clevercsv.console import build_application
from clevercsv.dialect import SimpleDialect
from clevercsv.encoding import get_encoding
from clevercsv.write import writer

TableType = List[List[Any]]
Expand Down Expand Up @@ -671,7 +672,7 @@ def test_standardize_target_encoding2(self) -> None:
dialect = SimpleDialect(delimiter=";", quotechar="", escapechar="")
encoding='latin-1'
tmpfname = self._build_file(table, dialect, encoding=encoding)

self.assertEqual("ISO-8859-1", get_encoding(tmpfname, try_cchardet=False))
tmpfd, tmpoutname = tempfile.mkstemp(prefix="ccsv_", suffix=".csv")
os.close(tmpfd)

Expand All @@ -682,14 +683,19 @@ def test_standardize_target_encoding2(self) -> None:
# Excel format (i.e. RFC4180) *requires* CRLF
crlf = "\r\n"
exp = crlf.join(["A,B,C", "é,è,à", "4,5,6", ""])

self.assertEqual("utf-8", get_encoding(tmpoutname, try_cchardet=False))
with open(tmpoutname, "r", newline="") as fp:
output = fp.read()

try:
self.assertEqual(exp, output)

finally:
os.unlink(tmpfname)
os.unlink(tmpoutname)



def test_standardize_target_encoding_raise_UnicodeEncodeError(self) -> None:
table: TableType = [["Å", "B", "C"], ['é', 'ü', '中'], [4, 5, 6]]
Expand Down

0 comments on commit ac55544

Please sign in to comment.