xonsh/tests/test_news.py

64 lines
2 KiB
Python
Raw Normal View History

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
2016-07-05 14:42:18 -04:00
from xonsh.platform import scandir
2016-09-05 22:49:11 +03:00
2016-09-05 14:33:42 +03:00
NEWSDIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'news')
2016-07-05 14:42:18 -04:00
CATEGORIES = frozenset(['Added', 'Changed', 'Deprecated', 'Removed',
'Fixed', 'Security'])
2016-09-13 23:03:55 -04:00
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
if '`' in l:
if single_grave_reg.search(l):
pytest.fail("{}:{}: single grave accents"
" are not valid rst".format(name, i+1),
pytrace=False)
# determine the form of line
if l.startswith('**'):
2018-06-06 12:34:30 +05:30
cat = l[2:].rsplit(':')[0]
if cat not in CATEGORIES:
2016-09-05 22:36:12 +03:00
pytest.fail('{}:{}: {!r} not a proper category '
'must be one of {}'
''.format(name, i+1, cat, list(CATEGORIES)),
pytrace=False)
2018-07-14 13:40:04 -05:00
if l.endswith('None'):
2018-06-06 12:28:23 +05:30
form += '3'
2016-07-05 14:42:18 -04:00
else:
2018-06-06 12:28:23 +05:30
form += '2'
2018-07-14 13:40:04 -05:00
elif l.startswith('* ') or l.startswith('- ') or l.startswith(' '):
2018-06-06 12:28:23 +05:30
form += '1'
elif l.strip() == '':
form += '0'
2016-07-05 14:42:18 -04:00
else:
2018-06-06 12:28:23 +05:30
pytest.fail('{}:{}: invalid rst'.format(name, i+1),
pytrace=False)
# The file should have:
# empty lines around categories
# at least one content line in a non null category
2018-06-06 13:51:45 +05:30
reg = re.compile(r'^(3(0|$)|201(1|0)*0)+$')
2018-06-06 12:28:23 +05:30
if not reg.match(form):
2018-06-06 12:43:55 +05:30
pytest.fail('{}: invalid rst'.format(name),
2018-06-06 12:28:23 +05:30
pytrace=False)
2016-07-05 14:42:18 -04:00
2016-09-05 14:33:42 +03:00
@pytest.mark.parametrize('fname', list(scandir(NEWSDIR)))
def test_news(fname):
base, ext = os.path.splitext(fname.path)
assert 'rst' in ext
2016-09-05 22:36:12 +03:00
check_news_file(fname)