import json, re from pathlib import Path p = Path('output') a = (p/'article.md').read_text() m = json.loads((p/'metadata.json').read_text()) body = a.split('\n', 1)[1] clean = re.sub(r'\([^()]*`inputs/[^()]*\)', '', body) print('Article body words, whitespace count including headings/citations:', len(body.split())) print('Article body words excluding parenthetical source citations:', len(clean.split())) print('Headline characters:', len(m['headline'])) print('Excerpt words:', len(m['excerpt'].split())) print('Search description characters:', len(m['search_description'])) assert 600 <= len(body.split()) <= 800 assert 600 <= len(clean.split()) <= 800 assert 50 <= len(m['headline']) <= 70 assert len(m['excerpt'].split()) <= 45 assert 140 <= len(m['search_description']) <= 160 assert a.splitlines()[0] == '# ' + m['headline'] assert set(m) == {'headline', 'excerpt', 'search_description'} for source in set(re.findall(r'`(inputs/[^`]+)`', a)): assert Path(source).is_file(), source assert 29*3 == 87 and 29*3+12 == 99 and 29*3+(750-500)*0.08 == 107 assert (50-20)/50*100 == 60 print('PASS: lengths, metadata keys/JSON, headline consistency, cited file existence and arithmetic.')