Skip to content
Merged
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 pytest_examples/eval_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,5 @@ def _mark_for_update(self, example: CodeExample) -> None:

def _write_file(self, example: CodeExample) -> Path:
python_file = self.tmp_path / f'{example.module_name}.py'
python_file.write_text(example.source)
python_file.write_text(example.source, encoding='utf-8')
return python_file
2 changes: 1 addition & 1 deletion pytest_examples/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def ruff_check(
ruff = find_ruff_bin()
args = ruff, 'check', '-', *config.ruff_config(), *extra_ruff_args

p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, encoding='utf-8')
stdout, stderr = p.communicate(example.source, timeout=10)
if p.returncode == 1 and stdout:

Expand Down
4 changes: 2 additions & 2 deletions pytest_examples/modify_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _modify_files(examples: list[CodeExample]) -> str:
msg = [f'pytest-examples: {len(examples)} examples to update in {len(files)} file(s)...']

for path, g in groupby(examples, key=lambda ex: ex.path):
content = path.read_text()
content = path.read_text(encoding='utf-8')
count = 0
for ex in g:
example: CodeExample = ex
Expand All @@ -45,6 +45,6 @@ def _modify_files(examples: list[CodeExample]) -> str:
count += 1

msg.append(f' {path} {count} examples updated')
path.write_text(content)
path.write_text(content, encoding='utf-8')

return '\n'.join(msg)
20 changes: 20 additions & 0 deletions tests/test_run_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,23 @@ def test_find_run_examples(example: CodeExample, eval_example: EvalExample):

result = pytester.runpytest('-p', 'no:pretty', '-v')
result.assert_outcomes(passed=1)


def test_unicode_emoji(pytester: pytest.Pytester):
pytester.makefile(
'.md',
my_file="```py\nprint('πŸš€ βœ“')\n#> πŸš€ βœ“\n```",
)
pytester.makepyfile(
"""
from pytest_examples import find_examples, CodeExample, EvalExample
import pytest

@pytest.mark.parametrize('example', find_examples('.'), ids=str)
def test_find_run_examples(example: CodeExample, eval_example: EvalExample):
eval_example.run_print_check(example)
"""
)

result = pytester.runpytest('-p', 'no:pretty', '-v')
result.assert_outcomes(passed=1)
Loading