2020-06-11 00:54:34 +02:00
|
|
|
import logging
|
2017-12-04 10:10:15 +01:00
|
|
|
import os
|
|
|
|
import subprocess
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2017-12-04 10:10:15 +01:00
|
|
|
|
2022-11-17 09:30:48 +01:00
|
|
|
class DiffError(Exception):
|
2017-12-23 21:26:09 +01:00
|
|
|
pass
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2017-12-04 10:10:15 +01:00
|
|
|
def diff_strings(output: str, expected_output: str) -> str:
|
|
|
|
|
|
|
|
mdiff_path = "frontend_tests/zjsunit/mdiff.js"
|
|
|
|
if not os.path.isfile(mdiff_path): # nocoverage
|
2020-08-11 01:47:49 +02:00
|
|
|
msg = "Cannot find mdiff for Markdown diff rendering"
|
2017-12-23 21:26:09 +01:00
|
|
|
logging.error(msg)
|
2022-11-17 09:30:48 +01:00
|
|
|
raise DiffError(msg)
|
2017-12-04 10:10:15 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
command = ["node", mdiff_path, output, expected_output]
|
2022-01-22 07:52:54 +01:00
|
|
|
diff = subprocess.check_output(command, text=True)
|
2017-12-04 10:10:15 +01:00
|
|
|
return diff
|