Skip to content

Commit 17d540e

Browse files
committed
Merge pull request #539 from bnavigator/remove-nose
remove nose and extra mock
2 parents 41ff9e5 + 3bfb5ea commit 17d540e

14 files changed

+175
-242
lines changed

requirements-dev.pip

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#
77
# Libs required to run the tests
88
pytest
9-
nose
10-
mock
9+
mock;python_version<"3.3"
1110

1211
# Libs helpful during development
1312
Sphinx

tests/helpers.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,17 @@
55

66

77
__all__ = ('TempDirHelper', 'TempEnvironmentHelper', 'noop',
8-
'assert_raises_regexp', 'check_warnings')
8+
'assert_raises_regex', 'check_warnings')
99

1010

1111
# Define a noop filter; occasionally in tests we need to define
1212
# a filter to be able to test a certain piece of functionality,.
1313
noop = lambda _in, out: out.write(_in.read())
1414

1515

16-
try:
17-
# Python 3
18-
from nose.tools import assert_raises_regex
19-
except ImportError:
20-
try:
21-
# Python >= 2.7
22-
from nose.tools import assert_raises_regexp as assert_raises_regex
23-
except:
24-
# Python < 2.7
25-
def assert_raises_regex(expected, regexp, callable, *a, **kw):
26-
try:
27-
callable(*a, **kw)
28-
except expected as e:
29-
if isinstance(regexp, basestring):
30-
regexp = re.compile(regexp)
31-
if not regexp.search(str(e.message)):
32-
raise self.failureException('"%s" does not match "%s"' %
33-
(regexp.pattern, str(e.message)))
34-
else:
35-
if hasattr(expected,'__name__'): excName = expected.__name__
36-
else: excName = str(expected)
37-
raise AssertionError("%s not raised" % excName)
16+
from pytest import raises
17+
def assert_raises_regex(expected, regexp, callable, *a, **kw):
18+
raises(expected, callable, *a, **kw).match(regexp)
3819

3920

4021
try:

tests/test_bundle_build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77

88
import os
9-
from nose.tools import assert_raises
9+
10+
from pytest import raises as assert_raises
1011
import pytest
12+
1113
from webassets import Bundle
1214
from webassets.cache import MemoryCache
1315
from webassets.exceptions import BuildError, BundleError

tests/test_bundle_urls.py

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
from __future__ import with_statement
88

9-
from nose import SkipTest
10-
from nose.tools import assert_raises, assert_equal
9+
import re
10+
11+
import pytest
1112

1213
from tests.test_bundle_build import AppendFilter
1314
from webassets import Bundle
@@ -64,12 +65,12 @@ def test_erroneous_debug_value(self):
6465
value."""
6566
# On the bundle level
6667
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)
6869

6970
# On the environment level
7071
self.env.debug = "invalid"
7172
b = self.MockBundle('a', 'b')
72-
assert_raises(BundleError, b.urls, env=self.env)
73+
pytest.raises(BundleError, b.urls, env=self.env)
7374

7475
# Self-check - this should work if this test works.
7576
self.env.debug = True # valid again
@@ -96,7 +97,7 @@ def test_invalid_source_file(self):
9697
"""
9798
self.env.debug = True
9899
bundle = self.mkbundle('non-existent-file', output="out")
99-
assert_raises(BundleError, bundle.urls)
100+
pytest.raises(BundleError, bundle.urls)
100101

