Improve test coverage, docs, and .gitignore

This commit is contained in:
boxydog 2024-06-01 18:13:05 -05:00
commit b77bb690e2
5 changed files with 73 additions and 3 deletions

View file

@ -1,2 +1,4 @@
[report] [report]
omit = pelican/tests/* omit =
pelican/tests/*
pelican/signals.py

6
.gitignore vendored
View file

@ -18,3 +18,9 @@ samples/output
*.lock *.lock
.pdm-python .pdm-python
.venv .venv
# direnv
.envrc
# pycharm
.idea

View file

@ -64,6 +64,20 @@ your bug fix or feature::
Now you can make changes to Pelican, its documentation, and/or other aspects of Now you can make changes to Pelican, its documentation, and/or other aspects of
the project. the project.
Setting up git blame
--------------------
``git blame`` annotates lines from a file with information about the pull request
that last modified it. Sweeping shallow changes (like formatting) can make that
information less useful, so we keep a list of such changes to be ignored. To set
that up in your repository::
git config blame.ignoreRevsFile .git-blame-ignore-revs
For more information, see here_.
.. _here: https://www.michaelheap.com/git-ignore-rev/
Running the test suite Running the test suite
---------------------- ----------------------
@ -108,6 +122,20 @@ environments.
.. _Tox: https://tox.readthedocs.io/en/latest/ .. _Tox: https://tox.readthedocs.io/en/latest/
Running a code coverage report
------------------------------
The code is more likely to stay robust if it is tested.
coverage_ is a library that measures how much of the code is tested.
To run it::
invoke coverage
open htmlcov/index.html
The HTML will show overall coverage, coverage per file, and even line-by-line coverage.
.. _coverage: https://github.com/nedbat/coveragepy
Building the docs Building the docs
----------------- -----------------

View file

@ -0,0 +1 @@
../content/article_with_md_extension.md

View file

@ -1,3 +1,5 @@
import contextlib
import io
import locale import locale
import logging import logging
import os import os
@ -6,9 +8,12 @@ import sys
import unittest import unittest
from collections.abc import Sequence from collections.abc import Sequence
from shutil import rmtree from shutil import rmtree
from tempfile import mkdtemp from tempfile import TemporaryDirectory, mkdtemp
from unittest.mock import patch
from pelican import Pelican from rich.console import Console
from pelican import Pelican, __version__, main
from pelican.generators import StaticGenerator from pelican.generators import StaticGenerator
from pelican.settings import read_settings from pelican.settings import read_settings
from pelican.tests.support import ( from pelican.tests.support import (
@ -271,3 +276,31 @@ class TestPelican(LoggedTestCase):
[sys.executable, "-m", "pelican", "--help"] [sys.executable, "-m", "pelican", "--help"]
).decode("ascii", "replace") ).decode("ascii", "replace")
assert "usage:" in output assert "usage:" in output
def test_main_version(self):
"""Run main --version."""
out = io.StringIO()
with contextlib.redirect_stdout(out):
with self.assertRaises(SystemExit):
main(["--version"])
self.assertEqual(f"{__version__}\n", out.getvalue())
def test_main_help(self):
"""Run main --help."""
out = io.StringIO()
with contextlib.redirect_stdout(out):
with self.assertRaises(SystemExit):
main(["--help"])
self.assertIn("A tool to generate a static blog", out.getvalue())
def test_main_on_content(self):
"""Invoke main on simple_content directory."""
out, err = io.StringIO(), io.StringIO()
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
with TemporaryDirectory() as temp_dir:
# Don't highlight anything.
# See https://rich.readthedocs.io/en/stable/highlighting.html
with patch("pelican.console", new=Console(highlight=False)):
main(["-o", temp_dir, "pelican/tests/simple_content"])
self.assertIn("Processed 1 article", out.getvalue())
self.assertEqual("", err.getvalue())