diff --git a/poetry.lock b/poetry.lock index f070e0e..617ee1e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,10 +1,9 @@ -# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. [[package]] name = "argcomplete" version = "3.1.1" description = "Bash tab completion for argparse" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -19,7 +18,6 @@ test = ["coverage", "mypy", "pexpect", "ruff", "wheel"] name = "attrs" version = "23.1.0" description = "Classes Without Boilerplate" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -38,7 +36,6 @@ tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pyte name = "black" version = "23.7.0" description = "The uncompromising code formatter." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -84,7 +81,6 @@ uvloop = ["uvloop (>=0.15.2)"] name = "cfgv" version = "3.4.0" description = "Validate configuration and produce human readable error messages." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -96,7 +92,6 @@ files = [ name = "charset-normalizer" version = "3.2.0" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." -category = "main" optional = false python-versions = ">=3.7.0" files = [ @@ -181,7 +176,6 @@ files = [ name = "click" version = "8.1.7" description = "Composable command line interface toolkit" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -196,7 +190,6 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} name = "colorama" version = "0.4.6" description = "Cross-platform colored terminal text." -category = "main" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" files = [ @@ -208,7 +201,6 @@ files = [ name = "commitizen" version = "3.7.0" description = "Python commitizen client tool" -category = "dev" optional = false python-versions = ">=3.7,<4.0" files = [ @@ -233,7 +225,6 @@ tomlkit = ">=0.5.3,<1.0.0" name = "coverage" version = "7.3.0" description = "Code coverage measurement for Python" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -298,7 +289,6 @@ toml = ["tomli"] name = "decli" version = "0.6.1" description = "Minimal, easy-to-use, declarative cli tool" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -310,7 +300,6 @@ files = [ name = "distlib" version = "0.3.7" description = "Distribution utilities" -category = "dev" optional = false python-versions = "*" files = [ @@ -322,7 +311,6 @@ files = [ name = "emoji" version = "2.8.0" description = "Emoji for Python" -category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" files = [ @@ -337,7 +325,6 @@ dev = ["coverage", "coveralls", "pytest"] name = "exceptiongroup" version = "1.1.3" description = "Backport of PEP 654 (exception groups)" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -352,7 +339,6 @@ test = ["pytest (>=6)"] name = "execnet" version = "2.0.2" description = "execnet: rapid multi-Python deployment" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -367,7 +353,6 @@ testing = ["hatch", "pre-commit", "pytest", "tox"] name = "filelock" version = "3.12.3" description = "A platform independent file lock." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -386,7 +371,6 @@ testing = ["covdefaults (>=2.3)", "coverage (>=7.3)", "diff-cover (>=7.7)", "pyt name = "identify" version = "2.5.27" description = "File identification library for Python" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -401,7 +385,6 @@ license = ["ukkonen"] name = "importlib-metadata" version = "6.8.0" description = "Read metadata from Python packages" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -421,7 +404,6 @@ testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs name = "iniconfig" version = "2.0.0" description = "brain-dead simple config-ini parsing" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -433,7 +415,6 @@ files = [ name = "interrogate" version = "1.5.0" description = "Interrogate a codebase for docstring coverage." -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -459,7 +440,6 @@ tests = ["pytest", "pytest-cov", "pytest-mock"] name = "jinja2" version = "3.1.2" description = "A very fast and expressive template engine." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -477,7 +457,6 @@ i18n = ["Babel (>=2.7)"] name = "loguru" version = "0.7.0" description = "Python logging made (stupidly) simple" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -496,7 +475,6 @@ dev = ["Sphinx (==5.3.0)", "colorama (==0.4.5)", "colorama (==0.4.6)", "freezegu name = "markdown-it-py" version = "3.0.0" description = "Python port of markdown-it. Markdown parsing, done right!" -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -521,7 +499,6 @@ testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"] name = "markupsafe" version = "2.1.3" description = "Safely add untrusted strings to HTML/XML markup." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -581,7 +558,6 @@ files = [ name = "mdurl" version = "0.1.2" description = "Markdown URL utilities" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -593,7 +569,6 @@ files = [ name = "mypy" version = "1.5.1" description = "Optional static typing for Python" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -640,7 +615,6 @@ reports = ["lxml"] name = "mypy-extensions" version = "1.0.0" description = "Type system extensions for programs checked with the mypy type checker." -category = "dev" optional = false python-versions = ">=3.5" files = [ @@ -652,7 +626,6 @@ files = [ name = "nodeenv" version = "1.8.0" description = "Node.js virtual environment builder" -category = "dev" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" files = [ @@ -667,7 +640,6 @@ setuptools = "*" name = "packaging" version = "23.1" description = "Core utilities for Python packages" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -679,7 +651,6 @@ files = [ name = "pastel" version = "0.2.1" description = "Bring colors to your terminal." -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" files = [ @@ -691,7 +662,6 @@ files = [ name = "pathspec" version = "0.11.2" description = "Utility library for gitignore style pattern matching of file paths." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -703,7 +673,6 @@ files = [ name = "pdoc" version = "14.0.0" description = "API Documentation for Python Projects" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -723,7 +692,6 @@ dev = ["black", "hypothesis", "mypy", "pygments (>=2.14.0)", "pytest", "pytest-c name = "platformdirs" version = "3.10.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -739,7 +707,6 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-co name = "pluggy" version = "1.3.0" description = "plugin and hook calling mechanisms for python" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -755,7 +722,6 @@ testing = ["pytest", "pytest-benchmark"] name = "poethepoet" version = "0.22.0" description = "A task runner that works well with poetry." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -774,7 +740,6 @@ poetry-plugin = ["poetry (>=1.0,<2.0)"] name = "pprintpp" version = "0.4.0" description = "A drop-in replacement for pprint that's actually pretty" -category = "dev" optional = false python-versions = "*" files = [ @@ -784,14 +749,13 @@ files = [ [[package]] name = "pre-commit" -version = "3.3.3" +version = "3.4.0" description = "A framework for managing and maintaining multi-language pre-commit hooks." -category = "dev" optional = false python-versions = ">=3.8" files = [ - {file = "pre_commit-3.3.3-py2.py3-none-any.whl", hash = "sha256:10badb65d6a38caff29703362271d7dca483d01da88f9d7e05d0b97171c136cb"}, - {file = "pre_commit-3.3.3.tar.gz", hash = "sha256:a2256f489cd913d575c145132ae196fe335da32d91a8294b7afe6622335dd023"}, + {file = "pre_commit-3.4.0-py2.py3-none-any.whl", hash = "sha256:96d529a951f8b677f730a7212442027e8ba53f9b04d217c4c67dc56c393ad945"}, + {file = "pre_commit-3.4.0.tar.gz", hash = "sha256:6bbd5129a64cad4c0dfaeeb12cd8f7ea7e15b77028d985341478c8af3c759522"}, ] [package.dependencies] @@ -805,7 +769,6 @@ virtualenv = ">=20.10.0" name = "prompt-toolkit" version = "3.0.39" description = "Library for building powerful interactive command lines in Python" -category = "main" optional = false python-versions = ">=3.7.0" files = [ @@ -820,7 +783,6 @@ wcwidth = "*" name = "py" version = "1.11.0" description = "library with cross-python path, ini-parsing, io, code, log facilities" -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" files = [ @@ -832,7 +794,6 @@ files = [ name = "pygments" version = "2.16.1" description = "Pygments is a syntax highlighting package written in Python." -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -845,14 +806,13 @@ plugins = ["importlib-metadata"] [[package]] name = "pytest" -version = "7.4.0" +version = "7.4.1" description = "pytest: simple powerful testing with Python" -category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "pytest-7.4.0-py3-none-any.whl", hash = "sha256:78bf16451a2eb8c7a2ea98e32dc119fd2aa758f1d5d66dbf0a59d69a3969df32"}, - {file = "pytest-7.4.0.tar.gz", hash = "sha256:b4bf8c45bd59934ed84001ad51e11b4ee40d40a1229d2c79f9c592b0a3f6bd8a"}, + {file = "pytest-7.4.1-py3-none-any.whl", hash = "sha256:460c9a59b14e27c602eb5ece2e47bec99dc5fc5f6513cf924a7d03a578991b1f"}, + {file = "pytest-7.4.1.tar.gz", hash = "sha256:2f2301e797521b23e4d2585a0a3d7b5e50fdddaaf7e7d6773ea26ddb17c213ab"}, ] [package.dependencies] @@ -870,7 +830,6 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no name = "pytest-clarity" version = "1.0.1" description = "A plugin providing an alternative, colourful diff output for failing assertions." -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" files = [ @@ -886,7 +845,6 @@ rich = ">=8.0.0" name = "pytest-mock" version = "3.11.1" description = "Thin-wrapper around the mock package for easier use with pytest" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -904,7 +862,6 @@ dev = ["pre-commit", "pytest-asyncio", "tox"] name = "pytest-pretty-terminal" version = "1.1.0" description = "pytest plugin for generating prettier terminal output" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -922,7 +879,6 @@ test = ["pytest-adaptavist (>=5.1.1)"] name = "pytest-xdist" version = "3.3.1" description = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -943,7 +899,6 @@ testing = ["filelock"] name = "pyyaml" version = "6.0.1" description = "YAML parser and emitter for Python" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -993,7 +948,6 @@ files = [ name = "questionary" version = "1.10.0" description = "Python library to build pretty command line user prompts ⭐️" -category = "main" optional = false python-versions = ">=3.6,<4.0" files = [ @@ -1011,7 +965,6 @@ docs = ["Sphinx (>=3.3,<4.0)", "sphinx-autobuild (>=2020.9.1,<2021.0.0)", "sphin name = "regex" version = "2023.8.8" description = "Alternative regular expression module, to replace re." -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -1109,7 +1062,6 @@ files = [ name = "rich" version = "13.5.2" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" -category = "main" optional = false python-versions = ">=3.7.0" files = [ @@ -1128,7 +1080,6 @@ jupyter = ["ipywidgets (>=7.5.1,<9)"] name = "ruamel-yaml" version = "0.17.32" description = "ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order" -category = "main" optional = false python-versions = ">=3" files = [ @@ -1147,7 +1098,6 @@ jinja2 = ["ruamel.yaml.jinja2 (>=0.2)"] name = "ruamel-yaml-clib" version = "0.2.7" description = "C version of reader, parser and emitter for ruamel.yaml derived from libyaml" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -1193,7 +1143,6 @@ files = [ name = "ruff" version = "0.0.286" description = "An extremely fast Python linter, written in Rust." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1220,7 +1169,6 @@ files = [ name = "setuptools" version = "68.1.2" description = "Easily download, build, install, upgrade, and uninstall Python packages" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1237,7 +1185,6 @@ testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs ( name = "sh" version = "2.0.6" description = "Python subprocess replacement" -category = "dev" optional = false python-versions = ">=3.8.1,<4.0" files = [ @@ -1249,7 +1196,6 @@ files = [ name = "shellingham" version = "1.5.3" description = "Tool to Detect Surrounding Shell" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1261,7 +1207,6 @@ files = [ name = "tabulate" version = "0.9.0" description = "Pretty-print tabular data" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1276,7 +1221,6 @@ widechars = ["wcwidth"] name = "termcolor" version = "2.3.0" description = "ANSI color formatting for output in terminal" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1291,7 +1235,6 @@ tests = ["pytest", "pytest-cov"] name = "toml" version = "0.10.2" description = "Python Library for Tom's Obvious, Minimal Language" -category = "dev" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -1303,7 +1246,6 @@ files = [ name = "tomli" version = "2.0.1" description = "A lil' TOML parser" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1315,7 +1257,6 @@ files = [ name = "tomlkit" version = "0.12.1" description = "Style preserving TOML library" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1327,7 +1268,6 @@ files = [ name = "typer" version = "0.9.0" description = "Typer, build great CLIs. Easy to code. Based on Python type hints." -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -1349,7 +1289,6 @@ test = ["black (>=22.3.0,<23.0.0)", "coverage (>=6.2,<7.0)", "isort (>=5.0.6,<6. name = "types-python-dateutil" version = "2.8.19.14" description = "Typing stubs for python-dateutil" -category = "dev" optional = false python-versions = "*" files = [ @@ -1361,7 +1300,6 @@ files = [ name = "typing-extensions" version = "4.7.1" description = "Backported and Experimental Type Hints for Python 3.7+" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1371,29 +1309,27 @@ files = [ [[package]] name = "typos" -version = "1.16.9" +version = "1.16.10" description = "Source Code Spelling Correction" -category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "typos-1.16.9-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:a57a2bb3c2cefe635a311656e68c37befaee6380af7b5c670250125781862cdb"}, - {file = "typos-1.16.9-py3-none-macosx_11_0_arm64.whl", hash = "sha256:22c3006eb56410d1854c78e982b2c61a2f35d5530fa9b58a5c61c9fff80a550e"}, - {file = "typos-1.16.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8a0424c6536dc7210892437c610d761278b13dc8a755e35a8a2ee16017bcf112"}, - {file = "typos-1.16.9-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7e26df48469ce64d994b7abcfc31ac18080429e4099ac2d6485b610b589cf418"}, - {file = "typos-1.16.9-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:62abe376396b97b3a9830b51125af1207a0b598c8bad83a4a9c593e0a9e228a8"}, - {file = "typos-1.16.9-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:b4a6dc96a9e8f46f5ef7f49b6b8c504ac432e12ade37e08df4c488acca18b76f"}, - {file = "typos-1.16.9-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:de0641a1c09f6c5255b9025e6de4e4137a3aaf910dc067312c288a22d3eb245c"}, - {file = "typos-1.16.9-py3-none-win32.whl", hash = "sha256:abcd1dde8b5c598363a392a32ebb1572442a377ad67377cb912b367d269e6a4a"}, - {file = "typos-1.16.9-py3-none-win_amd64.whl", hash = "sha256:1a3f65697e8d290abb05fda06704b64a90489e2b66802d1c2bdc1122d5fdc784"}, - {file = "typos-1.16.9.tar.gz", hash = "sha256:ebc3437484aff83c85cde05128533aaa2f4fdeb29054e7ae7511921d14bb7ce8"}, + {file = "typos-1.16.10-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:909d0c6446c3d1f68f2721e9acfd4ed996d459cb0fbea129d66daf22c42b2a2d"}, + {file = "typos-1.16.10-py3-none-macosx_11_0_arm64.whl", hash = "sha256:849b4b5b3f6a507e287b604f327bd881d5b96cb6c81856e05fb5891b6a3a0bba"}, + {file = "typos-1.16.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b6d2842494e03cc97133126509bc40b129de5810b86f3d1d3f15f966c8b7c031"}, + {file = "typos-1.16.10-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ef6104f5951bb8348337c6cb64ebb4a6f72af2f6157e981473db8bd1ba3b5569"}, + {file = "typos-1.16.10-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2325bdf30f38d53e5efdf170a7691ce4fb51411782c4fc465a862d152b0df198"}, + {file = "typos-1.16.10-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:dc77b0ae05cf81cfa4bbb5486e008ce7049770539340ef01c3be950a91981032"}, + {file = "typos-1.16.10-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:670bb6877b99de725fae6b374a4aef4f13ff1bfe492bb165054bac8454086e88"}, + {file = "typos-1.16.10-py3-none-win32.whl", hash = "sha256:2173f10ec3eff7812b49cce096199deee044c399fa2c49c9a7d24bf3e10d28b2"}, + {file = "typos-1.16.10-py3-none-win_amd64.whl", hash = "sha256:486edb47ab514d0aa15f145b7da9b5fc5892f8bde5afc5e49e792f5a39e4ec77"}, + {file = "typos-1.16.10.tar.gz", hash = "sha256:e4325f5818de70f7cec5caeb8644853a8271fce47bba391f73b529750841c059"}, ] [[package]] name = "virtualenv" version = "20.24.4" description = "Virtual Python Environment builder" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1414,7 +1350,6 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess name = "vulture" version = "2.9.1" description = "Find dead code" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1429,7 +1364,6 @@ toml = "*" name = "wcwidth" version = "0.2.6" description = "Measures the displayed width of unicode strings in a terminal" -category = "main" optional = false python-versions = "*" files = [ @@ -1441,7 +1375,6 @@ files = [ name = "win32-setctime" version = "1.1.0" description = "A small Python utility to set file creation time on Windows" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -1456,7 +1389,6 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] name = "zipp" version = "3.16.2" description = "Backport of pathlib-compatible object wrapper for zip files" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1470,5 +1402,5 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" - python-versions = "^3.10" +python-versions = "^3.10" content-hash = "6aca7ce8bb2d4e097d7e62625026bf85ab82710a010dacaf49b13371216bdbfa" diff --git a/src/obsidian_metadata/models/notes.py b/src/obsidian_metadata/models/notes.py index fc2d8dd..733dc17 100644 --- a/src/obsidian_metadata/models/notes.py +++ b/src/obsidian_metadata/models/notes.py @@ -448,7 +448,8 @@ class Note: try: log.trace(f"Writing note {p} to disk") - p.write_text(self.file_content) + content_bytes = bytes(self.file_content, self.encoding) + p.write_bytes(content_bytes) except FileNotFoundError as e: alerts.error(f"Note {p} not found. Exiting") raise typer.Exit(code=1) from e diff --git a/tests/fixtures/CP1250.md b/tests/fixtures/CP1250.md new file mode 100644 index 0000000..cb7b29b --- /dev/null +++ b/tests/fixtures/CP1250.md @@ -0,0 +1,44 @@ +--- +date_created: 2022-12-22 # confirm dates are translated to strings +tags: + - foo + - bar +frontmatter1: foo +frontmatter2: ["bar", "baz", "qux"] +??: ?? +# Nested lists are not supported +# invalid: +# invalid: +# - invalid +# - invalid2 +french1: "Voix ambigu d'un cour qui, au zphyr, prfere les jattes de kiwis" +--- + +# Heading 1 + +inline1:: foo +inline1::bar baz +**inline2**:: [[foo]] +_inline3_:: value +??::?? +key with space:: foo +french2:: Voix ambigu d'un cour qui, au zphyr, prfere les jattes de kiwis. + +> inline4:: foo + +inline5:: + +foo bar [intext1:: foo] baz `#invalid` qux (intext2:: foo) foobar. #tag1 Foo bar #tag2 baz qux. [[link]] + +The quick brown fox jumped over the lazy dog. + +# tag3 + +--- + +## invalid: invalid + +```python +invalid:: invalid +#invalid +``` diff --git a/tests/fixtures/test_vault/sample_note.md b/tests/fixtures/test_vault/sample_note.md index 9f1fea4..a6ae3b3 100644 --- a/tests/fixtures/test_vault/sample_note.md +++ b/tests/fixtures/test_vault/sample_note.md @@ -11,6 +11,7 @@ frontmatter2: ["bar", "baz", "qux"] # invalid: # - invalid # - invalid2 +french1: "Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis" --- # Heading 1 @@ -21,6 +22,7 @@ inline1::bar baz _inline3_:: value 🌱::🌿 key with space:: foo +french2:: Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis. > inline4:: foo diff --git a/tests/notes/note_init_test.py b/tests/notes/note_init_test.py index d6a2249..5addba1 100644 --- a/tests/notes/note_init_test.py +++ b/tests/notes/note_init_test.py @@ -34,7 +34,7 @@ def test_create_note_1(sample_note): assert note.note_path == Path(sample_note) assert note.dry_run is True assert note.encoding == "utf_8" - assert len(note.metadata) == 20 + assert len(note.metadata) == 22 with sample_note.open(): content = sample_note.read_text() diff --git a/tests/notes/note_methods_test.py b/tests/notes/note_methods_test.py index f4d3dd0..47bdf7f 100644 --- a/tests/notes/note_methods_test.py +++ b/tests/notes/note_methods_test.py @@ -1,9 +1,11 @@ # type: ignore """Test for metadata methods within Note class.""" +import shutil from pathlib import Path import pytest import typer +from charset_normalizer import from_path from tests.helpers import Regex from obsidian_metadata._utils.console import console @@ -97,8 +99,8 @@ def test__edit_inline_metadata_2(tmp_path, content, new_key, new_value, new_cont @pytest.mark.parametrize( ("meta_type", "key", "value", "is_regex", "expected"), [ - (MetadataType.FRONTMATTER, None, None, False, 8), - (MetadataType.FRONTMATTER, None, None, True, 8), + (MetadataType.FRONTMATTER, None, None, False, 9), + (MetadataType.FRONTMATTER, None, None, True, 9), (MetadataType.FRONTMATTER, "frontmatter1", None, False, 1), (MetadataType.FRONTMATTER, r"\w+2", None, True, 3), (MetadataType.FRONTMATTER, "frontmatter1", "foo", False, 1), @@ -108,10 +110,10 @@ def test__edit_inline_metadata_2(tmp_path, content, new_key, new_value, new_cont (MetadataType.FRONTMATTER, "frontmatterXX", None, False, 0), (MetadataType.FRONTMATTER, r"^\d", "XXX", False, 0), (MetadataType.FRONTMATTER, "frontmatterXX", r"^\d+", False, 0), - (MetadataType.INLINE, None, None, False, 10), - (MetadataType.INLINE, None, None, True, 10), + (MetadataType.INLINE, None, None, False, 11), + (MetadataType.INLINE, None, None, True, 11), (MetadataType.INLINE, "inline1", None, False, 2), - (MetadataType.INLINE, r"\w+2", None, True, 2), + (MetadataType.INLINE, r"\w+2", None, True, 3), (MetadataType.INLINE, "inline1", "foo", False, 1), (MetadataType.INLINE, "inline1", r"\w+", True, 2), (MetadataType.INLINE, r"\w+1", "foo", True, 2), @@ -155,7 +157,7 @@ def test__update_inline_metadata_1(sample_note, meta_type): THEN raise an error """ note = Note(note_path=sample_note) - source_field = [x for x in note.metadata][0] + source_field = next(iter(note.metadata)) source_field.meta_type = meta_type with pytest.raises(typer.Exit): @@ -170,7 +172,7 @@ def test__update_inline_metadata_2(sample_note): THEN raise an error """ note = Note(note_path=sample_note) - source_field = [x for x in note.metadata][0] + source_field = next(iter(note.metadata)) source_field.meta_type = MetadataType.INLINE with pytest.raises(typer.Exit): @@ -198,11 +200,11 @@ def test__update_inline_metadata_3( note = Note(note_path=sample_note) if orig_key is None: - source_inlinefield = [ + source_inlinefield = next( x for x in note.metadata if x.meta_type == MetadataType.INLINE and x.normalized_value == orig_value - ][0] + ) assert ( note._update_inline_metadata(source_inlinefield, new_key=new_key, new_value=new_value) is True @@ -210,11 +212,11 @@ def test__update_inline_metadata_3( assert source_inlinefield.normalized_value == new_value elif orig_value is None: - source_inlinefield = [ + source_inlinefield = next( x for x in note.metadata if x.meta_type == MetadataType.INLINE and x.normalized_key == orig_key - ][0] + ) assert ( note._update_inline_metadata(source_inlinefield, new_key=new_key, new_value=new_value) is True @@ -222,13 +224,13 @@ def test__update_inline_metadata_3( assert source_inlinefield.normalized_key == new_key.lower() else: - source_inlinefield = [ + source_inlinefield = next( x for x in note.metadata if x.meta_type == MetadataType.INLINE if x.normalized_key == orig_key if x.normalized_value == orig_value - ][0] + ) assert ( note._update_inline_metadata(source_inlinefield, new_key=new_key, new_value=new_value) is True @@ -329,6 +331,18 @@ def test_add_metadata_6(sample_note): (MetadataType.INLINE, "test", "value", "test:: value"), (MetadataType.TAGS, None, "testtag", "#testtag"), (MetadataType.TAGS, None, "#testtag", "#testtag"), + ( + MetadataType.INLINE, + "french3", + "Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.", + "french3:: Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.", + ), + ( + MetadataType.FRONTMATTER, + "french3", + "Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.", + "french3: Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.", + ), ], ) def test_add_metadata_7(sample_note, metatype, key, value, expected): @@ -362,15 +376,14 @@ def test_commit_1(sample_note, tmp_path) -> None: note.sub(pattern="Heading 1", replacement="Heading 2") note.commit() - note = Note(note_path=sample_note) - assert "Heading 2" in note.file_content - assert "Heading 1" not in note.file_content + assert "Heading 2" in sample_note.read_text() + assert "Heading 1" not in sample_note.read_text() new_path = Path(tmp_path / "new_note.md") + note.commit(new_path) - note2 = Note(note_path=new_path) - assert "Heading 2" in note2.file_content - assert "Heading 1" not in note2.file_content + assert "Heading 2" in new_path.read_text() + assert "Heading 1" not in new_path.read_text() def test_commit_2(sample_note) -> None: @@ -382,10 +395,37 @@ def test_commit_2(sample_note) -> None: """ note = Note(note_path=sample_note, dry_run=True) note.sub(pattern="Heading 1", replacement="Heading 2") - note.commit() - note = Note(note_path=sample_note) - assert "Heading 1" in note.file_content + + assert "Heading 2" in note.file_content + assert "Heading 1" in sample_note.read_text() + + +def test_commit_3(tmp_path) -> None: + """Test that commit() method preserves encoding. + + GIVEN a file in CP1250 encoding + WHEN the file is written to + THEN the file is output in its original encoding. + """ + source_file: Path = Path("tests/fixtures/CP1250.md") + dest_file: Path = Path(tmp_path / source_file.name) + shutil.copy(source_file, dest_file) + + # Assert that the file is in CP1250 encoding + assert from_path(dest_file).best().encoding == "cp1250" + + # Create the note object + note = Note(note_path=dest_file) + assert note.encoding == "cp1250" + + # Modify and commit the note + note.sub(pattern="Heading 1", replacement="Heading 2") + note.commit() + + # Assert that the file is still in CP1250 encoding + assert from_path(dest_file).best().encoding == "cp1250" + assert "Heading 2" in dest_file.read_text(encoding="cp1250") @pytest.mark.parametrize( @@ -439,8 +479,6 @@ def test_commit_2(sample_note) -> None: (MetadataType.ALL, None, r"^\d+", True, False), (MetadataType.ALL, "frontmatter1", "foo", False, True), (MetadataType.ALL, r"^f\w+1", r"[a-z]{3}", True, True), - (MetadataType.ALL, "frontmatter1", "foo", False, True), - (MetadataType.ALL, r"^f\w+1", r"[a-z]{3}", True, True), (MetadataType.ALL, "inline1", "foo", False, True), (MetadataType.ALL, r"^i\w+1", r"[a-z]{3}", True, True), (MetadataType.ALL, None, "#tag1", False, True), @@ -563,7 +601,6 @@ def test_delete_metadata_2(sample_note, meta_type, key, value, is_regex): (MetadataType.META, r"\d{8}", None, True), (MetadataType.FRONTMATTER, r"\d{8}", None, True), (MetadataType.INLINE, r"\d{8}", None, True), - (MetadataType.META, r"\d{8}", None, True), (MetadataType.META, "frontmatter1", r"\d{8}", True), (MetadataType.FRONTMATTER, "frontmatter1", r"\d{8}", True), (MetadataType.INLINE, "inline1", r"\d{8}", True), @@ -835,7 +872,7 @@ def test_transpose_metadata_1(sample_note, begin, end, key, value, location): None, None, InsertLocation.BOTTOM, - "```\n\ninline1:: bar baz\ninline1:: foo\ninline2:: [[foo]]\ninline3:: value\ninline4:: foo\ninline5::\nintext1:: foo\nintext2:: foo\nkey with space:: foo\n🌱:: 🌿", + "```\n\nfrench2:: Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.\ninline1:: bar baz\ninline1:: foo\ninline2:: [[foo]]\ninline3:: value\ninline4:: foo\ninline5::\nintext1:: foo\nintext2:: foo\nkey with space:: foo\n🌱:: 🌿", ), ], ) @@ -978,7 +1015,7 @@ no frontmatter ) new_note = """\ --- -key: value +french: Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis. --- # Header1 @@ -986,7 +1023,11 @@ inline:: only no frontmatter """ note = Note(note_path=note_path) - note.add_metadata(meta_type=MetadataType.FRONTMATTER, added_key="key", added_value="value") + note.add_metadata( + meta_type=MetadataType.FRONTMATTER, + added_key="french", + added_value="Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.", + ) assert note.write_frontmatter() is True assert note.file_content == new_note diff --git a/tests/vault_test.py b/tests/vault_test.py index 59b45a0..a6c4d50 100644 --- a/tests/vault_test.py +++ b/tests/vault_test.py @@ -31,12 +31,18 @@ def test_vault_creation(test_vault, tmp_path): assert len(vault.all_notes) == 2 assert vault.frontmatter == { "date_created": ["2022-12-22"], + "french1": [ + "Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis", + ], "frontmatter1": ["foo"], "frontmatter2": ["bar", "baz", "qux"], "tags": ["bar", "foo"], "🌱": ["🌿"], } assert vault.inline_meta == { + "french2": [ + "Voix ambiguë d'un cœur qui, au zéphyr, préfère les jattes de kiwis.", + ], "inline1": ["bar baz", "foo"], "inline2": ["[[foo]]"], "inline3": ["value"],