4242
4343class CoffeeScriptTest (unittest .TestCase ):
4444 def setUp (self ):
45- self .runtimes = list (execjs .available_runtimes ().values ())
46-
4745 self .encodings = "shift-jis utf-8 euc-jp" .split ()
48- self .compilers = []
49- self .compilers .append (coffeescript ) # default compiler
50-
51- from os .path import join , dirname
52- script_path = join (dirname (coffeescript .__file__ ), "coffee-script.js" )
53- with io .open (script_path ) as fp :
54- compiler_script = fp .read ()
55-
56- for runtime in self .runtimes :
57- self .compilers .append (
58- coffeescript .Compiler (compiler_script , runtime ))
59-
6046
6147 def assertExprsSuccess (self , ctx ):
6248 self .assertEqual (ctx .call ("add" , 1 , 2 ), 3 )
@@ -72,39 +58,29 @@ def assertExprsFail(self, ctx):
7258 ctx .eval ("helloworld" )
7359
7460 def test_compile (self ):
75- for compiler , runtime in product (self .compilers , self .runtimes ):
76- compile = compiler .compile
77-
78- # test bare=True
79- jscode = compile (coffee_code , bare = True )
80- ctx = runtime .compile (jscode )
81- self .assertExprsSuccess (ctx )
82-
83- # test bare=False
84- jscode = compile (coffee_code , bare = False )
85- ctx = runtime .compile (jscode )
86- self .assertExprsFail (ctx )
87-
88- def combinations_for_compile_file (self ):
89- return product (
90- self .compilers ,
91- self .encodings ,
92- self .runtimes ,
93- )
94-
95- def assert_compile_file_success (self , compiler , runtime , filename , encoding , bare ):
96- jscode = compiler .compile_file (filename , encoding = encoding , bare = bare )
97- ctx = runtime .compile (jscode )
61+ # test bare=True
62+ jscode = coffeescript .compile (coffee_code , bare = True )
63+ ctx = execjs .compile (jscode )
64+ self .assertExprsSuccess (ctx )
65+
66+ # test bare=False
67+ jscode = coffeescript .compile (coffee_code , bare = False )
68+ ctx = execjs .compile (jscode )
69+ self .assertExprsFail (ctx )
70+
71+ def assert_compile_file_success (self , filename , encoding , bare ):
72+ jscode = coffeescript .compile_file (filename , encoding = encoding , bare = bare )
73+ ctx = execjs .compile (jscode )
9874 self .assertExprsSuccess (ctx )
9975
100- def assert_compile_file_fail (self , compiler , runtime , filename , encoding , bare ):
101- jscode = compiler .compile_file (filename , encoding = encoding , bare = bare )
102- ctx = runtime .compile (jscode )
76+ def assert_compile_file_fail (self , filename , encoding , bare ):
77+ jscode = coffeescript .compile_file (filename , encoding = encoding , bare = bare )
78+ ctx = execjs .compile (jscode )
10379 self .assertExprsFail (ctx )
10480
105- def assert_compile_file_decode_error (self , compiler , runtime , filename , encoding , bare ):
81+ def assert_compile_file_decode_error (self , filename , encoding , bare ):
10682 with self .assertRaises (UnicodeDecodeError ):
107- compiler .compile_file (filename , encoding = encoding , bare = bare )
83+ coffeescript .compile_file (filename , encoding = encoding , bare = bare )
10884
10985 def write_temp_files (self , strings , encoding ):
11086 paths = []
@@ -121,34 +97,34 @@ def remove_files(self, paths):
12197 os .remove (p )
12298
12399 def test_compile_files (self ):
124- for compiler , encoding , runtime in self .combinations_for_compile_file () :
100+ for encoding in self .encodings :
125101 paths = self .write_temp_files ([coffee_code ], encoding )
126102 try :
127103 filename = paths [0 ]
128104
129- self .assert_compile_file_success (compiler , runtime , filename , encoding , True )
130- self .assert_compile_file_fail (compiler , runtime , filename , encoding , False )
105+ self .assert_compile_file_success (filename , encoding , True )
106+ self .assert_compile_file_fail (filename , encoding , False )
131107 for wrong_encoding in set (self .encodings ) - set ([encoding ]):
132108 self .assert_compile_file_decode_error (
133- compiler , runtime , filename , wrong_encoding , True )
109+ filename , wrong_encoding , True )
134110 self .assert_compile_file_decode_error (
135- compiler , runtime , filename , wrong_encoding , False )
111+ filename , wrong_encoding , False )
136112 finally :
137113 self .remove_files (paths )
138114
139115 def test_compile_splitted_files (self ):
140- for compiler , encoding , runtime in self .combinations_for_compile_file () :
116+ for encoding in self .encodings :
141117 paths = self .write_temp_files (splitted_coffee_code , encoding )
142118 try :
143119 filename = paths
144120
145- self .assert_compile_file_success (compiler , runtime , filename , encoding , True )
146- self .assert_compile_file_fail (compiler , runtime , filename , encoding , False )
121+ self .assert_compile_file_success (filename , encoding , True )
122+ self .assert_compile_file_fail (filename , encoding , False )
147123 for wrong_encoding in set (self .encodings ) - set ([encoding ]):
148124 self .assert_compile_file_decode_error (
149- compiler , runtime , filename , wrong_encoding , True )
125+ filename , wrong_encoding , True )
150126 self .assert_compile_file_decode_error (
151- compiler , runtime , filename , wrong_encoding , False )
127+ filename , wrong_encoding , False )
152128 finally :
153129 self .remove_files (paths )
154130
0 commit comments