101102
def test_filters_in_debug_mode(self):
102103
"""Test that if a filter is used which runs in debug mode, the bundle
@@ -124,33 +125,25 @@ def test_external_refs(self):
124125
"""If a bundle contains absolute paths outside of the
125126
media directory, to generate a url they are copied in.
126127
"""
127-
try:
128-
from nose.tools import assert_regex
129-
except ImportError:
130-
raise SkipTest("Assertion method only present in 2.7+")
131128
self.env.debug = True
132129
with TempDirHelper() as h:
133130
h.create_files(['foo.css'])
134131
bundle = self.mkbundle(h.path('foo.css'))
135132
urls = bundle.urls()
136133
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])
138135

139136
def test_external_refs_calculate_sri(self):
140137
"""If a bundle contains absolute paths outside of the
141138
media directory, to generate a url they are copied in.
142139
"""
143-
try:
144-
from nose.tools import assert_regex
145-
except ImportError:
146-
raise SkipTest("Assertion method only present in 2.7+")
147140
self.env.debug = True
148141
with TempDirHelper() as h:
149142
h.create_files(['foo.css'])
150143
bundle = self.mkbundle(h.path('foo.css'))
151144
urls = bundle.urls(calculate_sri=True)
152145
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'])
154147
assert urls[0]['sri'] == _EMPTY_FILE_SRI
155148

156149

@@ -194,7 +187,7 @@ def test_root_bundle_switching_to_merge(self):
194187
does not affect url generation).
195188
"""
196189
bundle = self.MockBundle('1', '2', output='childout', debug='merge')
197-
assert_equal(bundle.urls(), ['/childout'])
190+
assert bundle.urls() == ['/childout']
198191
assert len(self.build_called) == 1
199192

200193
def test_root_bundle_switching_to_debug_true(self):
@@ -203,7 +196,7 @@ def test_root_bundle_switching_to_debug_true(self):
203196
ineffectual.
204197
"""
205198
bundle = self.MockBundle('1', '2', output='childout', debug=True)
206-
assert_equal(bundle.urls(), ['/childout'])
199+
assert bundle.urls() == ['/childout']
207200
assert len(self.build_called) == 1
208201

209202
def test_root_debug_true_and_child_debug_false(self):
@@ -217,7 +210,7 @@ def test_root_debug_true_and_child_debug_false(self):
217210
'1', '2',
218211
self.MockBundle('a', output='child1', debug=False),
219212
output='rootout', debug=True)
220-
assert_equal(bundle.urls(), ['/rootout'])
213+
assert bundle.urls() == ['/rootout']
221214

222215
def test_simple_bundle_with_sri(self):
223216
bundle = self.MockBundle('a', 'b', 'c', output='out')
@@ -259,7 +252,7 @@ def test_root_bundle_switching_to_merge_with_sri(self):
259252
does not affect url generation).
260253
"""
261254
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}]
263256
assert len(self.build_called) == 1
264257

