예제 #1
0
    def test_filter_code_should_ignore_docstring(self):
        line = """
def foo():
    '''
    >>> import math
    '''
"""
        self.assertEqual(line, ''.join(autoflake.filter_code(line)))
예제 #2
0
    def test_filter_code_should_ignore_docstring(self):
        line = """
def foo():
    '''
    >>> import math
    '''
"""
        self.assertEqual(line, ''.join(autoflake.filter_code(line)))
예제 #3
0
    def test_filter_code_should_avoid_inline_except(self):
        line = """\
try: from zap import foo
except: from zap import bar
"""
        self.assertEqual(
            line,
            ''.join(autoflake.filter_code(line,
                                          remove_all_unused_imports=True)))
예제 #4
0
    def test_filter_code_with_from(self):
        self.assertEqual(
            """\
pass
x = 1
""", ''.join(autoflake.filter_code("""\
from os import path
x = 1
""")))
예제 #5
0
    def test_filter_code_with_ambiguous_from(self):
        self.assertEqual(
            """\
pass
""",
            ''.join(autoflake.filter_code("""\
from frommer import abc, frommer, xyz
""",
                                          remove_all_unused_imports=True)))
예제 #6
0
    def test_filter_code_should_avoid_inline_except(self):
        line = """\
try: from zap import foo
except: from zap import bar
"""
        self.assertEqual(
            line,
            ''.join(autoflake.filter_code(line,
                                          remove_all_unused_imports=True)))
예제 #7
0
    def test_filter_code_with_from(self):
        self.assertEqual(
            """\
pass
x = 1
""",
            ''.join(autoflake.filter_code("""\
from os import path
x = 1
""")))
예제 #8
0
    def test_filter_code(self):
        self.assertEqual(
            """\
import os
pass
os.foo()
""", ''.join(autoflake.filter_code("""\
import os
import re
os.foo()
""")))
예제 #9
0
    def test_filter_code_with_used_from(self):
        self.assertEqual(
            """\
import frommer
print(frommer)
""",
            ''.join(autoflake.filter_code("""\
import frommer
print(frommer)
""",
                                          remove_all_unused_imports=True)))
