Skip to content

Commit

Permalink
Set utf-8 encoding in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Dec 4, 2024
1 parent 3d1420f commit 6074f3c
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions tests/test_juv.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def test_add_creates_inline_meta(
result = invoke(["add", str(nb), "polars==1", "anywidget"], uv_python="3.11")
assert result.exit_code == 0
assert filter_tempfile_ipynb(result.stdout) == snapshot("Updated `foo.ipynb`\n")
assert filter_ids(nb.read_text()) == snapshot("""\
assert filter_ids(nb.read_text(encoding="utf-8")) == snapshot("""\
{
"cells": [
{
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_add_prepends_script_meta(
result = invoke(["add", str(path), "polars==1", "anywidget"], uv_python="3.10")
assert result.exit_code == 0
assert filter_tempfile_ipynb(result.stdout) == snapshot("Updated `empty.ipynb`\n")
assert filter_ids(path.read_text()) == snapshot("""\
assert filter_ids(path.read_text(encoding="utf-8")) == snapshot("""\
{
"cells": [
{
Expand Down Expand Up @@ -404,7 +404,7 @@ def test_add_updates_existing_meta(
result = invoke(["add", str(path), "polars==1", "anywidget"], uv_python="3.13")
assert result.exit_code == 0
assert filter_tempfile_ipynb(result.stdout) == snapshot("Updated `empty.ipynb`\n")
assert filter_ids(path.read_text()) == snapshot("""\
assert filter_ids(path.read_text(encoding="utf-8")) == snapshot("""\
{
"cells": [
{
Expand Down Expand Up @@ -444,7 +444,7 @@ def test_init_creates_notebook_with_inline_meta(
assert filter_tempfile_ipynb(result.stdout) == snapshot(
"Initialized notebook at `empty.ipynb`\n"
)
assert filter_ids(path.read_text()) == snapshot("""\
assert filter_ids(path.read_text(encoding="utf-8")) == snapshot("""\
{
"cells": [
{
Expand Down Expand Up @@ -497,7 +497,7 @@ def test_init_creates_notebook_with_specific_python_version(
assert filter_tempfile_ipynb(result.stdout) == snapshot(
"Initialized notebook at `empty.ipynb`\n"
)
assert filter_ids(path.read_text()) == snapshot("""\
assert filter_ids(path.read_text(encoding="utf-8")) == snapshot("""\
{
"cells": [
{
Expand Down Expand Up @@ -558,7 +558,7 @@ def test_init_with_deps(
assert result.stdout == snapshot("Initialized notebook at `Untitled.ipynb`\n")

path = tmp_path / "Untitled.ipynb"
assert filter_ids(path.read_text()) == snapshot("""\
assert filter_ids(path.read_text(encoding="utf-8")) == snapshot("""\
{
"cells": [
{
Expand Down Expand Up @@ -853,18 +853,18 @@ def test_stamp_script(
tmp_path = pathlib.Path(tmpdir)
monkeypatch.chdir(tmp_path)

with (tmp_path / "foo.py").open("w") as f:
with (tmp_path / "foo.py").open("w", encoding="utf-8") as f:
f.write("""# /// script
# requires-python = ">=3.13"
# dependencies = []
# ///
def main() -> None: |
print("Hello from foo.py!") |
|
|
if __name__ == "__main__": |
def main() -> None:
print("Hello from foo.py!")
if __name__ == "__main__":
main()
""")
result = invoke(["stamp", "foo.py", "--date", "2006-01-02"])
Expand All @@ -873,7 +873,7 @@ def main() -> None:
assert result.stdout == snapshot(
"Stamped `foo.py` with 2006-01-03T00:00:00-05:00\n"
)
assert (tmp_path / "foo.py").read_text() == snapshot("""\
assert (tmp_path / "foo.py").read_text(encoding="utf-8") == snapshot("""\
# /// script
# requires-python = ">=3.13"
# dependencies = []
Expand All @@ -883,11 +883,11 @@ def main() -> None:
# ///
def main() -> None: |
print("Hello from foo.py!") |
|
|
if __name__ == "__main__": |
def main() -> None:
print("Hello from foo.py!")
if __name__ == "__main__":
main()
""")

Expand All @@ -902,7 +902,7 @@ def test_stamp_clear(
tmp_path = pathlib.Path(tmpdir)
monkeypatch.chdir(tmp_path)

with (tmp_path / "foo.py").open("w") as f:
with (tmp_path / "foo.py").open("w", encoding="utf-8") as f:
f.write("""# /// script
# requires-python = ">=3.13"
# dependencies = []
Expand All @@ -916,7 +916,7 @@ def test_stamp_clear(

assert result.exit_code == 0
assert result.stdout == snapshot("Removed blah from `foo.py`\n")
assert (tmp_path / "foo.py").read_text() == snapshot("""\
assert (tmp_path / "foo.py").read_text(encoding="utf-8") == snapshot("""\
# /// script
# requires-python = ">=3.13"
# dependencies = []
Expand Down Expand Up @@ -950,7 +950,7 @@ def test_add_script_pinned(
) -> None:
monkeypatch.chdir(tmp_path)

with (tmp_path / "foo.py").open("w") as f:
with (tmp_path / "foo.py").open("w", encoding="utf-8") as f:
f.write("""# /// script
# requires-python = ">=3.13"
# dependencies = []
Expand All @@ -962,7 +962,7 @@ def test_add_script_pinned(
result = invoke(["add", "foo.py", "anywidget", "--pin"])
assert result.exit_code == 0
assert result.stdout == snapshot("Updated `foo.py`\n")
assert (tmp_path / "foo.py").read_text() == snapshot("""\
assert (tmp_path / "foo.py").read_text(encoding="utf-8") == snapshot("""\
# /// script
# requires-python = ">=3.13"
# dependencies = [
Expand Down

0 comments on commit 6074f3c

Please sign in to comment.