-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor readme generation and testing framework
- Loading branch information
1 parent
4ef45c5
commit d673580
Showing
18 changed files
with
307 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
tests/tools/__pycache__/ | ||
tests/outputs/ | ||
docs/tmp/ | ||
tools/__pycache__/ | ||
tools/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from generate_readme import split_images, combine_markdown, IMAGE_FOLDER, query_to_markdown, README_TEMPLATE_PATH, README_PATH, README_PDF_PATH | ||
from common import TypstRunner, ToolStatus, compare_files | ||
import os | ||
|
||
def check_images(split_markdown, runner, status): | ||
if type(split_markdown) == dict: | ||
name, code, after = split_markdown["name"], split_markdown["code"], split_markdown["after"] | ||
image_path = os.path.join(IMAGE_FOLDER, name + ".png") | ||
|
||
status.start_action("Checking " + image_path) | ||
output_path = runner.tmp_file_path(name + ".png") | ||
runner.compile_code(code, name + ".typ", output_path) | ||
if status.check_runner(runner): | ||
status.end_action(compare_files(image_path, output_path)) | ||
else: | ||
status.end_action(False) | ||
|
||
check_images(split_markdown["after"], runner, status) | ||
|
||
def main(): | ||
with TypstRunner() as runner, ToolStatus("Readme is up to date", "Readme is not up to date") as status: | ||
status.start_action("Compiling " + README_TEMPLATE_PATH) | ||
output_path = runner.tmp_file_path("readme.pdf") | ||
runner.compile_file(README_TEMPLATE_PATH, output_path) | ||
if status.check_runner(runner): | ||
status.end_action(compare_files(README_PDF_PATH, output_path)) | ||
else: | ||
status.end_action(False) | ||
|
||
status.start_action("Querying " + README_TEMPLATE_PATH) | ||
query_result, query_success = runner.query_file(README_TEMPLATE_PATH, "<export>") | ||
status.end_action(query_success) | ||
|
||
markdown_with_tags = query_to_markdown(query_result) | ||
split_markdown = split_images(markdown_with_tags) | ||
|
||
check_images(split_markdown, runner, status) | ||
|
||
status.start_action("Checking " + README_PATH) | ||
markdown = combine_markdown(split_markdown) | ||
with open(README_PATH) as file: | ||
status.end_action(file.read() == markdown) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from common import ToolStatus, TypstRunner, compare_files | ||
from generate_references import list_tests, input_file_path, reference_file_path, has_reference_check | ||
|
||
def main(): | ||
with TypstRunner() as runner, ToolStatus("All tests passed", "Some tests failed") as status: | ||
for test in list_tests(): | ||
status.start_action("Checking " + input_file_path(test)) | ||
output_path = runner.tmp_file_path(test + ".png") | ||
runner.compile_file(input_file_path(test), output_path) | ||
if status.check_runner(runner): | ||
if has_reference_check(test): | ||
status.end_action(compare_files(output_path, reference_file_path(test))) | ||
else: | ||
status.end_action(True) | ||
else: | ||
status.end_action(False) | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.