xonsh/tests/test_news.py

65 lines
2.4 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()
nlines = len(lines)
for i, line in enumerate(lines):
if line.startswith('**'):
2016-09-05 14:33:42 +03:00
cat, *_ = line[2:].rsplit(':')
2016-09-05 22:36:12 +03:00
if cat not in CATEGORIES:
pytest.fail('{}:{}: {!r} not a proper category '
'must be one of {}'
''.format(name, i+1, cat, list(CATEGORIES)),
pytrace=False)
2016-07-05 14:42:18 -04:00
if i+1 == nlines:
continue
2016-09-05 22:36:12 +03:00
if not lines[i+1].strip() == '':
pytest.fail('{}:{}: empty line required after category'
''.format(name, i+1), pytrace=False)
if i > 0 and not lines[i-1].strip() == '':
pytest.fail('{}:{}: empty line required before category'
''.format(name, i+1), pytrace=False)
2016-07-05 14:42:18 -04:00
if line.endswith('None'):
2016-09-05 22:36:12 +03:00
if not lines[i+2].startswith('**'):
pytest.fail("{}:{}: can't have entries after None"
''.format(name, i+1), pytrace=False)
2016-07-05 14:42:18 -04:00
else:
2016-09-05 22:36:12 +03:00
if lines[i+2].startswith('**'):
pytest.fail("{}:{}: must have entry if not None"
''.format(name, i+1), pytrace=False)
2016-07-05 14:42:18 -04:00
else:
2016-09-05 22:36:12 +03:00
if not (line.startswith('* ')
2016-09-05 14:33:42 +03:00
or line.startswith(' ')
2016-09-05 22:36:12 +03:00
or (line.strip() == '')):
pytest.fail('{}:{}: invalid rst'.format(name, i+1),
pytrace=False)
2016-09-05 21:27:06 +03:00
if '`' in line:
2016-09-13 23:24:14 -04:00
if single_grave_reg.search(line):
2016-09-05 22:36:12 +03:00
pytest.fail("{}:{}: single grave accents"
" are not valid rst".format(name, i+1),
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)