fix error in import_string

This commit is contained in:
Jotagê Sales
2018-12-27 15:20:58 -02:00
parent bf029c1b9d
commit f2a55d01ea
2 changed files with 14 additions and 4 deletions

View File

@@ -1,3 +1,5 @@
import inspect
from sanic import helpers
from sanic.config import Config
import pytest
@@ -76,11 +78,16 @@ def test_remove_entity_headers():
assert helpers.remove_entity_headers(header) == expected
def test_import_string():
def test_import_string_class():
obj = helpers.import_string('sanic.config.Config')
assert isinstance(obj, Config)
def test_import_string_module():
module = helpers.import_string('sanic.config')
assert inspect.ismodule(module)
def test_import_string_exception():
with pytest.raises(ImportError):
helpers.import_string('test.test.test')