fix: v0.4.1 — read stdin as UTF-8 (section --content - got mojibake from the frozen exe)
This commit is contained in:
1 parent
d063551a1e
commit
34d28c03fa
2 files changed
+24
-4
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
import yaml
|
||||
import shutil
|
||||
@@ -10,6 +12,8 @@ import click
|
||||
from click.testing import CliRunner
|
||||
from datetime import datetime
|
||||
|
||||
SRC = Path(__file__).resolve().parent.parent / 'src' / 'onyx.py'
|
||||
|
||||
class TestOnyxCLI(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Create temporary test directory and files
|
||||
@@ -594,5 +598,20 @@ Test content"""
|
||||
self.assertIn(str(self.test_dir.resolve()), printed)
|
||||
self.assertNotIn('path_prefix', printed)
|
||||
|
||||
def test_pipes_are_utf8_without_utf8_mode(self):
|
||||
"""stdin/stdout are UTF-8 even when Python isn't in UTF-8 mode (frozen exe on Windows)"""
|
||||
note = self.test_dir / 'd.md'
|
||||
note.write_text('## Journal\n', encoding='utf-8')
|
||||
env = {k: v for k, v in os.environ.items() if k not in ('PYTHONUTF8', 'PYTHONIOENCODING')}
|
||||
home = str(self.temp_config_dir.resolve())
|
||||
env.update(PYTHONUTF8='0', USERPROFILE=home, HOME=home)
|
||||
result = subprocess.run([sys.executable, str(SRC), 'section', 'd', '--heading', 'Journal',
|
||||
'--content', '-'], input='Réunion « test »'.encode('utf-8'),
|
||||
capture_output=True, env=env)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(note.read_text(encoding='utf-8'), '## Journal\nRéunion « test »\n')
|
||||
printed = subprocess.run([sys.executable, str(SRC), 'print-note', 'd'], capture_output=True, env=env)
|
||||
self.assertEqual(printed.stdout, '## Journal\nRéunion « test »\n\n'.encode('utf-8'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user