Skip to content

Commit

Permalink
add a test for loading configuration from pyproject.toml (PyCQA#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejd committed May 17, 2022
1 parent 9a9167a commit d0ef363
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/doc8/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import shutil
import sys

from doc8.main import main, doc8
from doc8.main import main, doc8, from_toml


# Location to create test files
Expand Down Expand Up @@ -426,3 +426,43 @@ def test_args__version__overrides_default(self):
state = main()
self.assertEqual(state, 0)
mock_scan.assert_not_called()


CONFIG_TOML = """\
[tool.doc8]
allow-long-titles = true
ignore-path-errors = ["foo.rst;D001;D002", "bar.rst;D002"]
default-extension = ".rst"
extension = [".rst", ".rST", ".txt", ".TXT"]
ignore-path = ["baz.rst", "boff.rst"]
ignore = ["D002", "D005"]
max-line-length = 80
file-encoding = "utf8"
sphinx = false"""


class TestConfig(unittest.TestCase):
"""
Test that configuration file is loaded correctly
"""

def test_config__from_toml(self):
with TmpFs() as tmpfs:
tmpfs.create_file("pyproject.toml", CONFIG_TOML)
cfg = from_toml(os.path.join(tmpfs.path, "pyproject.toml"))

self.assertEqual(cfg["allow_long_titles"], True)
self.assertEqual(
cfg["ignore_path_errors"],
{
"foo.rst": {"D001", "D002"},
"bar.rst": {"D002"},
},
)
self.assertEqual(cfg["default_extension"], ".rst")
self.assertEqual(cfg["extension"], [".rst", ".rST", ".txt", ".TXT"])
self.assertEqual(cfg["ignore_path"], ["baz.rst", "boff.rst"])
self.assertEqual(cfg["ignore"], ["D002", "D005"])
self.assertEqual(cfg["max_line_length"], 80)
self.assertEqual(cfg["file_encoding"], "utf8")
self.assertEqual(cfg["sphinx"], False)

0 comments on commit d0ef363

Please sign in to comment.