Added test for main function, template and json for running test

This commit is contained in:
Lucas 2021-09-30 09:41:58 -03:00
parent 7b2d7e1946
commit e4737ddfbb
3 changed files with 29 additions and 0 deletions

21
tests/main.py Normal file
View File

@ -0,0 +1,21 @@
from docxtpl.__main__ import main
import sys
from pathlib import Path
TEMPLATE_PATH = 'templates/template_for_main_test.docx'
JSON_PATH = 'templates/json_for_main_test.json'
OUTPUT_FILENAME = 'output/output_for_main_test.docx'
OVERWRITE = '-o'
# Simulate command line arguments, running with overwrite flag so test can be
# run repeatedly without need for confirmation:
sys.argv[1:] = [TEMPLATE_PATH, JSON_PATH, OUTPUT_FILENAME, OVERWRITE]
main()
output_path = Path(OUTPUT_FILENAME)
if output_path.exists():
print(f'File {output_path.resolve()} exists.')

View File

@ -0,0 +1,8 @@
{"json_dict_var" : {"json_dict_var":"successfully inserted"},
"json_array_var": ["json","array","var","successfully", "inserted"],
"json_string_var":"json_string_var successfully inserted",
"json_int_var":123,
"json_float_var":1.234,
"json_true_var":true,
"json_false_var":false,
"json_none_var":null}

Binary file not shown.