Example #1
0
 def test_fixer_loading_helpers(self):
     contents = ["explicit", "first", "last", "parrot", "preorder"]
     non_prefixed = refactor.get_all_fix_names("myfixes")
     prefixed = refactor.get_all_fix_names("myfixes", False)
     full_names = refactor.get_fixers_from_package("myfixes")
     self.assertEqual(prefixed, ["fix_" + name for name in contents])
     self.assertEqual(non_prefixed, contents)
     self.assertEqual(full_names,
                      ["myfixes.fix_" + name for name in contents])
Example #2
0
 def test_crlf_newlines(self):
     old_sep = os.linesep
     os.linesep = "\r\n"
     try:
         fn = os.path.join(TEST_DATA_DIR, "crlf.py")
         fixes = refactor.get_fixers_from_package("py3kwarn2to3.fixes")
         self.check_file_refactoring(fn, fixes)
     finally:
         os.linesep = old_sep
Example #3
0
 def test_fixer_loading_helpers(self):
     contents = ["explicit", "first", "last", "parrot", "preorder"]
     non_prefixed = refactor.get_all_fix_names("myfixes")
     prefixed = refactor.get_all_fix_names("myfixes", False)
     full_names = refactor.get_fixers_from_package("myfixes")
     self.assertEqual(prefixed, ["fix_" + name for name in contents])
     self.assertEqual(non_prefixed, contents)
     self.assertEqual(full_names,
                      ["myfixes.fix_" + name for name in contents])
Example #4
0
 def test_crlf_newlines(self):
     old_sep = os.linesep
     os.linesep = "\r\n"
     try:
         fn = os.path.join(TEST_DATA_DIR, "crlf.py")
         fixes = refactor.get_fixers_from_package("py3kwarn2to3.fixes")
         self.check_file_refactoring(fn, fixes)
     finally:
         os.linesep = old_sep
Example #5
0
def warnings_for_string(data, name=''):
    tool = WarnRefactoringTool(
        refactor.get_fixers_from_package(
            'py3kwarn2to3.fixes'))
    data += '\n'  # Silence certain parse errors
    tree = tool.refactor_string(data, name)
    if tree and tree.was_changed:
        tool.processed_file(unicode(tree), name, data)
        return sorted(tool.warnings, key=lambda warning: warning[0])
    return []
Example #6
0
def get_refactorer(fixer_pkg="py3kwarn2to3", fixers=None, options=None):
    """
    A convenience function for creating a RefactoringTool for tests.

    fixers is a list of fixers for the RefactoringTool to use. By default
    "py3kwarn2to3.fixes.*" is used. options is an optional dictionary of options to
    be passed to the RefactoringTool.
    """
    if fixers is not None:
        fixers = [fixer_pkg + ".fixes.fix_" + fix for fix in fixers]
    else:
        fixers = refactor.get_fixers_from_package(fixer_pkg + ".fixes")
    options = options or {}
    return refactor.RefactoringTool(fixers, options, explicit=True)
Example #7
0
def get_refactorer(fixer_pkg="py3kwarn2to3", fixers=None, options=None):
    """
    A convenience function for creating a RefactoringTool for tests.

    fixers is a list of fixers for the RefactoringTool to use. By default
    "py3kwarn2to3.fixes.*" is used. options is an optional dictionary of options to
    be passed to the RefactoringTool.
    """
    if fixers is not None:
        fixers = [fixer_pkg + ".fixes.fix_" + fix for fix in fixers]
    else:
        fixers = refactor.get_fixers_from_package(fixer_pkg + ".fixes")
    options = options or {}
    return refactor.RefactoringTool(fixers, options, explicit=True)
Example #8
0
def print_warnings_for_files(filenames, num_processes=1):
    """Print warnings to standard out.

    Return number of warnings.

    """
    if not filenames:
        return 0

    tool = PrintWarnRefactoringTool(refactor.get_fixers_from_package(
        'py3kwarn2to3.fixes'))

    if filenames == ['-']:
        tool.refactor_stdin()
    else:
        tool.refactor(filenames,
                      num_processes=num_processes)

    return len(tool.warnings)
Example #9
0
if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest

from py3kwarn2to3 import refactor, pygram, fixer_base
from py3kwarn2to3.pgen2 import token


TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers")

sys.path.append(FIXER_DIR)
try:
    _DEFAULT_FIXERS = refactor.get_fixers_from_package("myfixes")
finally:
    sys.path.pop()

_2TO3_FIXERS = refactor.get_fixers_from_package("py3kwarn2to3.fixes")

class TestRefactoringTool(unittest.TestCase):

    def setUp(self):
        sys.path.append(FIXER_DIR)

    def tearDown(self):
        sys.path.pop()

    def check_instances(self, instances, classes):
        for inst, cls in zip(instances, classes):
Example #10
0
import shutil

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest

from py3kwarn2to3 import refactor, pygram, fixer_base
from py3kwarn2to3.pgen2 import token

TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers")

sys.path.append(FIXER_DIR)
try:
    _DEFAULT_FIXERS = refactor.get_fixers_from_package("myfixes")
finally:
    sys.path.pop()

_2TO3_FIXERS = refactor.get_fixers_from_package("py3kwarn2to3.fixes")


class TestRefactoringTool(unittest.TestCase):
    def setUp(self):
        sys.path.append(FIXER_DIR)

    def tearDown(self):
        sys.path.pop()

    def check_instances(self, instances, classes):
        for inst, cls in zip(instances, classes):