66
77from mdformat ._cli import run
88from mdformat ._conf import read_toml_opts
9+ from tests .test_cli import FORMATTED_MARKDOWN , UNFORMATTED_MARKDOWN
910
1011
1112def test_cli_override (tmp_path ):
1213 config_path = tmp_path / ".mdformat.toml"
13- config_path .write_text ("wrap = 'no'" )
14+ config_path .write_text ("wrap = 'no'\n end_of_line = 'lf' " )
1415
1516 file_path = tmp_path / "test_markdown.md"
1617 file_path .write_text ("remove\n this\n wrap\n " )
@@ -65,9 +66,13 @@ def test_invalid_toml(tmp_path, capsys):
6566 ("wrap" , "wrap = -3" ),
6667 ("end_of_line" , "end_of_line = 'lol'" ),
6768 ("number" , "number = 0" ),
69+ ("exclude" , "exclude = '**'" ),
70+ ("exclude" , "exclude = ['1',3]" ),
6871 ],
6972)
7073def test_invalid_conf_value (bad_conf , conf_key , tmp_path , capsys ):
74+ if conf_key == "exclude" and sys .version_info < (3 , 13 ):
75+ pytest .skip ("exclude conf only on Python 3.13+" )
7176 config_path = tmp_path / ".mdformat.toml"
7277 config_path .write_text (bad_conf )
7378
@@ -91,3 +96,53 @@ def test_conf_with_stdin(tmp_path, capfd, monkeypatch):
9196 assert run (("-" ,)) == 0
9297 captured = capfd .readouterr ()
9398 assert captured .out == "1. one\n 2. two\n 3. three\n "
99+
100+
101+ @pytest .mark .skipif (
102+ sys .version_info >= (3 , 13 ), reason = "'exclude' only possible on 3.13+"
103+ )
104+ def test_exclude_conf_on_old_python (tmp_path , capsys ):
105+ config_path = tmp_path / ".mdformat.toml"
106+ config_path .write_text ("exclude = ['**']" )
107+
108+ file_path = tmp_path / "test_markdown.md"
109+ file_path .write_text ("# Test Markdown" )
110+
111+ assert run ((str (file_path ),)) == 1
112+ assert "only available on Python 3.13+" in capsys .readouterr ().err
113+
114+
115+ @pytest .mark .skipif (
116+ sys .version_info < (3 , 13 ), reason = "'exclude' only possible on 3.13+"
117+ )
118+ def test_exclude (tmp_path , capsys ):
119+ config_path = tmp_path / ".mdformat.toml"
120+ config_path .write_text ("exclude = ['dir1/*', 'file1.md']" )
121+
122+ dir1_path = tmp_path / "dir1"
123+ file1_path = tmp_path / "file1.md"
124+ file2_path = tmp_path / "file2.md"
125+ file3_path = tmp_path / dir1_path / "file3.md"
126+ dir1_path .mkdir ()
127+ file1_path .write_text (UNFORMATTED_MARKDOWN )
128+ file2_path .write_text (UNFORMATTED_MARKDOWN )
129+ file3_path .write_text (UNFORMATTED_MARKDOWN )
130+
131+ assert run ((str (tmp_path ),)) == 0
132+ assert file1_path .read_text () == UNFORMATTED_MARKDOWN
133+ assert file2_path .read_text () == FORMATTED_MARKDOWN
134+ assert file3_path .read_text () == UNFORMATTED_MARKDOWN
135+
136+
137+ @pytest .mark .skipif (
138+ sys .version_info < (3 , 13 ), reason = "'exclude' only possible on 3.13+"
139+ )
140+ def test_empty_exclude (tmp_path , capsys ):
141+ config_path = tmp_path / ".mdformat.toml"
142+ config_path .write_text ("exclude = []" )
143+
144+ file1_path = tmp_path / "file1.md"
145+ file1_path .write_text (UNFORMATTED_MARKDOWN )
146+
147+ assert run ((str (tmp_path ),)) == 0
148+ assert file1_path .read_text () == FORMATTED_MARKDOWN
0 commit comments