Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def stream_file(path: os.PathLike) -> Iterator[IO[str]]:
"""

try:
with open(path) as stream:
with open(path, encoding="utf-8") as stream:
yield stream
except OSError as exc:
print(f"Error opening env file: {exc}", file=sys.stderr)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def test_list(
assert (result.exit_code, result.output) == (0, expected)


def test_list_non_ascii_value(cli, dotenv_path):
"""`list` must read the file as UTF-8, like the library API does."""
dotenv_path.write_text("a=Köln\n", encoding="utf-8")

result = cli.invoke(dotenv_cli, ["--file", dotenv_path, "list"])

assert (result.exit_code, result.output) == (0, "a=Köln\n")


def test_list_non_existent_file(cli):
result = cli.invoke(dotenv_cli, ["--file", "nx_file", "list"])

Expand Down Expand Up @@ -67,6 +76,15 @@ def test_get_existing_value(cli, dotenv_path):
assert (result.exit_code, result.output) == (0, "b\n")


def test_get_non_ascii_value(cli, dotenv_path):
"""`get` must read the file as UTF-8, like the library API does."""
dotenv_path.write_text("a=Köln\n", encoding="utf-8")

result = cli.invoke(dotenv_cli, ["--file", dotenv_path, "get", "a"])

assert (result.exit_code, result.output) == (0, "Köln\n")


def test_get_non_existent_value(cli, dotenv_path):
result = cli.invoke(dotenv_cli, ["--file", dotenv_path, "get", "a"])

Expand Down