1
1
import os
2
2
import sys
3
3
4
+ import pytest
4
5
import fs .path
5
6
from mock import patch
6
7
from lml .plugin import PluginInfo
7
- from nose .tools import eq_ , raises
8
8
9
9
import moban .exceptions as exceptions
10
10
from moban .core import ENGINES
11
11
from moban .core .context import Context
12
- from moban .jinja2 .engine import (
12
+ from moban .core .moban_factory import MobanEngine , expand_template_directories
13
+ from moban .plugins .jinja2 .engine import (
13
14
Engine ,
14
15
is_extension_list_valid ,
15
16
import_module_of_extension ,
16
17
)
17
- from moban .core .moban_factory import MobanEngine , expand_template_directories
18
18
19
19
USER_HOME = fs .path .join ("user" , "home" , ".moban" , "repos" )
20
20
23
23
class TestPypkg :
24
24
def __init__ (self ):
25
25
__package_path__ = os .path .normcase (os .path .dirname (__file__ ))
26
- self .resources_path = os .path .join (__package_path__ , "fixtures" )
26
+ self .resources_path = fs .path .join (__package_path__ , "fixtures" )
27
27
28
28
29
29
def test_expand_pypi_dir ():
30
- dirs = list (expand_template_directories ("testmobans:template-tests" ))
30
+ dirs = list (
31
+ expand_template_directories (
32
+ [
33
+ "tests/fixtures/template" ,
34
+ "tests/regression_tests/level-7-plugin-dir-cli/my-templates" ,
35
+ ]
36
+ )
37
+ )
31
38
for directory in dirs :
32
- assert os .path .exists (directory )
39
+ assert os .path .exists (directory [ 7 :] )
33
40
34
41
35
42
@patch ("moban.deprecated.repo.get_moban_home" , return_value = USER_HOME )
36
- @patch ("moban.file_system.exists" , return_value = True )
43
+ @patch ("moban.externals. file_system.exists" , return_value = True )
37
44
def test_expand_repo_dir (_ , __ ):
38
45
dirs = list (expand_template_directories ("git_repo:template" ))
39
46
40
47
expected = [fs .path .join (USER_HOME , "git_repo" , "template" )]
41
- eq_ ( expected , dirs )
48
+ assert expected == dirs
42
49
43
50
44
51
def test_default_template_type ():
@@ -57,22 +64,20 @@ def test_default_mako_type(_): # fake mako
57
64
assert engine .engine .__class__ == FakeEngine
58
65
59
66
60
- @raises (exceptions .NoThirdPartyEngine )
61
67
def test_unknown_template_type ():
62
- ENGINES .get_engine ("unknown_template_type" , [], "" )
68
+ with pytest .raises (exceptions .NoThirdPartyEngine ):
69
+ ENGINES .get_engine ("unknown_template_type" , [], "" )
63
70
64
71
65
- @raises (exceptions .DirectoryNotFound )
66
72
def test_non_existent_tmpl_directries ():
67
- ENGINES .get_engine ("jj2" , "idontexist" , "" )
73
+ with pytest .raises (fs .errors .CreateFailed ):
74
+ ENGINES .get_engine ("jj2" , "idontexist" , "" )
68
75
69
76
70
- @raises (exceptions .DirectoryNotFound )
71
77
def test_non_existent_config_directries ():
72
78
MobanEngine ("tests" , "abc" , Engine )
73
79
74
80
75
- @raises (exceptions .DirectoryNotFound )
76
81
def test_non_existent_ctx_directries ():
77
82
Context (["abc" ])
78
83
@@ -84,9 +89,9 @@ def test_file_tests():
84
89
engine .render_to_file ("file_tests.template" , "file_tests.yml" , output )
85
90
with open (output , "r" ) as output_file :
86
91
content = output_file .read ()
87
- eq_ ( content , "yes\n here" )
88
- eq_ ( engine .file_count , 1 )
89
- eq_ ( engine .templated_count , 1 )
92
+ assert content == "yes\n here"
93
+ assert engine .file_count == 1
94
+ assert engine .templated_count == 1
90
95
os .unlink (output )
91
96
92
97
@@ -97,9 +102,9 @@ def test_render_string_to_file():
97
102
engine .render_string_to_file ("{{test}}" , "file_tests.yml" , output )
98
103
with open (output , "r" ) as output_file :
99
104
content = output_file .read ()
100
- eq_ ( content , "here" )
101
- eq_ ( engine .file_count , 1 )
102
- eq_ ( engine .templated_count , 1 )
105
+ assert content == "here"
106
+ assert engine .file_count == 1
107
+ assert engine .templated_count == 1
103
108
os .unlink (output )
104
109
105
110
@@ -110,7 +115,9 @@ def test_global_template_variables():
110
115
engine .render_to_file ("variables.template" , "variables.yml" , output )
111
116
with open (output , "r" ) as output_file :
112
117
content = output_file .read ()
113
- eq_ (content , "template: variables.template\n target: test.txt\n here" )
118
+ assert (
119
+ content == "template: variables.template\n target: test.txt\n here"
120
+ )
114
121
os .unlink (output )
115
122
116
123
@@ -121,7 +128,7 @@ def test_nested_global_template_variables():
121
128
engine .render_to_file ("nested.template" , "variables.yml" , output )
122
129
with open (output , "r" ) as output_file :
123
130
content = output_file .read ()
124
- eq_ ( content , "template: nested.template\n target: test.txt\n here" )
131
+ assert content == "template: nested.template\n target: test.txt\n here"
125
132
os .unlink (output )
126
133
127
134
@@ -135,7 +142,7 @@ def test_environ_variables_as_data():
135
142
engine .render_to_file ("test.template" , "this_does_not_exist.yml" , output )
136
143
with open (output , "r" ) as output_file :
137
144
content = output_file .read ()
138
- eq_ ( content , "foo" )
145
+ assert content == "foo"
139
146
os .unlink (output )
140
147
141
148
@@ -146,7 +153,7 @@ def test_string_template():
146
153
engine .render_string_to_file ("{{simple}}" , "simple.yaml" , output )
147
154
with open (output , "r" ) as output_file :
148
155
content = output_file .read ()
149
- eq_ ( content , "yaml" )
156
+ assert content == "yaml"
150
157
os .unlink (output )
151
158
152
159
@@ -157,7 +164,7 @@ def test_extensions_validator():
157
164
for fixture in test_fixtures :
158
165
actual .append (is_extension_list_valid (fixture ))
159
166
160
- eq_ ( expected , actual )
167
+ assert expected == actual
161
168
162
169
163
170
def test_import ():
0 commit comments