Skip to content

Commit 6805a2c

Browse files
- Manual testing works.
1 parent 41c1c15 commit 6805a2c

File tree

1 file changed

+55
-19
lines changed

1 file changed

+55
-19
lines changed

test/python/markdown_testing/markdown_testing.py

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __init__(self, node: ASTNode):
127127
def _contains_nonempty_table(self, s: str) -> bool:
128128
required_run_length: int = 5
129129
lines = s.split('\n')
130-
print(f'lines: {lines}')
130+
# print(f'lines: {lines}')
131131
if len(lines) < required_run_length:
132132
return False
133133
run_length: int = 0
@@ -207,7 +207,7 @@ def orchestrate(self, file_path: str) -> WorkloadDTO:
207207
teardown_count: int = 0
208208
invocation_count: int = 0
209209
ast = self._parser.parse_markdown_file(file_path)
210-
print(f'AST: {ast}')
210+
# print(f'AST: {ast}')
211211
setup_str: str = f'cd {_REPOSITORY_ROOT_PATH};\n'
212212
in_session_commands: List[str] = []
213213
teardown_str: str = f'cd {_REPOSITORY_ROOT_PATH};\n'
@@ -246,7 +246,7 @@ def __init__(self, stdout_str :str, stderr_str :str, rc :int) -> None:
246246
self.stderr :str = stderr_str
247247
self.rc = rc
248248

249-
class SimpleE2E(object):
249+
class SimpleRunner(object):
250250

251251
def __init__(self, workload: WorkloadDTO):
252252
self._workload = workload
@@ -264,24 +264,60 @@ def run(self) -> Tuple[bytes, bytes]:
264264
for cmd in self._workload.get_in_session():
265265
pr.stdin.write(f"{cmd}\n".encode(sys.getdefaultencoding()))
266266
pr.stdin.flush()
267-
stdoout_bytes, stderr_bytes = pr.communicate()
268-
return WalkthroughResult(stdoout_bytes.decode(sys.getdefaultencoding()) , stderr_bytes.decode(sys.getdefaultencoding()), pr.returncode)
267+
stdout_bytes, stderr_bytes = pr.communicate()
268+
269+
stdout_str: str = stdout_bytes.decode(sys.getdefaultencoding())
270+
stderr_str: str = stderr_bytes.decode(sys.getdefaultencoding())
271+
272+
for expectation in self._workload.get_expectations():
273+
print(f'Expectation: {expectation}')
274+
print(f'Passes stdout: {expectation.passes_stdout(stdout_str)}')
275+
print(f'Passes stderr: {expectation.passes_stderr(stderr_str)}')
276+
print('---')
277+
return WalkthroughResult(stdout_str, stderr_str, pr.returncode)
278+
279+
class AllWalkthroughsRunner(object):
280+
281+
def __init__(self):
282+
md_parser = MdParser()
283+
self._orchestrator: MdOrchestrator = MdOrchestrator(md_parser)
284+
285+
def run_all(self, walkthrough_inodes: List[str], recursive=True) -> List[WalkthroughResult]:
286+
results: List[WalkthroughResult] = []
287+
for inode_path in walkthrough_inodes:
288+
is_dir = os.path.isdir(inode_path)
289+
if is_dir:
290+
for root, dirs, files in os.walk(inode_path):
291+
for file in files:
292+
file_path = os.path.join(root, file)
293+
print(f'File path: {file_path}')
294+
workload: WorkloadDTO = self._orchestrator.orchestrate(file_path)
295+
e2e: SimpleRunner = SimpleRunner(workload)
296+
result = e2e.run()
297+
results.append(result)
298+
if recursive:
299+
for dir in dirs:
300+
dir_path = os.path.join(root, dir)
301+
results += self.run_all([dir_path], recursive)
302+
continue
303+
is_file = os.path.isfile(inode_path)
304+
if is_file:
305+
file_path = inode_path
306+
workload: WorkloadDTO = self._orchestrator.orchestrate(file_path)
307+
e2e: SimpleRunner = SimpleRunner(workload)
308+
result = e2e.run()
309+
results.append(result)
310+
continue
311+
raise FileNotFoundError(f'Path not tractable: {inode_path}')
312+
return results
269313

270314
def main():
271-
md_parser = MdParser()
272-
orchestrator: MdOrchestrator = MdOrchestrator(md_parser)
273-
workload_dto: WorkloadDTO = orchestrator.orchestrate(os.path.join(_REPOSITORY_ROOT_PATH, 'docs', 'walkthroughs', 'get-google-vms.md'))
274-
print(f'Workload DTO: {workload_dto}')
275-
# print(json.dumps(parsed_file, indent=2))
276-
e2e: SimpleE2E = SimpleE2E(workload_dto)
277-
result: WalkthroughResult = e2e.run()
278-
print(result.stdout)
279-
print(result.stderr)
280-
for expectation in workload_dto.get_expectations():
281-
print(f'Expectation: {expectation}')
282-
print(f'Passes stdout: {expectation.passes_stdout(result.stdout)}')
283-
print(f'Passes stderr: {expectation.passes_stderr(result.stderr)}')
284-
print('---')
315+
runner: AllWalkthroughsRunner = AllWalkthroughsRunner()
316+
results: List[WalkthroughResult] = runner.run_all([os.path.join(_REPOSITORY_ROOT_PATH, 'docs', 'walkthroughs')])
317+
for result in results:
318+
print(f'RC: {result.rc}')
319+
print(f'STDOUT: {result.stdout}')
320+
print(f'STDERR: {result.stderr}')
285321

286322
if __name__ == '__main__':
287323
main()

0 commit comments

Comments
 (0)