6
6
7
7
from __future__ import with_statement
8
8
9
- from nose import SkipTest
10
- from nose .tools import assert_raises , assert_equal
9
+ import re
10
+
11
+ import pytest
11
12
12
13
from tests .test_bundle_build import AppendFilter
13
14
from webassets import Bundle
@@ -64,12 +65,12 @@ def test_erroneous_debug_value(self):
64
65
value."""
65
66
# On the bundle level
66
67
b = self .MockBundle ('a' , 'b' , debug = "invalid" )
67
- assert_raises (BundleError , b .urls , env = self .env )
68
+ pytest . raises (BundleError , b .urls , env = self .env )
68
69
69
70
# On the environment level
70
71
self .env .debug = "invalid"
71
72
b = self .MockBundle ('a' , 'b' )
72
- assert_raises (BundleError , b .urls , env = self .env )
73
+ pytest . raises (BundleError , b .urls , env = self .env )
73
74
74
75
# Self-check - this should work if this test works.
75
76
self .env .debug = True # valid again
@@ -96,7 +97,7 @@ def test_invalid_source_file(self):
96
97
"""
97
98
self .env .debug = True
98
99
bundle = self .mkbundle ('non-existent-file' , output = "out" )
99
- assert_raises (BundleError , bundle .urls )
100
+ pytest . raises (BundleError , bundle .urls )
100
101
101
102
def test_filters_in_debug_mode (self ):
102
103
"""Test that if a filter is used which runs in debug mode, the bundle
@@ -124,33 +125,25 @@ def test_external_refs(self):
124
125
"""If a bundle contains absolute paths outside of the
125
126
media directory, to generate a url they are copied in.
126
127
"""
127
- try :
128
- from nose .tools import assert_regex
129
- except ImportError :
130
- raise SkipTest ("Assertion method only present in 2.7+" )
131
128
self .env .debug = True
132
129
with TempDirHelper () as h :
133
130
h .create_files (['foo.css' ])
134
131
bundle = self .mkbundle (h .path ('foo.css' ))
135
132
urls = bundle .urls ()
136
133
assert len (urls ) == 1
137
- assert_regex ( urls [ 0 ], r'.*/webassets-external/[\da-z]*_foo.css' )
134
+ assert re . match ( r'.*/webassets-external/[\da-z]*_foo.css' , urls [ 0 ] )
138
135
139
136
def test_external_refs_calculate_sri (self ):
140
137
"""If a bundle contains absolute paths outside of the
141
138
media directory, to generate a url they are copied in.
142
139
"""
143
- try :
144
- from nose .tools import assert_regex
145
- except ImportError :
146
- raise SkipTest ("Assertion method only present in 2.7+" )
147
140
self .env .debug = True
148
141
with TempDirHelper () as h :
149
142
h .create_files (['foo.css' ])
150
143
bundle = self .mkbundle (h .path ('foo.css' ))
151
144
urls = bundle .urls (calculate_sri = True )
152
145
assert len (urls ) == 1
153
- assert_regex ( urls [ 0 ][ 'uri' ], r'.*/webassets-external/[\da-z]*_foo.css' )
146
+ assert re . match ( r'.*/webassets-external/[\da-z]*_foo.css' , urls [ 0 ][ 'uri' ] )
154
147
assert urls [0 ]['sri' ] == _EMPTY_FILE_SRI
155
148
156
149
@@ -194,7 +187,7 @@ def test_root_bundle_switching_to_merge(self):
194
187
does not affect url generation).
195
188
"""
196
189
bundle = self .MockBundle ('1' , '2' , output = 'childout' , debug = 'merge' )
197
- assert_equal ( bundle .urls (), ['/childout' ])
190
+ assert bundle .urls () == ['/childout' ]
198
191
assert len (self .build_called ) == 1
199
192
200
193
def test_root_bundle_switching_to_debug_true (self ):
@@ -203,7 +196,7 @@ def test_root_bundle_switching_to_debug_true(self):
203
196
ineffectual.
204
197
"""
205
198
bundle = self .MockBundle ('1' , '2' , output = 'childout' , debug = True )
206
- assert_equal ( bundle .urls (), ['/childout' ])
199
+ assert bundle .urls () == ['/childout' ]
207
200
assert len (self .build_called ) == 1
208
201
209
202
def test_root_debug_true_and_child_debug_false (self ):
@@ -217,7 +210,7 @@ def test_root_debug_true_and_child_debug_false(self):
217
210
'1' , '2' ,
218
211
self .MockBundle ('a' , output = 'child1' , debug = False ),
219
212
output = 'rootout' , debug = True )
220
- assert_equal ( bundle .urls (), ['/rootout' ])
213
+ assert bundle .urls () == ['/rootout' ]
221
214
222
215
def test_simple_bundle_with_sri (self ):
223
216
bundle = self .MockBundle ('a' , 'b' , 'c' , output = 'out' )
@@ -259,7 +252,7 @@ def test_root_bundle_switching_to_merge_with_sri(self):
259
252
does not affect url generation).
260
253
"""
261
254
bundle = self .MockBundle ('1' , '2' , output = 'childout' , debug = 'merge' )
262
- assert_equal ( bundle .urls (calculate_sri = True ), [{'uri' : '/childout' , 'sri' : None }])
255
+ assert bundle .urls (calculate_sri = True ) == [{'uri' : '/childout' , 'sri' : None }]
263
256
assert len (self .build_called ) == 1
264
257
265
258
def test_root_bundle_switching_to_debug_true_with_sri (self ):
@@ -268,7 +261,7 @@ def test_root_bundle_switching_to_debug_true_with_sri(self):
268
261
ineffectual.
269
262
"""
270
263
bundle = self .MockBundle ('1' , '2' , output = 'childout' , debug = True )
271
- assert_equal ( bundle .urls (calculate_sri = True ), [{'uri' : '/childout' , 'sri' : None }])
264
+ assert bundle .urls (calculate_sri = True ) == [{'uri' : '/childout' , 'sri' : None }]
272
265
assert len (self .build_called ) == 1
273
266
274
267
def test_root_debug_true_and_child_debug_false_with_sri (self ):
@@ -282,7 +275,7 @@ def test_root_debug_true_and_child_debug_false_with_sri(self):
282
275
'1' , '2' ,
283
276
self .MockBundle ('a' , output = 'child1' , debug = False ),
284
277
output = 'rootout' , debug = True )
285
- assert_equal ( bundle .urls (calculate_sri = True ), [{'uri' : '/rootout' , 'sri' : None }])
278
+ assert bundle .urls (calculate_sri = True ) == [{'uri' : '/rootout' , 'sri' : None }]
286
279
287
280
288
281
class TestUrlsWithDebugTrue (BaseUrlsTester ):
@@ -295,8 +288,8 @@ def setup(self):
295
288
296
289
def test_simple_bundle (self ):
297
290
bundle = self .MockBundle ('a' , 'b' , 'c' , output = 'out' )
298
- assert_equal ( bundle .urls (), ['/a' , '/b' , '/c' ])
299
- assert_equal ( len (self .build_called ), 0 )
291
+ assert bundle .urls () == ['/a' , '/b' , '/c' ]
292
+ assert len (self .build_called ) == 0
300
293
301
294
def test_nested_bundle (self ):
302
295
bundle = self .MockBundle (
@@ -318,8 +311,8 @@ def test_url_source(self):
318
311
"""[Regression] Test a Bundle that contains a source URL.
319
312
"""
320
313
bundle = self .MockBundle ('http://test.de' , output = 'out' )
321
- assert_equal ( bundle .urls (), ['http://test.de' ])
322
- assert_equal ( len (self .build_called ), 0 )
314
+ assert bundle .urls () == ['http://test.de' ]
315
+ assert len (self .build_called ) == 0
323
316
324
317
# This is the important test. It proves that the url source
325
318
# was handled separately, and not processed like any other
@@ -328,22 +321,22 @@ def test_url_source(self):
328
321
# converts a bundle content into an url operates just fine
329
322
# on a url source, so there is no easy other way to determine
330
323
# whether the url source was treated special.
331
- assert_equal ( len (self .makeurl_called ), 0 )
324
+ assert len (self .makeurl_called ) == 0
332
325
333
326
def test_root_bundle_switching_to_debug_false (self ):
334
327
"""A bundle explicitly says it wants to be processed with
335
328
debug=False, overriding the global "debug=True" setting.
336
329
"""
337
330
bundle = self .MockBundle ('1' , '2' , output = 'childout' , debug = False )
338
- assert_equal ( bundle .urls (), ['/childout' ])
331
+ assert bundle .urls () == ['/childout' ]
339
332
assert len (self .build_called ) == 1
340
333
341
334
def test_root_bundle_switching_to_merge (self ):
342
335
"""A bundle explicitly says it wants to be merged, overriding
343
336
the global "debug=True" setting.
344
337
"""
345
338
bundle = self .MockBundle ('1' , '2' , output = 'childout' , debug = 'merge' )
346
- assert_equal ( bundle .urls (), ['/childout' ])
339
+ assert bundle .urls () == ['/childout' ]
347
340
assert len (self .build_called ) == 1
348
341
349
342
def test_child_bundle_switching (self ):
@@ -354,16 +347,16 @@ def test_child_bundle_switching(self):
354
347
bundle = self .MockBundle (
355
348
'a' , self .MockBundle ('1' , '2' , output = 'childout' , debug = 'merge' ),
356
349
'c' , output = 'out' )
357
- assert_equal ( bundle .urls (), ['/a' , '/childout' , '/c' ])
350
+ assert bundle .urls () == ['/a' , '/childout' , '/c' ]
358
351
assert len (self .build_called ) == 1
359
352
360
353
def test_simple_bundle_with_sri (self ):
361
354
bundle = self .MockBundle ('a' , 'b' , 'c' , output = 'out' )
362
- assert_equal ( bundle .urls (calculate_sri = True ),
363
- [ {'sri' : _EMPTY_FILE_SRI , 'uri' : '/a' },
355
+ assert bundle .urls (calculate_sri = True ) == [
356
+ {'sri' : _EMPTY_FILE_SRI , 'uri' : '/a' },
364
357
{'sri' : _EMPTY_FILE_SRI , 'uri' : '/b' },
365
- {'sri' : _EMPTY_FILE_SRI , 'uri' : '/c' }])
366
- assert_equal ( len (self .build_called ), 0 )
358
+ {'sri' : _EMPTY_FILE_SRI , 'uri' : '/c' }]
359
+ assert len (self .build_called ) == 0
367
360
368
361
def test_nested_bundle_with_sri (self ):
369
362
bundle = self .MockBundle (
@@ -389,8 +382,8 @@ def test_url_source_with_sri(self):
389
382
"""[Regression] Test a Bundle that contains a source URL.
390
383
"""
391
384
bundle = self .MockBundle ('http://test.de' , output = 'out' )
392
- assert_equal ( bundle .urls (calculate_sri = True ), [{'sri' : None , 'uri' : 'http://test.de' }])
393
- assert_equal ( len (self .build_called ), 0 )
385
+ assert bundle .urls (calculate_sri = True ) == [{'sri' : None , 'uri' : 'http://test.de' }]
386
+ assert len (self .build_called ) == 0
394
387
395
388
# This is the important test. It proves that the url source
396
389
# was handled separately, and not processed like any other
@@ -399,22 +392,22 @@ def test_url_source_with_sri(self):
399
392
# converts a bundle content into an url operates just fine
400
393
# on a url source, so there is no easy other way to determine
401
394
# whether the url source was treated special.
402
- assert_equal ( len (self .makeurl_called ), 0 )
395
+ assert len (self .makeurl_called ) == 0
403
396
404
397
def test_root_bundle_switching_to_debug_false_with_sri (self ):
405
398
"""A bundle explicitly says it wants to be processed with
406
399
debug=False, overriding the global "debug=True" setting.
407
400
"""
408
401
bundle = self .MockBundle ('1' , '2' , output = 'childout' , debug = False )
409
- assert_equal ( bundle .urls (calculate_sri = True ), [{'sri' : None , 'uri' : '/childout' }])
402
+ assert bundle .urls (calculate_sri = True ) == [{'sri' : None , 'uri' : '/childout' }]
410
403
assert len (self .build_called ) == 1
411
404
412
405
def test_root_bundle_switching_to_merge_with_sri (self ):
413
406
"""A bundle explicitly says it wants to be merged, overriding
414
407
the global "debug=True" setting.
415
408
"""
416
409
bundle = self .MockBundle ('1' , '2' , output = 'childout' , debug = 'merge' )
417
- assert_equal ( bundle .urls (calculate_sri = True ), [{'sri' : None , 'uri' : '/childout' }])
410
+ assert bundle .urls (calculate_sri = True ) == [{'sri' : None , 'uri' : '/childout' }]
418
411
assert len (self .build_called ) == 1
419
412
420
413
def test_child_bundle_switching_with_sri (self ):
@@ -425,10 +418,10 @@ def test_child_bundle_switching_with_sri(self):
425
418
bundle = self .MockBundle (
426
419
'a' , self .MockBundle ('1' , '2' , output = 'childout' , debug = 'merge' ),
427
420
'c' , output = 'out' )
428
- assert_equal ( bundle .urls (calculate_sri = True ),
429
- [ {'sri' : _EMPTY_FILE_SRI , 'uri' : '/a' },
421
+ assert bundle .urls (calculate_sri = True ) == [
422
+ {'sri' : _EMPTY_FILE_SRI , 'uri' : '/a' },
430
423
{'sri' : None , 'uri' : '/childout' },
431
- {'sri' : _EMPTY_FILE_SRI , 'uri' : '/c' }])
424
+ {'sri' : _EMPTY_FILE_SRI , 'uri' : '/c' }]
432
425
assert len (self .build_called ) == 1
433
426
434
427
@@ -457,7 +450,7 @@ def test_child_bundle_switching_to_debug_false(self):
457
450
bundle = self .MockBundle (
458
451
'a' , self .MockBundle ('1' , '2' , output = 'childout' , debug = False ),
459
452
'c' , output = 'out' )
460
- assert_equal ( bundle .urls (), ['/out' ])
453
+ assert bundle .urls () == ['/out' ]
461
454
assert len (self .build_called ) == 1
462
455
463
456
def test_root_bundle_switching_to_debug_true (self ):
@@ -467,7 +460,7 @@ def test_root_bundle_switching_to_debug_true(self):
467
460
bundle = self .MockBundle (
468
461
'a' , self .MockBundle ('1' , '2' , output = 'childout' , debug = True ),
469
462
'c' , output = 'out' )
470
- assert_equal ( bundle .urls (), ['/out' ])
463
+ assert bundle .urls () == ['/out' ]
471
464
assert len (self .build_called ) == 1
472
465
473
466
def test_simple_bundle_with_sri (self ):
@@ -489,7 +482,7 @@ def test_child_bundle_switching_to_debug_false_with_sri(self):
489
482
bundle = self .MockBundle (
490
483
'a' , self .MockBundle ('1' , '2' , output = 'childout' , debug = False ),
491
484
'c' , output = 'out' )
492
- assert_equal ( bundle .urls (calculate_sri = True ), [{'sri' : None , 'uri' : '/out' }])
485
+ assert bundle .urls (calculate_sri = True ) == [{'sri' : None , 'uri' : '/out' }]
493
486
assert len (self .build_called ) == 1
494
487
495
488
def test_root_bundle_switching_to_debug_true_with_sri (self ):
@@ -499,5 +492,5 @@ def test_root_bundle_switching_to_debug_true_with_sri(self):
499
492
bundle = self .MockBundle (
500
493
'a' , self .MockBundle ('1' , '2' , output = 'childout' , debug = True ),
501
494
'c' , output = 'out' )
502
- assert_equal ( bundle .urls (calculate_sri = True ), [{'sri' : None , 'uri' : '/out' }])
495
+ assert bundle .urls (calculate_sri = True ) == [{'sri' : None , 'uri' : '/out' }]
503
496
assert len (self .build_called ) == 1
0 commit comments