Skip to content

Commit 042c9d0

Browse files
committed
tests: ensure tests never mutate DEFAULT_OPTS or cached TOML opts
1 parent e05f2cf commit 042c9d0

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/mdformat/_cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def run(cli_args: Sequence[str], cache_toml: bool = True) -> int: # noqa: C901
5454
print_error(str(e))
5555
return 1
5656

57-
opts: Mapping = {**DEFAULT_OPTS, **toml_opts, **cli_core_opts}
57+
opts = {**DEFAULT_OPTS, **toml_opts, **cli_core_opts}
58+
59+
# Merge plugin options from CLI.
60+
# Make a copy of opts["plugin"] to not mutate DEFAULT_OPTS or cached TOML.
61+
opts["plugin"] = dict(opts["plugin"])
5862
for plugin_id, plugin_opts in cli_plugin_opts.items():
5963
if plugin_id in opts["plugin"]:
6064
opts["plugin"][plugin_id] |= plugin_opts

src/mdformat/_conf.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
import functools
44
from pathlib import Path
5+
from types import MappingProxyType
56
from typing import Mapping
67

78
from mdformat._compat import tomllib
9+
from mdformat._util import EMPTY_MAP
810

9-
DEFAULT_OPTS = {
10-
"wrap": "keep",
11-
"number": False,
12-
"end_of_line": "lf",
13-
"validate": True,
14-
"exclude": [],
15-
"plugin": {},
16-
"extensions": None,
17-
"codeformatters": None,
18-
}
11+
DEFAULT_OPTS = MappingProxyType(
12+
{
13+
"wrap": "keep",
14+
"number": False,
15+
"end_of_line": "lf",
16+
"validate": True,
17+
"exclude": (),
18+
"plugin": EMPTY_MAP,
19+
"extensions": None,
20+
"codeformatters": None,
21+
}
22+
)
1923

2024

2125
class InvalidConfError(Exception):

0 commit comments

Comments
 (0)