|
7 | 7 | import shutil
|
8 | 8 | import sys
|
9 | 9 |
|
10 |
| -from doc8.main import main, doc8 |
| 10 | +from doc8.main import main, doc8, from_toml |
11 | 11 |
|
12 | 12 |
|
13 | 13 | # Location to create test files
|
@@ -426,3 +426,43 @@ def test_args__version__overrides_default(self):
|
426 | 426 | state = main()
|
427 | 427 | self.assertEqual(state, 0)
|
428 | 428 | mock_scan.assert_not_called()
|
| 429 | + |
| 430 | + |
| 431 | +CONFIG_TOML = """\ |
| 432 | +[tool.doc8] |
| 433 | +allow-long-titles = true |
| 434 | +ignore-path-errors = ["foo.rst;D001;D002", "bar.rst;D002"] |
| 435 | +default-extension = ".rst" |
| 436 | +extension = [".rst", ".rST", ".txt", ".TXT"] |
| 437 | +ignore-path = ["baz.rst", "boff.rst"] |
| 438 | +ignore = ["D002", "D005"] |
| 439 | +max-line-length = 80 |
| 440 | +file-encoding = "utf8" |
| 441 | +sphinx = false""" |
| 442 | + |
| 443 | + |
| 444 | +class TestConfig(unittest.TestCase): |
| 445 | + """ |
| 446 | + Test that configuration file is loaded correctly |
| 447 | + """ |
| 448 | + |
| 449 | + def test_config__from_toml(self): |
| 450 | + with TmpFs() as tmpfs: |
| 451 | + tmpfs.create_file("pyproject.toml", CONFIG_TOML) |
| 452 | + cfg = from_toml(os.path.join(tmpfs.path, "pyproject.toml")) |
| 453 | + |
| 454 | + self.assertEqual(cfg["allow_long_titles"], True) |
| 455 | + self.assertEqual( |
| 456 | + cfg["ignore_path_errors"], |
| 457 | + { |
| 458 | + "foo.rst": {"D001", "D002"}, |
| 459 | + "bar.rst": {"D002"}, |
| 460 | + }, |
| 461 | + ) |
| 462 | + self.assertEqual(cfg["default_extension"], ".rst") |
| 463 | + self.assertEqual(cfg["extension"], [".rst", ".rST", ".txt", ".TXT"]) |
| 464 | + self.assertEqual(cfg["ignore_path"], ["baz.rst", "boff.rst"]) |
| 465 | + self.assertEqual(cfg["ignore"], ["D002", "D005"]) |
| 466 | + self.assertEqual(cfg["max_line_length"], 80) |
| 467 | + self.assertEqual(cfg["file_encoding"], "utf8") |
| 468 | + self.assertEqual(cfg["sphinx"], False) |
0 commit comments