xonsh/tests/test_news.py

47 lines
1.3 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 14:33:42 +03:00
import pytest
2016-09-05 21:27:06 +03:00
import re
2016-07-05 14:42:18 -04:00
from xonsh.platform import scandir
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-05 21:27:06 +03:00
single_grave_reg = re.compile(r'[^`]`[^`]+`[^`]')
2016-07-05 14:42:18 -04:00
def check_news_file(fname):
with open(fname) as f:
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-07-05 14:42:18 -04:00
assert cat in CATEGORIES
if i+1 == nlines:
continue
assert lines[i+1].strip() == ''
if line.endswith('None'):
assert lines[i+2].startswith('**')
else:
assert lines[i+2].startswith('* ')
else:
2016-09-05 21:27:06 +03:00
assert (line.startswith('* ')
2016-09-05 14:33:42 +03:00
or line.startswith(' ')
or (line.strip() == ''))
2016-09-05 21:27:06 +03:00
if '`' in line:
assert line.count('`') % 4 == 0
assert not single_grave_reg.search(line)
2016-09-05 14:33:42 +03:00
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
check_news_file(fname.path)