From 0cf5881312a2256607cebe36938405a6fe5a820e Mon Sep 17 00:00:00 2001 From: Keyan Pishdadian Date: Wed, 11 Feb 2015 15:06:53 -0500 Subject: [PATCH] Add tests, remove manual testing file #1135 --- scripts/test.py | 34 ----------------------------- tests/test_import_migration.py | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 34 deletions(-) delete mode 100644 scripts/test.py create mode 100644 tests/test_import_migration.py diff --git a/scripts/test.py b/scripts/test.py deleted file mode 100644 index 31b33b58..00000000 --- a/scripts/test.py +++ /dev/null @@ -1,34 +0,0 @@ -from flask.ext.foo import \ - bam, \ - crackle - -from flask.ext import foo - -from flask.ext.foo import (bam, - a, - b -) - -import flask.ext.foo - -from flask.ext import foo - -import sys - -def migrate(old_file): - new_file = open("temp.py", "w") - for line in old_file: - if line[0, 15] is "from flask.ext": - if line[15] == '.': - import_statement = line[16::].split(' ') - extension = import_statement[0] - line = line. replace("flask.ext." + extension, - "flask_" + extension) - else: - pass - - new_file.write(line) - - -if __name__ == "__main__": - old_file = open(sys.arv[1]) diff --git a/tests/test_import_migration.py b/tests/test_import_migration.py new file mode 100644 index 00000000..dc662aa7 --- /dev/null +++ b/tests/test_import_migration.py @@ -0,0 +1,40 @@ +# Tester for the flaskext_migrate.py module located in flask/scripts/ +# +# Author: Keyan Pishdadian + +import pytest +from redbaron import RedBaron +import flaskext_migrate as migrate + + +def test_simple_from_import(): + red = RedBaron("from flask.ext import foo") + output = migrate.fix(red) + assert output == "import flask_foo as foo" + + +def test_from_to_from_import(): + red = RedBaron("from flask.ext.foo import bar") + output = migrate.fix(red) + assert output == "from flask_foo import bar" + + +def test_multiple_import(): + red = RedBaron("from flask.ext.foo import bar, foobar, something") + output = migrate.fix(red) + assert output == "from flask_foo import bar,foobar,something" + + +def test_multiline_import(): + red = RedBaron("from flask.ext.foo import \ + bar,\ + foobar,\ + something") + output = migrate.fix(red) + assert output == "from flask_foo import bar,foobar,something" + + +def test_module_import(): + red = RedBaron("import flask.ext.foo") + output = migrate.fix(red) + assert output == "import flask_foo"