File tree Expand file tree Collapse file tree 2 files changed +96
-0
lines changed Expand file tree Collapse file tree 2 files changed +96
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ def add_future(node, symbol):
60
60
61
61
import_ = fixer_util .FromImport ('__future__' ,
62
62
[Leaf (token .NAME , symbol , prefix = " " )])
63
+
64
+ # Place after any comments or whitespace. (copyright, shebang etc.)
65
+ import_ .prefix = node .prefix
66
+ node .prefix = ''
67
+
63
68
children = [import_ , fixer_util .Newline ()]
64
69
root .insert_child (idx , Node (syms .simple_stmt , children ))
65
70
Original file line number Diff line number Diff line change 29
29
import foo
30
30
""" )
31
31
32
+ DOCSTRING = ("""\
33
+ \" ""
34
+ Docstring
35
+ \" ""
36
+ import foo
37
+ """ , """\
38
+ \" ""
39
+ Docstring
40
+ \" ""
41
+ from __future__ import absolute_import
42
+ import foo
43
+ """ )
44
+
45
+ SHEBANG = ("""\
46
+ #!/usr/bin/env python
47
+ import foo
48
+ """ , """\
49
+ #!/usr/bin/env python
50
+ from __future__ import absolute_import
51
+ import foo
52
+ """ )
53
+
54
+ DOCSTING_AND_SHEBANG = ("""\
55
+ #!/usr/bin/env python
56
+ \" ""
57
+ Docstring
58
+ \" ""
59
+ import foo
60
+ """ , """\
61
+ #!/usr/bin/env python
62
+ \" ""
63
+ Docstring
64
+ \" ""
65
+ from __future__ import absolute_import
66
+ import foo
67
+ """ )
68
+
69
+ COPYRIGHT_AND_SHEBANG = ("""\
70
+ #!/usr/bin/env python
71
+
72
+ #
73
+ # Copyright notice
74
+ #
75
+
76
+ import foo
77
+ """ , """\
78
+ #!/usr/bin/env python
79
+
80
+ #
81
+ # Copyright notice
82
+ #
83
+
84
+ from __future__ import absolute_import
85
+ import foo
86
+ """ )
87
+
88
+
89
+ COPYRIGHT_AND_DOCSTRING = ("""\
90
+ #
91
+ # Copyright notice
92
+ #
93
+
94
+ \" ""Docstring\" ""
95
+
96
+ import foo
97
+ """ , """\
98
+ #
99
+ # Copyright notice
100
+ #
101
+
102
+ \" ""Docstring\" ""
103
+
104
+ from __future__ import absolute_import
105
+ import foo
106
+ """ )
107
+
32
108
33
109
def test_no_imports ():
34
110
check_on_input (* NO_IMPORTS )
@@ -41,3 +117,18 @@ def test_only_normal_imports():
41
117
42
118
def test_normal_and_future_imports ():
43
119
check_on_input (* NORMAL_AND_FUTURE_IMPORTS )
120
+
121
+ def test_import_with_docstring ():
122
+ check_on_input (* DOCSTRING )
123
+
124
+ def test_import_with_shebang ():
125
+ check_on_input (* SHEBANG )
126
+
127
+ def test_import_with_docstring_and_shebang ():
128
+ check_on_input (* DOCSTING_AND_SHEBANG )
129
+
130
+ def test_import_with_copyright_and_shebang ():
131
+ check_on_input (* COPYRIGHT_AND_SHEBANG )
132
+
133
+ def test_import_with_copyright_and_docstring ():
134
+ check_on_input (* COPYRIGHT_AND_DOCSTRING )
You can’t perform that action at this time.
0 commit comments