Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Révision | 9ddb4256ff0d33a9dd3ed56eeebbc8028591d654 (tree) |
---|---|
l'heure | 2023-09-29 18:24:40 |
Auteur | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
small refactoring
@@ -8,16 +8,24 @@ | ||
8 | 8 | from . import * |
9 | 9 | from castle.writers import RPy |
10 | 10 | |
11 | -template_dir ="./templates/" | |
12 | -t_dir = get_dirPath_of_file(__file__) / template_dir | |
11 | +my_dir = get_dirPath_of_file(__file__) | |
12 | +template_r_dir = "./templates/" | |
13 | +template_a_dir = my_dir / template_r_dir | |
13 | 14 | |
14 | 15 | def test_simpel_template(): |
15 | 16 | HW_file = 'HW_template.txt' |
16 | - | |
17 | - template = RPy.Template(template=HW_file, search_path=t_dir) | |
17 | + template = RPy.Template(template=HW_file, search_path=template_a_dir) | |
18 | 18 | out=template.render(Hello='{{Hello}}', World='{{World}}') # Generates itself |
19 | 19 | |
20 | - ref=open(t_dir / HW_file).read() | |
20 | + ref=open(template_a_dir / HW_file).read() | |
21 | + assert end_with_NL(ref) == end_with_NL(out), f"ref::\n{ref}\nout::\n{out}\nDo not match" | |
22 | + | |
23 | +def test_simpel_template_2(): | |
24 | + HW_file = 'HW_template.txt' | |
25 | + template = RPy.Template(template=HW_file, top_dir=my_dir) | |
26 | + out=template.render(Hello='{{Hello}}', World='{{World}}') # Generates itself | |
27 | + | |
28 | + ref=open(template_a_dir / HW_file).read() | |
21 | 29 | assert end_with_NL(ref) == end_with_NL(out), f"ref::\n{ref}\nout::\n{out}\nDo not match" |
22 | 30 | |
23 | 31 |
@@ -25,10 +33,10 @@ | ||
25 | 33 | child = 'child.txt' |
26 | 34 | base = 'base.txt' # Not used to render, only to test |
27 | 35 | |
28 | - template = RPy.Template(template=child, search_path=t_dir) | |
36 | + template = RPy.Template(template=child, search_path=template_a_dir) | |
29 | 37 | out = template.render(v1 ='Var 1', v2 ='Var 2', TOP='top: but not completely', BOTTOM="bottom, really") |
30 | 38 | |
31 | - ref_lines = open(t_dir / base).readlines() | |
39 | + ref_lines = open(template_a_dir / base).readlines() | |
32 | 40 | out_lines = out.splitlines(keepends=True) |
33 | 41 | |
34 | 42 | assert ref_lines[0] == out_lines[0], "Rendering child, should return the topline of base" |
@@ -44,7 +52,7 @@ | ||
44 | 52 | def test_template_parts(): |
45 | 53 | big_file = "big.txt" # Uses: part-include.txt & part-import.txt |
46 | 54 | |
47 | - template = RPy.Template(template=big_file, search_path=t_dir) | |
55 | + template = RPy.Template(template=big_file, search_path=template_a_dir) | |
48 | 56 | out = template.render() |
49 | 57 | |
50 | 58 | assert 'INCLUDED' in out, "this line in part-include.txt" |