265258
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):
268261
ineffectual.
269262
"""
270263
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}]
272265
assert len(self.build_called) == 1
273266

274267
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):
282275
'1', '2',
283276
self.MockBundle('a', output='child1', debug=False),
284277
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}]
286279

287280

288281
class TestUrlsWithDebugTrue(BaseUrlsTester):
@@ -295,8 +288,8 @@ def setup(self):
295288

296289
def test_simple_bundle(self):
297290
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
300293

301294
def test_nested_bundle(self):
302295
bundle = self.MockBundle(
@@ -318,8 +311,8 @@ def test_url_source(self):
318311
"""[Regression] Test a Bundle that contains a source URL.
319312
"""
320313
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
323316

324317
# This is the important test. It proves that the url source
325318
# was handled separately, and not processed like any other
@@ -328,22 +321,22 @@ def test_url_source(self):
328321
# converts a bundle content into an url operates just fine
329322
# on a url source, so there is no easy other way to determine
330323
# whether the url source was treated special.
331-
assert_equal(len(self.makeurl_called), 0)
324+
assert len(self.makeurl_called) == 0
332325

333326
def test_root_bundle_switching_to_debug_false(self):
334327
"""A bundle explicitly says it wants to be processed with
335328
debug=False, overriding the global "debug=True" setting.
336329
"""
337330
bundle = self.MockBundle('1', '2', output='childout', debug=False)
338-
assert_equal(bundle.urls(), ['/childout'])
331+
assert bundle.urls() == ['/childout']
339332
assert len(self.build_called) == 1
340333

341334
def test_root_bundle_switching_to_merge(self):
342335
"""A bundle explicitly says it wants to be merged, overriding
343336
the global "debug=True" setting.
344337
"""
345338
bundle = self.MockBundle('1', '2', output='childout', debug='merge')
346-
assert_equal(bundle.urls(), ['/childout'])
339+
assert bundle.urls() == ['/childout']
347340
assert len(self.build_called) == 1
348341

349342
def test_child_bundle_switching(self):
@@ -354,16 +347,16 @@ def test_child_bundle_switching(self):
354347
bundle = self.MockBundle(
355348
'a', self.MockBundle('1', '2', output='childout', debug='merge'),
356349
'c', output='out')
357-
assert_equal(bundle.urls(), ['/a', '/childout', '/c'])
350+
assert bundle.urls() == ['/a', '/childout', '/c']
358351
assert len(self.build_called) == 1
359352

360353
def test_simple_bundle_with_sri(self):
361354
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'},
364357
{'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
367360

368361
def test_nested_bundle_with_sri(self):
369362
bundle = self.MockBundle(
@@ -389,8 +382,8 @@ def test_url_source_with_sri(self):
389382
"""[Regression] Test a Bundle that contains a source URL.
390383
"""
391384
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
394387

395388
# This is the important test. It proves that the url source
396389
# was handled separately, and not processed like any other
@@ -399,22 +392,22 @@ def test_url_source_with_sri(self):
399392
# converts a bundle content into an url operates just fine
400393
# on a url source, so there is no easy other way to determine
401394
# whether the url source was treated special.
402-
assert_equal(len(self.makeurl_called), 0)
395+
assert len(self.makeurl_called) == 0
403396

404397
def test_root_bundle_switching_to_debug_false_with_sri(self):
405398
"""A bundle explicitly says it wants to be processed with
406399
debug=False, overriding the global "debug=True" setting.
407400
"""
408401
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'}]
410403
assert len(self.build_called) == 1
411404

412405
def test_root_bundle_switching_to_merge_with_sri(self):
413406
"""A bundle explicitly says it wants to be merged, overriding
414407
the global "debug=True" setting.
415408
"""
416409
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'}]
418411
assert len(self.build_called) == 1
419412

420413
def test_child_bundle_switching_with_sri(self):
@@ -425,10 +418,10 @@ def test_child_bundle_switching_with_sri(self):
425418
bundle = self.MockBundle(
426419
'a', self.MockBundle('1', '2', output='childout', debug='merge'),
427420
'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'},
430423
{'sri': None, 'uri': '/childout'},
431-
{'sri': _EMPTY_FILE_SRI, 'uri': '/c'}])
424+
{'sri': _EMPTY_FILE_SRI, 'uri': '/c'}]
432425
assert len(self.build_called) == 1
433426

434427

@@ -457,7 +450,7 @@ def test_child_bundle_switching_to_debug_false(self):
457450
bundle = self.MockBundle(
458451
'a', self.MockBundle('1', '2', output='childout', debug=False),
459452
'c', output='out')
460-
assert_equal(bundle.urls(), ['/out'])
453+
assert bundle.urls() == ['/out']
461454
assert len(self.build_called) == 1
462455

463456
def test_root_bundle_switching_to_debug_true(self):
@@ -467,7 +460,7 @@ def test_root_bundle_switching_to_debug_true(self):
467460
bundle = self.MockBundle(
468461
'a', self.MockBundle('1', '2', output='childout', debug=True),
469462
'c', output='out')
470-
assert_equal(bundle.urls(), ['/out'])
463+
assert bundle.urls() == ['/out']
471464
assert len(self.build_called) == 1
472465

473466
def test_simple_bundle_with_sri(self):
@@ -489,7 +482,7 @@ def test_child_bundle_switching_to_debug_false_with_sri(self):
489482
bundle = self.MockBundle(
490483
'a', self.MockBundle('1', '2', output='childout', debug=False),
491484
'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'}]
493486
assert len(self.build_called) == 1
494487

495488
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):
499492
bundle = self.MockBundle(
500493
'a', self.MockBundle('1', '2', output='childout', debug=True),
501494
'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'}]
503496
assert len(self.build_called) == 1

0 commit comments

Comments
 (0)