From 7f30f80d1a983751246ee1008cf4255f0f41b2d9 Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Sun, 28 Jan 2024 11:50:21 +0100 Subject: [PATCH 1/5] ci: run tests on windows --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 378afb51..0d6000ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,10 +22,11 @@ jobs: - run: nox --session mypy-${{matrix.python-version}} test: - runs-on: ubuntu-latest + runs-on: ${{matrix.os}} strategy: matrix: python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 From 78e9d4c88ed9285d0572933eb62f352abf90f427 Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Sun, 28 Jan 2024 13:05:44 +0100 Subject: [PATCH 2/5] test: add unicode characters to all generated files --- .pre-commit-config.yaml | 2 +- tests/conftest.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b6b7dee2..d57cd56a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,7 +70,7 @@ repos: stages: - commit-msg repo: https://github.com/commitizen-tools/commitizen - rev: 3.12.0 + rev: v3.12.0 - repo: https://github.com/PyCQA/docformatter diff --git a/tests/conftest.py b/tests/conftest.py index 06f53c40..78309e5e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,6 +67,7 @@ def run(self, *flags): prefix = """\"\"\" PYTEST_DONT_REWRITE \"\"\" +# äöß 🐍 from inline_snapshot import snapshot from inline_snapshot import external from inline_snapshot import outsource @@ -172,13 +173,17 @@ def project(pytester): class Project: def setup(self, source: str): self.header = """\ +# äöß 🐍 from inline_snapshot import snapshot from inline_snapshot import outsource """ if "# no imports" in source: - self.header = "" + self.header = """\ +# äöß 🐍 +""" else: self.header = """\ +# äöß 🐍 from inline_snapshot import snapshot from inline_snapshot import outsource """ From b732bb107f69ad839f4f8393d8f559ead64da096 Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Sun, 28 Jan 2024 13:36:06 +0100 Subject: [PATCH 3/5] fix: use utf-8 encoding to read and write source files --- inline_snapshot/_config.py | 2 +- inline_snapshot/_external.py | 3 ++- inline_snapshot/_find_external.py | 2 +- inline_snapshot/_rewrite_code.py | 2 +- tests/conftest.py | 21 +++++++++++---------- tests/test_docs.py | 4 ++-- tests/test_external.py | 10 ++++++---- tests/test_rewrite_code.py | 5 +++-- 8 files changed, 27 insertions(+), 22 deletions(-) diff --git a/inline_snapshot/_config.py b/inline_snapshot/_config.py index 551ef392..1b53567b 100644 --- a/inline_snapshot/_config.py +++ b/inline_snapshot/_config.py @@ -16,7 +16,7 @@ def read_config(path: Path) -> Config: if not path.exists(): return Config() - data = toml.loads(path.read_text()) + data = toml.loads(path.read_text("utf-8")) result = Config() diff --git a/inline_snapshot/_external.py b/inline_snapshot/_external.py index 9ba1a32d..0051147b 100644 --- a/inline_snapshot/_external.py +++ b/inline_snapshot/_external.py @@ -21,7 +21,8 @@ def _ensure_directory(self): gitignore = self.directory / ".gitignore" if not gitignore.exists(): gitignore.write_text( - "# ignore all snapshots which are not refered in the source\n*-new.*\n" + "# ignore all snapshots which are not refered in the source\n*-new.*\n", + "utf-8", ) def save(self, name, data): diff --git a/inline_snapshot/_find_external.py b/inline_snapshot/_find_external.py index 1306e3ec..e5e044a0 100644 --- a/inline_snapshot/_find_external.py +++ b/inline_snapshot/_find_external.py @@ -54,7 +54,7 @@ def used_externals_in(source) -> Set[str]: def used_externals() -> Set[str]: result = set() for filename in _inline_snapshot._files_with_snapshots: - result |= used_externals_in(pathlib.Path(filename).read_text()) + result |= used_externals_in(pathlib.Path(filename).read_text("utf-8")) return result diff --git a/inline_snapshot/_rewrite_code.py b/inline_snapshot/_rewrite_code.py index 615b8708..0ebae3bd 100644 --- a/inline_snapshot/_rewrite_code.py +++ b/inline_snapshot/_rewrite_code.py @@ -145,7 +145,7 @@ def new_code(self): for lhs, rhs in pairwise(replacements): assert lhs.range.end <= rhs.range.start - code = self.filename.read_text() + code = self.filename.read_text("utf-8") is_formatted = code == format_code(code, self.filename) diff --git a/tests/conftest.py b/tests/conftest.py index 78309e5e..999c7eeb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,6 +4,7 @@ import traceback from dataclasses import dataclass from dataclasses import field +from pathlib import Path from typing import Set import black @@ -61,7 +62,7 @@ def run(self, *flags): flags = Flags({*flags}) nonlocal filecount - filename = tmp_path / f"test_{filecount}.py" + filename: Path = tmp_path / f"test_{filecount}.py" filecount += 1 prefix = """\"\"\" @@ -75,7 +76,7 @@ def run(self, *flags): """ source = prefix + textwrap.dedent(self.source) - filename.write_text(source) + filename.write_text(source, "utf-8") print() print(f'run: inline-snapshot={",".join(flags.to_set())}') @@ -92,7 +93,7 @@ def run(self, *flags): error = False try: - exec(compile(filename.read_text(), filename, "exec")) + exec(compile(filename.read_text("utf-8"), filename, "exec")) except AssertionError: traceback.print_exc() error = True @@ -111,7 +112,7 @@ def run(self, *flags): recorder.fix_all(tags=["inline_snapshot"]) - source = filename.read_text()[len(prefix) :] + source = filename.read_text("utf-8")[len(prefix) :] print("output:") print(textwrap.indent(source, " |", lambda line: True).rstrip()) print("reported_flags:", snapshot_flags) @@ -194,23 +195,23 @@ def setup(self, source: str): source = header + source print("write code:") print(source) - self._filename.write_text(source) + self._filename.write_text(source, "utf-8") @property def _filename(self): return pytester.path / "test_file.py" def is_formatted(self): - code = self._filename.read_text() + code = self._filename.read_text("utf-8") return code == format_code(code, self._filename) def format(self): self._filename.write_text( - format_code(self._filename.read_text(), self._filename) + format_code(self._filename.read_text("utf-8"), self._filename), "utf-8" ) def pyproject(self, source): - (pytester.path / "pyproject.toml").write_text(source) + (pytester.path / "pyproject.toml").write_text(source, "utf-8") def storage(self): return sorted( @@ -221,8 +222,8 @@ def storage(self): @property def source(self): - assert self._filename.read_text()[: len(self.header)] == self.header - return self._filename.read_text()[len(self.header) :].lstrip() + assert self._filename.read_text("utf-8")[: len(self.header)] == self.header + return self._filename.read_text("utf-8")[len(self.header) :].lstrip() def run(self, *args): cache = pytester.path / "__pycache__" diff --git a/tests/test_docs.py b/tests/test_docs.py index e59c7fa0..e033a774 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -30,7 +30,7 @@ def test_docs(project, file, subtests): header = re.compile("") - text = file.read_text() + text = file.read_text("utf-8") new_lines = [] block_lines = [] options = set() @@ -118,4 +118,4 @@ def test_docs(project, file, subtests): new_lines.append(line) if inline_snapshot._inline_snapshot._update_flags.fix: # pragma: no cover - file.write_text("\n".join(new_lines) + "\n") + file.write_text("\n".join(new_lines) + "\n", "utf-8") diff --git a/tests/test_external.py b/tests/test_external.py index e0dd94ac..ea48f44e 100644 --- a/tests/test_external.py +++ b/tests/test_external.py @@ -323,13 +323,14 @@ def test_ensure_imports(tmp_path): """\ from os import environ from os import getcwd -""" +""", + "utf-8", ) with apply_changes(): ensure_import(file, {"os": ["chdir", "environ"]}) - assert file.read_text() == snapshot( + assert file.read_text("utf-8") == snapshot( """\ from os import environ from os import getcwd @@ -344,13 +345,14 @@ def test_ensure_imports_with_comment(tmp_path): file.write_text( """\ from os import environ # comment -""" +""", + "utf-8", ) with apply_changes(): ensure_import(file, {"os": ["chdir"]}) - assert file.read_text() == snapshot( + assert file.read_text("utf-8") == snapshot( """\ from os import environ # comment diff --git a/tests/test_rewrite_code.py b/tests/test_rewrite_code.py index 9a79aebc..b4bddcc7 100644 --- a/tests/test_rewrite_code.py +++ b/tests/test_rewrite_code.py @@ -29,7 +29,8 @@ def test_rewrite(tmp_path): 12345 12345 12345 -""" +""", + "utf-8", ) with ChangeRecorder().activate() as recorder: @@ -43,7 +44,7 @@ def test_rewrite(tmp_path): recorder.fix_all() assert ( - file.read_text() + file.read_text("utf-8") == """ 12a45 1245 From e765abfe0c4c366a13e442682ebaba5027356adc Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Sun, 28 Jan 2024 16:03:15 +0100 Subject: [PATCH 4/5] build: fix coverage --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d6000ed..fb1aa64c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: run: | poetry install poetry run coverage combine - mv .coverage .coverage.${{ matrix.python-version }} + mv .coverage .coverage.${{ matrix.python-version }}.${{matrix.os}} - name: Upload coverage data uses: actions/upload-artifact@v3 @@ -72,6 +72,7 @@ jobs: env: TOP: ${{github.workspace}} run: | + rm .coverage.*.windows-latest pip install coverage coverage combine coverage From dcec5e6ab3bea2366011043185c9fcda0552b561 Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Sun, 28 Jan 2024 16:30:23 +0100 Subject: [PATCH 5/5] =?UTF-8?q?bump:=20version=200.6.0=20=E2=86=92=200.6.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ inline_snapshot/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cdeffb8..8fbae2a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.6.1 (2024-01-28) + +### Fix + +- use utf-8 encoding to read and write source files + ## v0.6.0 (2023-12-10) ### Feat diff --git a/inline_snapshot/__init__.py b/inline_snapshot/__init__.py index c1b85b8b..8206cb32 100644 --- a/inline_snapshot/__init__.py +++ b/inline_snapshot/__init__.py @@ -4,4 +4,4 @@ __all__ = ["snapshot", "external", "outsource"] -__version__ = "0.6.0" +__version__ = "0.6.1" diff --git a/pyproject.toml b/pyproject.toml index 4282c7b9..0d6d3380 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ license = "MIT" name = "inline-snapshot" readme = "README.md" repository = "https://github.com/15r10nk/inline-snapshots" -version = "0.6.0" +version = "0.6.1" [tool.poetry.dependencies] asttokens = ">=2.0.5"