PK>Lbbpytest_markdown/__init__.py''' A py.test plugin that runs tests its found in your Markdown files. ''' __version__ = '0.0.3' PK/L`SSpytest_markdown/plugin.pyimport imp import pytest from _pytest.python import Module from mistletoe.base_renderer import BaseRenderer class MarkdownItem(Module): def __init__(self, name, file, code, nodeid=None): self._code_obj = imp.new_module(name) exec(code, self._code_obj.__dict__) super().__init__(name, file, nodeid=nodeid) def _getobj(self): return self._code_obj class MarkdownCollector(BaseRenderer): def __init__(self, item): super().__init__() self.item = item self.stack = [(0, self.item, self.item.name,)] self.collected = [] def render_heading(self, token): name = ''.join(self.render(c) for c in token.children).lower().replace(' ', '-') while self.stack[-1][0] >= token.level: self.stack.pop() nodeid = '::'.join(s[2] for s in self.stack) + '::' + name self.stack.append(( token.level, pytest.Item(name, self.stack[-1][1], nodeid=nodeid), name )) return '' def render_block_code(self, token): if token.language != 'python': return '' output = ''.join(c.content for c in token.children) if output.startswith('\n'): return '' name = f'line_{token.start}' if output.lower().strip().startswith('# conftest.py\n'): nodeid = self.stack[-1][1].nodeid else: nodeid = self.stack[-1][1].nodeid + '::' + name mi = MarkdownItem( name, self.stack[-1][1], output, nodeid=nodeid ) self.collected.append(mi) return '' def collect(self, token): self.render(token) return self.collected class MarkdownFile(pytest.File): def collect(self): fp = self.fspath.open() from mistletoe import Document with MarkdownCollector(self) as collector: for item in collector.collect(Document(fp)): yield item def pytest_collect_file(parent, path): if path.ext == '.md': return MarkdownFile(path, parent) PK!H-1B#,0pytest_markdown-0.0.3.dist-info/entry_points.txt.,I-.14M,N/ϳz9y\\PK!HNO%pytest_markdown-0.0.3.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,zd&Y)r$[)T&UrPK!H{Bz(pytest_markdown-0.0.3.dist-info/METADATA]S]o@|XW| -R iRDKVMD/>=# d7t^)LRcO-ݺɎl5& 2ZE!_5ES{P>ʆ!X_F m\<[j;Uy6%W-ҹQKqQ21G1`E\gO;*>]^w } r>%Є|[OL;齪n# CPrbO'V;i'^ pKn=ه`E>,n`b V}be",[@=|IV|dK25S>3K_5; c3G l l0Hx~(y8J#TJicG*/`bI5K`k~uWh.jpȮWR\{!̈q<TVC?}Gx!$;ESZd_PK!H^ 0&pytest_markdown-0.0.3.dist-info/RECORDͶB@}"-w!DMb3GLČ1ιM/}ddchUྙuLR?Ҁ[cFi*e$Kz씣p]5A]4tmB>DxխR9Pm19*VlU7ٷCI,~Sx/PǦla[\@T&jjfzՒ ˢ]1Ϫs9}۞|('\pߧӒm:WDS(Z'𐤢-oGeDƛ]e̪O^9K(Lbbpytest_markdown/__init__.pyPK/L`SSpytest_markdown/plugin.pyPK!H-1B#,0% pytest_markdown-0.0.3.dist-info/entry_points.txtPK!HNO% pytest_markdown-0.0.3.dist-info/WHEELPK!H{Bz(' pytest_markdown-0.0.3.dist-info/METADATAPK!H^ 0&r pytest_markdown-0.0.3.dist-info/RECORDPK