예제 #10
0
    def test_filter_code(self):
        self.assertEqual(
            """\
import os
pass
os.foo()
""",
            ''.join(autoflake.filter_code("""\
import os
import re
os.foo()
""")))
예제 #11
0
    def test_filter_code_with_remove_all_unused_imports(self):
        self.assertEqual(
            """\
pass
pass
x = 1
""",
            ''.join(autoflake.filter_code("""\
import foo
import zap
x = 1
""", remove_all_unused_imports=True)))
예제 #12
0
    def test_filter_code_with_additional_imports(self):
        self.assertEqual(
            """\
pass
import zap
x = 1
""",
            ''.join(autoflake.filter_code("""\
import foo
import zap
x = 1
""", additional_imports=['foo', 'bar'])))
예제 #13
0
    def test_filter_code_with_remove_all_unused_imports(self):
        self.assertEqual(
            """\
pass
pass
x = 1
""",
            ''.join(autoflake.filter_code("""\
import foo
import zap
x = 1
""", remove_all_unused_imports=True)))
예제 #14
0
    def test_filter_code_with_additional_imports(self):
        self.assertEqual(
            """\
pass
import zap
x = 1
""",
            ''.join(autoflake.filter_code("""\
import foo
import zap
x = 1
""", additional_imports=['foo', 'bar'])))
예제 #15
0
    def test_filter_code_expand_star_imports(self):
        self.assertEqual(
            """\
from math import sin
sin(1)
""",
            ''.join(autoflake.filter_code("""\
from math import *
sin(1)
""", expand_star_imports=True)))

        self.assertEqual(
            """\
from math import cos, sin
sin(1)
cos(1)
""",
            ''.join(autoflake.filter_code("""\
from math import *
sin(1)
cos(1)
""", expand_star_imports=True)))
예제 #16
0
    def test_filter_code_should_ignore_semicolons(self):
        self.assertEqual(
            r"""\
import os
pass
import os; import math, subprocess
os.foo()
""",
            ''.join(autoflake.filter_code(r"""\
import os
import re
import os; import math, subprocess
os.foo()
""")))
예제 #17
0
    def test_filter_code_should_ignore_imports_with_inline_comment(self):
        self.assertEqual(
            """\
from os import path  # foo
pass
from fake_foo import z  # foo, foo, zap
x = 1
""",
            ''.join(autoflake.filter_code("""\
from os import path  # foo
from os import path
from fake_foo import z  # foo, foo, zap
x = 1
""")))
예제 #18
0
    def test_filter_code_ignore_multiple_star_import(self):
        self.assertEqual(
            """\
from math import *
from re import *
sin(1)
cos(1)
""",
            ''.join(autoflake.filter_code("""\
from math import *
from re import *
sin(1)
cos(1)
""", expand_star_imports=True)))
예제 #19
0
    def test_filter_code_with_indented_import(self):
        self.assertEqual(
            """\
import os
if True:
    pass
os.foo()
""", ''.join(
                autoflake.filter_code("""\
import os
if True:
    import re
os.foo()
""")))
예제 #20
0
    def test_filter_code_should_respect_noqa(self):
        self.assertEqual(
            """\
pass
import re  # noqa
from subprocess import Popen  # NOQA
x = 1
""",
            ''.join(autoflake.filter_code("""\
from os import path
import re  # noqa
from subprocess import Popen  # NOQA
x = 1
""")))
예제 #21
0
    def test_filter_code_should_ignore_semicolons(self):
        self.assertEqual(
            r"""\
import os
pass
import os; import math, subprocess
os.foo()
""", ''.join(
                autoflake.filter_code(r"""\
import os
import re
import os; import math, subprocess
os.foo()
""")))
예제 #22
0
    def test_filter_code_with_indented_import(self):
        self.assertEqual(
            """\
import os
if True:
    pass
os.foo()
""",
            ''.join(autoflake.filter_code("""\
import os
if True:
    import re
os.foo()
""")))
예제 #23
0
    def test_filter_code_should_respect_noqa(self):
        self.assertEqual(
            """\
pass
import re  # noqa
from subprocess import Popen  # NOQA
x = 1
""", ''.join(
                autoflake.filter_code("""\
from os import path
import re  # noqa
from subprocess import Popen  # NOQA
x = 1
""")))
예제 #24
0
    def test_filter_code_should_ignore_imports_with_inline_comment(self):
        self.assertEqual(
            """\
from os import path  # foo
pass
from fake_foo import z  # foo, foo, zap
x = 1
""", ''.join(
                autoflake.filter_code("""\
from os import path  # foo
from os import path
from fake_foo import z  # foo, foo, zap
x = 1
""")))
예제 #25
0
    def test_filter_code_with_special_re_symbols_in_key(self):
        self.assertEqual(
            """\
a = {
  '????': 2,
}
print(a)
""",
            ''.join(autoflake.filter_code("""\
a = {
  '????': 3,
  '????': 2,
}
print(a)
""", remove_duplicate_keys=True)))
예제 #26
0
    def test_filter_code_should_ignore_unsafe_imports(self):
        self.assertEqual(
            """\
import rlcompleter
pass
pass
pass
print(1)
""", ''.join(
                autoflake.filter_code("""\
import rlcompleter
import sys
import io
import os
print(1)
""")))
예제 #27
0
    def test_filter_code_should_ignore_multiline_imports(self):
        self.assertEqual(
            r"""\
import os
pass
import os, \
    math, subprocess
os.foo()
""", ''.join(
                autoflake.filter_code(r"""\
import os
import re
import os, \
    math, subprocess
os.foo()
""")))
예제 #28
0
    def test_filter_code_should_ignore_multiline_imports(self):
        self.assertEqual(
            r"""\
import os
pass
import os, \
    math, subprocess
os.foo()
""",
            ''.join(autoflake.filter_code(r"""\
import os
import re
import os, \
    math, subprocess
os.foo()
""")))
예제 #29
0
    def test_filter_code_should_ignore_unsafe_imports(self):
        self.assertEqual(
            """\
import rlcompleter
pass
pass
pass
print(1)
""",
            ''.join(autoflake.filter_code("""\
import rlcompleter
import sys
import io
import os
print(1)
""")))
예제 #30
0
    def test_filter_code_should_ignore_non_standard_library(self):
        self.assertEqual(
            """\
import os
import my_own_module
pass
from my_package import another_module
from my_package import subprocess
from my_blah.my_blah_blah import blah
os.foo()
""", ''.join(
                autoflake.filter_code("""\
import os
import my_own_module
import re
from my_package import another_module
from my_package import subprocess
from my_blah.my_blah_blah import blah
os.foo()
""")))
예제 #31
0
    def test_filter_code_should_ignore_non_standard_library(self):
        self.assertEqual(
            """\
import os
import my_own_module
pass
from my_package import another_module
from my_package import subprocess
from my_blah.my_blah_blah import blah
os.foo()
""",
            ''.join(autoflake.filter_code("""\
import os
import my_own_module
import re
from my_package import another_module
from my_package import subprocess
from my_blah.my_blah_blah import blah
os.foo()
""")))