Skip to content
Open
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ repos:
hooks:
- id: absolufy-imports
- repo: https://github.com/PyCQA/isort
rev: c8ab4a5b21bac924d106e3103dd7c979fdd0f9bc # frozen: 6.0.1
rev: a333737ed43df02b18e6c95477ea1b285b3de15a # frozen: 8.0.1
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 8a737e727ac5ab2f1d4cf5876720ed276dc8dc4b # frozen: 25.1.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: fa505ab9c3e0fedafe1709fd7ac2b5f8996c670d # frozen: 26.3.1
hooks:
- id: black
- repo: https://github.com/hukkin/docformatter
Expand All @@ -43,6 +43,6 @@ repos:
- flake8-builtins
- flake8-comprehensions
- repo: https://github.com/pre-commit/pre-commit
rev: b74a22d96cca546b8e0bb9f68f1d7d8565205b65 # frozen: v4.3.0
rev: 8a0630ca1aa7f6d5665effe674ebe2022af17919 # frozen: v4.5.1
hooks:
- id: validate_manifest
5 changes: 1 addition & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,12 @@ def test_get_plugin_info_str():
{"mdformat-tables": ("0.1.0", ["tables"])},
{"mdformat-black": ("12.1.0", ["python"])},
)
assert (
info
== """\
assert info == """\
installed codeformatters:
mdformat-black: python

installed extensions:
mdformat-tables: tables"""
)


def test_no_timestamp_modify(tmp_path):
Expand Down
102 changes: 34 additions & 68 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,18 @@ def fmt_func(code, info):

monkeypatch.setitem(CODEFORMATTERS, "lang", fmt_func)
text = mdformat.text(
dedent(
"""\
dedent("""\
```lang
a
```
"""
),
"""),
codeformatters={"lang"},
)
assert text == dedent(
"""\
assert text == dedent("""\
```lang
dummy
```
"""
)
""")


def test_code_formatter__empty_str(monkeypatch):
Expand All @@ -55,22 +51,18 @@ def fmt_func(code, info):

monkeypatch.setitem(CODEFORMATTERS, "lang", fmt_func)
text = mdformat.text(
dedent(
"""\
dedent("""\
~~~lang
aag
gw
~~~
"""
),
"""),
codeformatters={"lang"},
)
assert text == dedent(
"""\
assert text == dedent("""\
```lang
```
"""
)
""")


def test_code_formatter__no_end_newline(monkeypatch):
Expand All @@ -79,22 +71,18 @@ def fmt_func(code, info):

monkeypatch.setitem(CODEFORMATTERS, "lang", fmt_func)
text = mdformat.text(
dedent(
"""\
dedent("""\
```lang
```
"""
),
"""),
codeformatters={"lang"},
)
assert text == dedent(
"""\
assert text == dedent("""\
```lang
dummy
dum
```
"""
)
""")


def test_code_formatter__interface(monkeypatch):
Expand All @@ -103,73 +91,61 @@ def fmt_func(code, info):

monkeypatch.setitem(CODEFORMATTERS, "lang", fmt_func)
text = mdformat.text(
dedent(
"""\
dedent("""\
``` lang long
multi
mul
```
"""
),
"""),
codeformatters={"lang"},
)
assert text == dedent(
"""\
assert text == dedent("""\
```lang long
lang longmulti
mul
multi
mul
```
"""
)
""")


def test_single_token_extension(monkeypatch):
"""Test the front matter plugin, as a single token extension example."""
plugin_name = "text_editor"
monkeypatch.setitem(PARSER_EXTENSIONS, plugin_name, TextEditorPlugin)
text = mdformat.text(
dedent(
"""\
dedent("""\
# Example Heading

Example paragraph.
"""
),
"""),
extensions=[plugin_name],
)
assert text == dedent(
"""\
assert text == dedent("""\
# All text is like this now!

All text is like this now!
"""
)
""")


def test_table(monkeypatch):
"""Test the table plugin, as a multi-token extension example."""
monkeypatch.setitem(PARSER_EXTENSIONS, "table", TablePlugin)
text = mdformat.text(
dedent(
"""\
dedent("""\
|a|b|
|-|-|
|c|d|

other text
"""
),
"""),
extensions=["table", "table"],
)
assert text == dedent(
"""\
assert text == dedent("""\
dummy 21

other text
"""
)
""")


class ExamplePluginWithGroupedCli:
Expand Down Expand Up @@ -198,14 +174,12 @@ def test_cli_options_group(monkeypatch, tmp_path):
file_path = tmp_path / "test_markdown.md"
conf_path = tmp_path / ".mdformat.toml"
file_path.touch()
conf_path.write_text(
"""\
conf_path.write_text("""\
[plugin.table]
override_toml = 'failed'
toml_only = true
dont_override_toml = 'dont override this with None if CLI opt not given'
"""
)
""")

with patch.object(MDRenderer, "render", return_value="") as mock_render:
assert (
Expand Down Expand Up @@ -365,22 +339,18 @@ def test_postprocess_plugins(monkeypatch):
monkeypatch.setitem(PARSER_EXTENSIONS, suffix_plugin_name, SuffixPostprocessPlugin)
monkeypatch.setitem(PARSER_EXTENSIONS, prefix_plugin_name, PrefixPostprocessPlugin)
text = mdformat.text(
dedent(
"""\
dedent("""\
# Example Heading.

Example paragraph.
"""
),
"""),
extensions=[suffix_plugin_name, prefix_plugin_name],
)
assert text == dedent(
"""\
assert text == dedent("""\
# Prefixed!Example Heading.Suffixed!

Prefixed!Example paragraph.Suffixed!
"""
)
""")


def test_load_entrypoints(tmp_path, monkeypatch):
Expand All @@ -392,20 +362,16 @@ def test_load_entrypoints(tmp_path, monkeypatch):
metadata_path = dist_info_path / "METADATA"
# The modules here will get loaded so use ones we know will always exist
# (even though they aren't actual extensions).
entry_points_path.write_text(
"""\
entry_points_path.write_text("""\
[mdformat.parser_extension]
ext1=mdformat.plugins
ext2=mdformat.plugins
"""
)
metadata_path.write_text(
"""\
""")
metadata_path.write_text("""\
Metadata-Version: 2.1
Name: mdformat-gfm
Version: 0.3.6
"""
)
""")
distro = importlib.metadata.PathDistribution(dist_info_path)
entrypoints = distro.entry_points

Expand Down
Loading