[Checkins] SVN: zope.fixers/trunk/zope/fixers/ Finally all zope.interface seems to keep a proper indentation after fixing.
Lennart Regebro
regebro at gmail.com
Tue Apr 7 02:20:54 EDT 2009
Log message for revision 98965:
Finally all zope.interface seems to keep a proper indentation after fixing.
Changed:
U zope.fixers/trunk/zope/fixers/fix_implements.py
U zope.fixers/trunk/zope/fixers/tests.py
-=-
Modified: zope.fixers/trunk/zope/fixers/fix_implements.py
===================================================================
--- zope.fixers/trunk/zope/fixers/fix_implements.py 2009-04-07 04:12:17 UTC (rev 98964)
+++ zope.fixers/trunk/zope/fixers/fix_implements.py 2009-04-07 06:20:54 UTC (rev 98965)
@@ -129,20 +129,18 @@
decorator = Node(syms.decorator, [Leaf(50, '@'),] + statement +
[Leaf(7, '(')] + interface + [Leaf(8, ')')])
- # And stick it in before the class defintion:
+ # Take the current class constructor prefix, and stick it into
+ # the decorator, to set the decorators indentation.
prefix = node.get_prefix()
- if prefix and prefix[0] == '\n':
- decorator.set_prefix(prefix)
- elif prefix:
- node.set_prefix('\n' + prefix)
- else:
- # Find previous node:
- previous = str(node.get_prev_sibling())
- if '\n' in previous:
- prefix = previous[previous.rfind('\n'):]
- else:
- prefix = '\n' + previous
- node.set_prefix(prefix)
+ decorator.set_prefix(prefix)
+
+ # Then find the last line of the previous node and use that as
+ # indentation, and add that to the class constructors prefix.
+ prefix = str(node.get_prev_sibling())
+ if '\n' in prefix:
+ prefix = prefix[prefix.rfind('\n')+1:]
+ prefix = '\n' + prefix + node.get_prefix()
+ node.set_prefix(prefix)
node.insert_child(0, decorator)
if 'old_statement' in results:
Modified: zope.fixers/trunk/zope/fixers/tests.py
===================================================================
--- zope.fixers/trunk/zope/fixers/tests.py 2009-04-07 04:12:17 UTC (rev 98964)
+++ zope.fixers/trunk/zope/fixers/tests.py 2009-04-07 06:20:54 UTC (rev 98965)
@@ -226,6 +226,45 @@
pass
"""
+
+# Edge cases I've encountered.
+edge_cases_source = """
+class Test(unittest.TestCase):
+
+ # Note that most of the tests are in the doc strings of the
+ # declarations module.
+
+ def test_builtins(self):
+ # Setup
+
+ intspec = implementedBy(int)
+ olddeclared = intspec.declared
+
+ classImplements(int, I1)
+ class myint(int):
+ implements(I2)
+
+"""
+
+edge_cases_target = """
+class Test(unittest.TestCase):
+
+ # Note that most of the tests are in the doc strings of the
+ # declarations module.
+
+ def test_builtins(self):
+ # Setup
+
+ intspec = implementedBy(int)
+ olddeclared = intspec.declared
+
+ classImplements(int, I1)
+ @implementer(I2)
+ class myint(int):
+ pass
+
+"""
+
class FixerTest(unittest.TestCase):
def setUp(self):
@@ -275,4 +314,6 @@
def test_indented_class(self):
self._test(indented_class_source, indented_class_target)
-
\ No newline at end of file
+
+ def test_edge_cases(self):
+ self._test(edge_cases_source, edge_cases_target)
More information about the Checkins
mailing list