Skip to content

Commit

Permalink
Merge pull request #161 from greyli/pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli committed Oct 17, 2023
2 parents 09abde7 + bee16f2 commit 6ff2d5d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
16 changes: 9 additions & 7 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
"""

from __future__ import absolute_import
from tests.helpers import check_warnings

from nose.tools import assert_raises
import pytest
from flask import Flask
from flask_assets import Environment
from webassets.exceptions import ImminentDeprecationWarning

try:
from webassets.updater import BaseUpdater
Expand Down Expand Up @@ -73,8 +71,10 @@ def setup(self):

def test_no_app_available(self):
"""Without an application bound, we can't do much."""
assert_raises(RuntimeError, setattr, self.env, 'debug', True)
assert_raises(RuntimeError, self.env.config.get, 'debug')
with pytest.raises(RuntimeError):
setattr(self.env, 'debug', True)
with pytest.raises(RuntimeError):
self.env.config.get('debug')

def test_global_defaults(self):
"""We may set defaults even without an application, however."""
Expand All @@ -89,7 +89,8 @@ def test_multiple_separate_apps(self):
self.env.init_app(app1)

# With no app yet available...
assert_raises(RuntimeError, getattr, self.env, 'url')
with pytest.raises(RuntimeError):
getattr(self.env, 'url')
# ...set a default
self.env.config.setdefault('FOO', 'BAR')

Expand All @@ -109,6 +110,7 @@ def test_key_error(self):
"""KeyError is raised if a config value doesn't exist.
"""
with Flask(__name__).test_request_context():
assert_raises(KeyError, self.env.config.__getitem__, 'YADDAYADDA')
with pytest.raises(KeyError):
self.env.config['YADDAYADDA']
# The get() helper, on the other hand, simply returns None
assert self.env.config.get('YADDAYADDA') == None
2 changes: 1 addition & 1 deletion tests/test_env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from nose.tools import assert_raises

from flask import Flask
from flask_assets import Environment, Bundle

Expand Down
16 changes: 10 additions & 6 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import absolute_import
from nose.tools import assert_raises

import pytest
from flask import Flask
from flask_assets import Environment, Bundle
from webassets.bundle import get_all_bundle_files

from tests.helpers import TempEnvironmentHelper, Module, Blueprint


Expand Down Expand Up @@ -44,8 +45,10 @@ def setup(self):
def test_config_values_not_set_by_default(self):
assert not 'directory' in self.env.config
assert not 'url' in self.env.config
assert_raises(KeyError, self.env.config.__getitem__, 'directory')
assert_raises(KeyError, self.env.config.__getitem__, 'url')
with pytest.raises(KeyError):
self.env.config['directory']
with pytest.raises(KeyError):
self.env.config['url']

def test_directory_auto(self):
"""Test how we resolve file references through the Flask static
Expand Down Expand Up @@ -83,8 +86,8 @@ def test_url_auto(self):

# [Regression] Ensure that any request context we may have added
# to the stack has been removed.
from flask import _request_ctx_stack
assert _request_ctx_stack.top is None
from flask import has_request_context
assert not has_request_context()

def test_custom_load_path(self):
"""A custom load_path is configured - this will affect how
Expand Down Expand Up @@ -233,7 +236,8 @@ def test_blueprint_urls(self):
def test_blueprint_no_static_folder(self):
"""Test dealing with a blueprint without a static folder."""
self.make_blueprint('module')
assert_raises(TypeError, self.mkbundle('module/foo').urls)
with pytest.raises(TypeError):
self.mkbundle('module/foo').urls()

def test_cssrewrite(self):
"""Make sure cssrewrite works with Blueprints.
Expand Down
9 changes: 4 additions & 5 deletions tests/test_script.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
from __future__ import absolute_import

from nose import SkipTest
import pytest

# check for flask-script before importing things that fail if it's not present
try:
from flask_script import Manager
except:
raise SkipTest()
pytest.skip(allow_module_level=True)

import sys
from flask import Flask
from flask_assets import Environment, ManageAssets
from flask_assets import ManageAssets
from webassets.script import GenericArgparseImplementation
from tests.helpers import TempEnvironmentHelper

# Flask-script seemingly no longer supports 2.6
if sys.version_info[:2] == (2, 6):
raise SkipTest()
pytest.skip(allow_module_level=True)


# The CLI likes to log to stderr, which isn't nice to the test output.
Expand Down

0 comments on commit 6ff2d5d

Please sign in to comment.