Allow ignoring OS-specific tests in run_tests script

This commit is contained in:
Veronica Berglyd Olsen
2026-07-02 19:16:52 +02:00
parent 4347021572
commit cd9244f0dd
4 changed files with 38 additions and 2 deletions

1
.gitignore vendored
View File

@@ -56,6 +56,7 @@ ToC.txt
# Coverage
/.coverage
/.coveragerc
/coverage.*
# Other

View File

@@ -172,4 +172,3 @@ source = ["novelwriter"]
[tool.coverage.report]
precision = 2
exclude_also = ["if TYPE_CHECKING:"]

View File

@@ -7,6 +7,36 @@ import shlex
import subprocess
import sys
from pathlib import Path
def _genCoverageConfig(path: Path) -> None:
"""Generate a config file for coverage.py."""
exclude = [] # ["if TYPE_CHECKING:"]
if sys.platform != "linux":
exclude.append(r'\s*(if|elif) sys\.platform == "linux":')
exclude.append(r"\s*(if|elif) (CONFIG|self)\.osLinux")
if sys.platform != "darwin":
exclude.append(r'\s*(if|elif) sys\.platform == "darwin":')
exclude.append(r"\s*(if|elif) (CONFIG|self)\.osDarwin")
if sys.platform != "win32":
exclude.append(r'\s*(if|elif) sys\.platform == "win32":')
exclude.append(r"\s*(if|elif) (CONFIG|self)\.osWindows")
config = [
"[run]",
"branch = false",
"source = novelwriter",
"",
"[report]",
"precision = 2",
"exclude_also =",
]
config.extend(f" {ex}" for ex in exclude)
path.write_text("\n".join(config), encoding="utf-8")
if __name__ == "__main__":
"""Parse command line options and run the commands."""
parser = argparse.ArgumentParser(usage="run_tests.py [--flags]")
@@ -14,6 +44,7 @@ if __name__ == "__main__":
parser.add_argument("-r", action="store_true", help="Generate reports")
parser.add_argument("-t", action="store_true", help="Generate terminal report")
parser.add_argument("-u", action="store_true", help="Generate uncovered terminal report")
parser.add_argument("-x", action="store_true", help="Ignore OS-specific tests in reports")
parser.add_argument("-lf", action="store_true", help="Re-run failed tests")
parser.add_argument("-sw", action="store_true", help="Run tests stepwise")
parser.add_argument("-m", help="Test modules", metavar="MARKEXPR")
@@ -23,8 +54,11 @@ if __name__ == "__main__":
env = os.environ.copy()
env["QT_SCALE_FACTOR"] = "1.0"
tmpConf = Path(__file__).parent / ".coveragerc"
if args.r or args.t or args.u:
if args.x:
_genCoverageConfig(tmpConf)
cmd = ["coverage", "run"]
if args.lf or args.sw:
cmd += ["--append"]
@@ -54,3 +88,5 @@ if __name__ == "__main__":
subprocess.call(["coverage", "report"])
if args.u:
subprocess.call(["coverage", "report", "--skip-covered"])
tmpConf.unlink(missing_ok=True)

View File

@@ -33,7 +33,7 @@ from novelwriter import logger
XML_IGNORE = ("<novelWriterXML", "<project")
ODT_IGNORE = ("<meta:generator", "<meta:creation-date", "<dc:date", "<meta:editing")
EPUB_IGNORE = ('<meta property="dcterms:date">', '<meta property="dcterms:modified">')
EPUB_IGNORE = ('<meta property="dcterms:date">', '<meta property="dcterms:modified">', "<dc:date>")
NWD_IGNORE = ("%%~date:",)
DOCX_IGNORE = ("<dcterms:created", "<dcterms:modified", "<ns0:Application")
MOCK_TIME = datetime(2019, 5, 10, 18, 52, 0).timestamp()