Browse Source

Merge pull request #1630 from redian/master

Skip tests if redbaron is not installed
pull/1634/head
David Lord 9 years ago
parent
commit
b3b5a98fd0
  1. 25
      scripts/test_import_migration.py

25
scripts/test_import_migration.py

@ -2,30 +2,29 @@
# #
# Author: Keyan Pishdadian # Author: Keyan Pishdadian
import pytest import pytest
from redbaron import RedBaron redbaron = pytest.importorskip("redbaron")
import flaskext_migrate as migrate import flaskext_migrate as migrate
def test_simple_from_import(): def test_simple_from_import():
red = RedBaron("from flask.ext import foo") red = redbaron.RedBaron("from flask.ext import foo")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "import flask_foo as foo" assert output == "import flask_foo as foo"
def test_from_to_from_import(): def test_from_to_from_import():
red = RedBaron("from flask.ext.foo import bar") red = redbaron.RedBaron("from flask.ext.foo import bar")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "from flask_foo import bar as bar" assert output == "from flask_foo import bar as bar"
def test_multiple_import(): def test_multiple_import():
red = RedBaron("from flask.ext.foo import bar, foobar, something") red = redbaron.RedBaron("from flask.ext.foo import bar, foobar, something")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "from flask_foo import bar, foobar, something" assert output == "from flask_foo import bar, foobar, something"
def test_multiline_import(): def test_multiline_import():
red = RedBaron("from flask.ext.foo import \ red = redbaron.RedBaron("from flask.ext.foo import \
bar,\ bar,\
foobar,\ foobar,\
something") something")
@ -34,37 +33,37 @@ def test_multiline_import():
def test_module_import(): def test_module_import():
red = RedBaron("import flask.ext.foo") red = redbaron.RedBaron("import flask.ext.foo")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "import flask_foo" assert output == "import flask_foo"
def test_named_module_import(): def test_named_module_import():
red = RedBaron("import flask.ext.foo as foobar") red = redbaron.RedBaron("import flask.ext.foo as foobar")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "import flask_foo as foobar" assert output == "import flask_foo as foobar"
def test_named_from_import(): def test_named_from_import():
red = RedBaron("from flask.ext.foo import bar as baz") red = redbaron.RedBaron("from flask.ext.foo import bar as baz")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "from flask_foo import bar as baz" assert output == "from flask_foo import bar as baz"
def test_parens_import(): def test_parens_import():
red = RedBaron("from flask.ext.foo import (bar, foo, foobar)") red = redbaron.RedBaron("from flask.ext.foo import (bar, foo, foobar)")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "from flask_foo import (bar, foo, foobar)" assert output == "from flask_foo import (bar, foo, foobar)"
def test_function_call_migration(): def test_function_call_migration():
red = RedBaron("flask.ext.foo(var)") red = redbaron.RedBaron("flask.ext.foo(var)")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "flask_foo(var)" assert output == "flask_foo(var)"
def test_nested_function_call_migration(): def test_nested_function_call_migration():
red = RedBaron("import flask.ext.foo\n\n" red = redbaron.RedBaron("import flask.ext.foo\n\n"
"flask.ext.foo.bar(var)") "flask.ext.foo.bar(var)")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == ("import flask_foo\n\n" assert output == ("import flask_foo\n\n"
@ -72,6 +71,6 @@ def test_nested_function_call_migration():
def test_no_change_to_import(): def test_no_change_to_import():
red = RedBaron("from flask import Flask") red = redbaron.RedBaron("from flask import Flask")
output = migrate.fix_tester(red) output = migrate.fix_tester(red)
assert output == "from flask import Flask" assert output == "from flask import Flask"

Loading…
Cancel
Save