Skip to content

Commit

Permalink
Merge pull request #50 from brettcannon/test_fixes
Browse files Browse the repository at this point in the history
Add basic tests for libmodernize.fixes
  • Loading branch information
takluyver committed Sep 5, 2014
2 parents e4ced8d + 1316ead commit a8c686c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/test_fixes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from lib2to3 import refactor
import sys

from libmodernize import fixes


LIB2TO3_FIXES_PKG = 'lib2to3.fixes'
LIBMODERNIZE_FIXES_PKG = 'libmodernize.fixes'


def check_existence(prefix, module_names):
"""Check that module_names have the expected prefix and exist."""
dotted_prefix = prefix + '.'
for module_name in module_names:
if not module_name.startswith(dotted_prefix):
msg = '{0!r} does not start with {1!r}'.format(module_name, lib2to3_prefix)
raise AssertionError(msg)
try:
__import__(module_name)
except ImportError:
raise AssertionError('{0!r} cannot be imported'.format(module_name))


def test_lib2to3_fix_names():
check_existence(LIB2TO3_FIXES_PKG, fixes.lib2to3_fix_names)


def test_six_fix_names():
check_existence(LIBMODERNIZE_FIXES_PKG, fixes.six_fix_names)


def test_fixers_importable():
fixers = refactor.get_fixers_from_package(LIBMODERNIZE_FIXES_PKG)
for module_name in fixers:
try:
__import__(module_name)
except ImportError:
raise AssertionError('{0!r} cannot be imported'.format(module_name))

0 comments on commit a8c686c

Please sign in to comment.