1
1
import os
2
2
3
- from lml .plugin import PluginInfo
3
+ from nose .tools import eq_
4
+ from moban .plugins import ENGINES , BaseEngine
5
+ from moban_handlebars .engine import EngineHandlebars
4
6
5
- import moban .exceptions as exceptions
6
- from mock import patch
7
- from nose .tools import eq_ , raises
8
- from moban .plugins import (
9
- ENGINES ,
10
- Context ,
11
- BaseEngine ,
12
- expand_template_directories ,
13
- )
14
- from moban .jinja2 .engine import Engine
15
- from moban .engine_handlebars import EngineHandlebars
16
7
17
-
18
- @PluginInfo ("library" , tags = ["testmobans" ])
19
- class TestPypkg :
20
- def __init__ (self ):
21
- __package_path__ = os .path .dirname (__file__ )
22
- self .resources_path = os .path .join (__package_path__ , "fixtures" )
23
-
24
-
25
- def test_expand_pypi_dir ():
26
- dirs = list (expand_template_directories ("testmobans:template-tests" ))
27
- for directory in dirs :
28
- assert os .path .exists (directory )
29
-
30
-
31
- @patch ("moban.utils.get_moban_home" , return_value = "/user/home/.moban/repos" )
32
- @patch ("os.path.exists" , return_value = True )
33
- def test_expand_repo_dir (_ , __ ):
34
- dirs = list (expand_template_directories ("git_repo:template" ))
35
-
36
- expected = ["/user/home/.moban/repos/git_repo/template" ]
37
- eq_ (expected , dirs )
38
-
39
-
40
- def test_default_template_type ():
41
- engine = ENGINES .get_engine ("jj2" , [], "" )
42
- assert engine .engine_cls == Engine
8
+ def test_handlebars_template_not_found ():
9
+ path = os .path .join ("tests" , "fixtures" , "handlebars_tests" )
10
+ engine = EngineHandlebars ([path ])
11
+ template = engine .get_template ("file_tests.template" )
12
+ data = dict (test = "here" )
13
+ result = engine .apply_template (template , data , None )
14
+ expected = "here"
15
+ eq_ (expected , result )
43
16
44
17
45
18
def test_handlebars_template_type ():
46
19
engine = ENGINES .get_engine ("hbs" , [], "" )
47
20
assert engine .engine_cls == EngineHandlebars
48
21
49
22
50
- def test_default_mako_type (): # fake mako
51
- engine = ENGINES .get_engine ("mako" , [], "" )
52
- assert engine .engine_cls .__name__ == "MakoEngine"
53
-
54
-
55
- @raises (exceptions .NoThirdPartyEngine )
56
- def test_unknown_template_type ():
57
- ENGINES .get_engine ("unknown_template_type" , [], "" )
58
-
59
-
60
- @raises (exceptions .DirectoryNotFound )
61
- def test_non_existent_tmpl_directries ():
62
- BaseEngine ("abc" , "tests" , Engine )
63
-
64
-
65
- @raises (exceptions .DirectoryNotFound )
66
- def test_non_existent_config_directries ():
67
- BaseEngine ("tests" , "abc" , Engine )
68
-
69
-
70
- @raises (exceptions .DirectoryNotFound )
71
- def test_non_existent_ctx_directries ():
72
- Context (["abc" ])
73
-
74
-
75
- def test_file_tests ():
76
- output = "test.txt"
77
- path = os .path .join ("tests" , "fixtures" , "jinja_tests" )
78
- engine = BaseEngine ([path ], path , Engine )
79
- engine .render_to_file ("file_tests.template" , "file_tests.yml" , output )
80
- with open (output , "r" ) as output_file :
81
- content = output_file .read ()
82
- eq_ (content , "yes\n here" )
83
- os .unlink (output )
84
-
85
-
86
23
def test_handlebars_file_tests ():
87
24
output = "test.txt"
88
25
path = os .path .join ("tests" , "fixtures" , "handlebars_tests" )
@@ -92,25 +29,3 @@ def test_handlebars_file_tests():
92
29
content = output_file .read ()
93
30
eq_ (content , "here" )
94
31
os .unlink (output )
95
-
96
-
97
- def test_global_template_variables ():
98
- output = "test.txt"
99
- path = os .path .join ("tests" , "fixtures" , "globals" )
100
- engine = BaseEngine ([path ], path , Engine )
101
- engine .render_to_file ("variables.template" , "variables.yml" , output )
102
- with open (output , "r" ) as output_file :
103
- content = output_file .read ()
104
- eq_ (content , "template: variables.template\n target: test.txt\n here" )
105
- os .unlink (output )
106
-
107
-
108
- def test_nested_global_template_variables ():
109
- output = "test.txt"
110
- path = os .path .join ("tests" , "fixtures" , "globals" )
111
- engine = BaseEngine ([path ], path , Engine )
112
- engine .render_to_file ("nested.template" , "variables.yml" , output )
113
- with open (output , "r" ) as output_file :
114
- content = output_file .read ()
115
- eq_ (content , "template: nested.template\n target: test.txt\n here" )
116
- os .unlink (output )
0 commit comments