Added test for main function, template and json for running test
This commit is contained in:
parent
7b2d7e1946
commit
e4737ddfbb
21
tests/main.py
Normal file
21
tests/main.py
Normal 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.')
|
||||||
|
|
||||||
8
tests/templates/json_for_main_test.json
Normal file
8
tests/templates/json_for_main_test.json
Normal 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}
|
||||||
BIN
tests/templates/template_for_main_test.docx
Normal file
BIN
tests/templates/template_for_main_test.docx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user