1. Joe Amenta
  2. lib3to2

Commits

Joe Amenta  committed 460b25d

'unittest' -> 'unittest2'

  • Participants
  • Parent commits 3d1338b
  • Branches default

Comments (0)

Files changed (2)

File lib3to2/fixes/fix_unittest.py

View file
+"""
+Fixer for unittest -> unittest2
+"""
+
+from lib2to3 import fixer_base
+from ..fixer_util import Name
+
+class FixUnittest(fixer_base.BaseFix):
+
+    explicit = True
+
+    PATTERN = """
+    import_from< 'from' name='unittest' 'import' any > |
+    import_name< 'import' (name='unittest' | dotted_as_name< name='unittest' 'as' any >) > |
+    import_name< 'import' dotted_as_names< any* (name='unittest' | dotted_as_name< name='unittest' 'as' any >) any* > > |
+    power< name='unittest' any* >"""
+
+    def transform(self, node, results):
+        name = results['name']
+        name.replace(Name("unittest2", prefix=name.prefix))

File lib3to2/tests/test_unittest.py

View file
+from test_all_fixers import lib3to2FixerTestCase
+
+class Test_unittest(lib3to2FixerTestCase):
+    fixer = 'unittest'
+
+    def test_imported(self):
+        b = "import unittest"
+        a = "import unittest2"
+        self.check(b, a)
+
+    def test_used(self):
+        b = "unittest.AssertStuff(True)"
+        a = "unittest2.AssertStuff(True)"
+        self.check(b, a)
+
+    def test_from_import(self):
+        b = "from unittest import *"
+        a = "from unittest2 import *"
+        self.check(b, a)
+
+    def test_imported_from(self):
+        s = "from whatever import unittest"
+        self.unchanged(s)
+
+    def test_not_base(self):
+        s = "not_unittest.unittest.stuff()"
+        self.unchanged(s)
+