2016-07-05 14:42:18 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Testing that news entries are well formed."""
|
|
|
|
import os
|
2016-09-05 21:27:06 +03:00
|
|
|
import re
|
2016-07-05 14:42:18 -04:00
|
|
|
|
2016-09-05 22:49:11 +03:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2018-08-30 09:18:49 -05:00
|
|
|
NEWSDIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "news")
|
2016-09-05 14:33:42 +03:00
|
|
|
|
2018-08-30 09:18:49 -05:00
|
|
|
CATEGORIES = frozenset(
|
|
|
|
["Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"]
|
|
|
|
)
|
|
|
|
|
|
|
|
single_grave_reg = re.compile(r"[^`]`[^`]+`[^`_]")
|
2016-07-05 14:42:18 -04:00
|
|
|
|
|
|
|
|
|
|
|
def check_news_file(fname):
|
2016-09-05 22:36:12 +03:00
|
|
|
name = fname.name
|
|
|
|
with open(fname.path) as f:
|
2016-07-05 14:42:18 -04:00
|
|
|
lines = f.read().splitlines()
|
2018-06-06 12:28:23 +05:30
|
|
|
form = ""
|
|
|
|
for i, l in enumerate(lines):
|
|
|
|
# search the graves
|
2018-08-30 09:18:49 -05:00
|
|
|
if "`" in l:
|
2018-06-06 12:28:23 +05:30
|
|
|
if single_grave_reg.search(l):
|
2018-08-30 09:18:49 -05:00
|
|
|
pytest.fail(
|
|
|
|
"{}:{}: single grave accents"
|
|
|
|
" are not valid rst".format(name, i + 1),
|
2018-12-22 12:00:22 -08:00
|
|
|
pytrace=True,
|
2018-08-30 09:18:49 -05:00
|
|
|
)
|
2018-06-06 12:28:23 +05:30
|
|
|
|
|
|
|
# determine the form of line
|
2018-08-30 09:18:49 -05:00
|
|
|
if l.startswith("**"):
|
|
|
|
cat = l[2:].rsplit(":")[0]
|
2018-06-06 12:34:30 +05:30
|
|
|
if cat not in CATEGORIES:
|
2018-08-30 09:18:49 -05:00
|
|
|
pytest.fail(
|
|
|
|
"{}:{}: {!r} not a proper category "
|
|
|
|
"must be one of {}"
|
|
|
|
"".format(name, i + 1, cat, list(CATEGORIES)),
|
2018-12-22 12:00:22 -08:00
|
|
|
pytrace=True,
|
2018-08-30 09:18:49 -05:00
|
|
|
)
|
|
|
|
if l.endswith("None"):
|
|
|
|
form += "3"
|
2016-07-05 14:42:18 -04:00
|
|
|
else:
|
2018-08-30 09:18:49 -05:00
|
|
|
form += "2"
|
2018-10-20 14:12:09 -06:00
|
|
|
elif l.startswith("* <news item>"):
|
2018-10-20 14:07:18 -06:00
|
|
|
form += "4"
|
2018-08-30 09:18:49 -05:00
|
|
|
elif l.startswith("* ") or l.startswith("- ") or l.startswith(" "):
|
|
|
|
form += "1"
|
|
|
|
elif l.strip() == "":
|
|
|
|
form += "0"
|
2016-07-05 14:42:18 -04:00
|
|
|
else:
|
2018-12-22 12:00:22 -08:00
|
|
|
pytest.fail("{}:{}: invalid rst".format(name, i + 1), pytrace=True)
|
2018-06-06 12:28:23 +05:30
|
|
|
# The file should have:
|
|
|
|
# empty lines around categories
|
|
|
|
# at least one content line in a non null category
|
2018-10-20 14:07:18 -06:00
|
|
|
reg = re.compile(r"^(3(0|$)|20(1|4)(1|0|4)*0|204$)+$")
|
2018-06-06 12:28:23 +05:30
|
|
|
if not reg.match(form):
|
2018-10-20 14:07:18 -06:00
|
|
|
print(form)
|
2018-12-22 12:00:22 -08:00
|
|
|
pytest.fail("{}: invalid rst".format(name), pytrace=True)
|
2016-07-05 14:42:18 -04:00
|
|
|
|
|
|
|
|
2021-03-01 22:26:32 +05:30
|
|
|
@pytest.mark.parametrize("fname", list(os.scandir(NEWSDIR)))
|
2016-09-05 14:33:42 +03:00
|
|
|
def test_news(fname):
|
|
|
|
base, ext = os.path.splitext(fname.path)
|
2018-08-30 09:18:49 -05:00
|
|
|
assert "rst" in ext
|
2016-09-05 22:36:12 +03:00
|
|
|
check_news_file(fname)
|