4
4
from nose import SkipTest
5
5
from flask import Flask
6
6
from flask .ext .assets import Environment , ManageAssets
7
+ from webassets .script import GenericArgparseImplementation
7
8
8
9
try :
9
10
from flaskext .script import Manager
@@ -21,28 +22,25 @@ def test_call(self):
21
22
# Setup the webassets.script with a mock main() function,
22
23
# so we can check whether our call via Flask-Script actually
23
24
# goes through.
24
- def dummy_main (argv , * a , ** kw ):
25
- self .last_script_call = argv
26
- return 0
27
- from webassets import script
28
- old_main = script .main
29
- script .main = dummy_main
25
+ test_inst = self
26
+ class DummyArgparseImplementation (GenericArgparseImplementation ):
27
+ def run_with_argv (self , argv ):
8000
28
+ test_inst .last_script_call = argv
29
+ return 0
30
+
31
+ mgmt = Manager (self .app )
32
+ mgmt .add_command ('assets' ,
33
+ ManageAssets (self .env , impl = DummyArgparseImplementation ))
30
34
31
35
try :
32
- mgmt = Manager (self .app )
33
- mgmt .add_command ('assets' , ManageAssets (self .env ))
34
-
35
- try :
36
- # -h is a great test as that is something Flask-Script might
37
- # want to claim for itself.
38
- sys .argv = ['./manage.py' , 'assets' , '-h' ]
39
- mgmt .run ()
40
- except SystemExit :
41
- # Always raised, regardless of success or failure of command
42
- pass
43
- assert self .last_script_call == ['-h' ]
44
- finally :
45
- script .main = old_main
36
+ # -h is a great test as that is something Flask-Script might
37
+ # want to claim for itself.
38
+ sys .argv = ['./manage.py' , 'assets' , '-h' ]
39
+ mgmt .run ()
40
+ except SystemExit :
41
+ # Always raised, regardless of success or failure of command
42
+ pass
43
+ assert self .last_script_call == ['-h' ]
46
44
47
45
def test_call_auto_env (self ):
48
46
"""Regression test: Passing the environment to the ManageAssets command
0 commit comments