コード例 #1
0
 def test_with_missing_file(self):
     output_file = io.StringIO()
     ignore = StubFile()
     autoflake._main(argv=['my_fake_program', '--in-place', '.fake'],
                     standard_out=output_file,
                     standard_error=ignore)
     self.assertFalse(output_file.getvalue())
コード例 #2
0
 def test_with_missing_file(self):
     output_file = io.StringIO()
     ignore = StubFile()
     autoflake._main(argv=['my_fake_program', '--in-place', '.fake'],
                     standard_out=output_file,
                     standard_error=ignore)
     self.assertFalse(output_file.getvalue())
コード例 #3
0
    def test_in_place_with_with_useless_pass(self):
        with temporary_file("""\
import foo
x = foo
import subprocess
x()

try:
    pass
    import os
except ImportError:
    pass
    import os
    import sys
""") as filename:
            output_file = io.StringIO()
            autoflake._main(argv=['my_fake_program', '--in-place', filename],
                            standard_out=output_file,
                            standard_error=None)
            with open(filename) as f:
                self.assertEqual(
                    """\
import foo
x = foo
x()

try:
    pass
except ImportError:
    pass
""", f.read())
コード例 #4
0
    def test_in_place_with_with_useless_pass(self):
        with temporary_file("""\
import foo
x = foo
import subprocess
x()

try:
    pass
    import os
except ImportError:
    pass
    import os
    import sys
""") as filename:
            output_file = io.StringIO()
            autoflake._main(argv=['my_fake_program', '--in-place', filename],
                            standard_out=output_file,
                            standard_error=None)
            with open(filename) as f:
                self.assertEqual("""\
import foo
x = foo
x()

try:
    pass
except ImportError:
    pass
""", f.read())
コード例 #5
0
ファイル: test_autoflake.py プロジェクト: sargun/autoflake
    def test_redundant_options(self):
        output_file = io.StringIO()
        autoflake._main(argv=['my_fake_program',
                              '--remove-all', '--imports=blah', __file__],
                        standard_out=output_file,
                        standard_error=output_file)

        self.assertIn('redundant', output_file.getvalue())
コード例 #6
0
    def test_redundant_options(self):
        output_file = io.StringIO()
        autoflake._main(argv=['my_fake_program',
                              '--remove-all', '--imports=blah', __file__],
                        standard_out=output_file,
                        standard_error=output_file)

        self.assertIn('redundant', output_file.getvalue())
コード例 #7
0
ファイル: test_autoflake.py プロジェクト: sargun/autoflake
    def test_check_with_empty_file(self):
        line = ''

        with temporary_file(line) as filename:
            output_file = io.StringIO()
            autoflake._main(argv=['my_fake_program', '--check', filename],
                            standard_out=output_file,
                            standard_error=None)
            self.assertEqual('No issues detected!', output_file.getvalue())
コード例 #8
0
    def test_in_place_with_empty_file(self):
        line = ''

        with temporary_file(line) as filename:
            output_file = io.StringIO()
            autoflake._main(argv=['my_fake_program', '--in-place', filename],
                            standard_out=output_file,
                            standard_error=None)
            with open(filename) as f:
                self.assertEqual(line, f.read())
コード例 #9
0
    def test_in_place_with_empty_file(self):
        line = ''

        with temporary_file(line) as filename:
            output_file = io.StringIO()
            autoflake._main(argv=['my_fake_program', '--in-place', filename],
                            standard_out=output_file,
                            standard_error=None)
            with open(filename) as f:
                self.assertEqual(line, f.read())
コード例 #10
0
ファイル: test_autoflake.py プロジェクト: sargun/autoflake
    def test_check_correct_file(self):
        with temporary_file("""\
import foo
x = foo.bar
print(x)
""") as filename:
            output_file = io.StringIO()
            autoflake._main(argv=['my_fake_program', '--check', filename],
                            standard_out=output_file,
                            standard_error=None)
            self.assertEqual('No issues detected!', output_file.getvalue())
コード例 #11
0
    def test_diff(self):
        with temporary_file("""\
import re
import os
import my_own_module
x = 1
""") as filename:
            output_file = io.StringIO()
            autoflake._main(argv=['my_fake_program', filename],
                            standard_out=output_file,
                            standard_error=None)
            self.assertEqual("""\
-import re
-import os
 import my_own_module
 x = 1
""", '\n'.join(output_file.getvalue().split('\n')[3:]))
コード例 #12
0
    def test_ignore_hidden_directories(self):
        with temporary_directory() as directory:
            with temporary_directory(prefix='.',
                                     directory=directory) as inner_directory:

                with temporary_file("""\
import re
import os
""",
                                    directory=inner_directory):

                    output_file = io.StringIO()
                    autoflake._main(
                        argv=['my_fake_program', '--recursive', directory],
                        standard_out=output_file,
                        standard_error=None)
                    self.assertEqual('', output_file.getvalue().strip())
コード例 #13
0
ファイル: test_autoflake.py プロジェクト: sargun/autoflake
    def test_diff(self):
        with temporary_file("""\
import re
import os
import my_own_module
x = 1
""") as filename:
            output_file = io.StringIO()
            autoflake._main(argv=['my_fake_program', filename],
                            standard_out=output_file,
                            standard_error=None)
            self.assertEqual("""\
-import re
-import os
 import my_own_module
 x = 1
""", '\n'.join(output_file.getvalue().split('\n')[3:]))
コード例 #14
0
    def test_ignore_hidden_directories(self):
        with temporary_directory() as directory:
            with temporary_directory(prefix='.',
                                     directory=directory) as inner_directory:

                with temporary_file("""\
import re
import os
""", directory=inner_directory):

                    output_file = io.StringIO()
                    autoflake._main(argv=['my_fake_program',
                                          '--recursive',
                                          directory],
                                    standard_out=output_file,
                                    standard_error=None)
                    self.assertEqual(
                        '',
                        output_file.getvalue().strip())
コード例 #15
0
ファイル: test_autoflake.py プロジェクト: sargun/autoflake
    def test_check_useless_pass(self):
        with temporary_file("""\
import foo
x = foo
import subprocess
x()

try:
    pass
    import os
except ImportError:
    pass
    import os
    import sys
""") as filename:
            output_file = io.StringIO()
            with self.assertRaises(SystemExit) as cm:
                autoflake._main(argv=['my_fake_program', '--check', filename],
                                standard_out=output_file,
                                standard_error=None)
                self.assertEqual(cm.exception.code, 1)
                self.assertEqual('Unused imports/variables detected.',
                                 output_file.getvalue())
コード例 #16
0
 def test_diff_with_nonexistent_file(self):
     output_file = io.StringIO()
     autoflake._main(argv=['my_fake_program', 'nonexistent_file'],
                     standard_out=output_file,
                     standard_error=output_file)
     self.assertIn('no such file', output_file.getvalue().lower())
コード例 #17
0
 def test_diff_with_nonexistent_file(self):
     output_file = io.StringIO()
     autoflake._main(argv=['my_fake_program', 'nonexistent_file'],
                     standard_out=output_file,
                     standard_error=output_file)
     self.assertIn('no such file', output_file.getvalue().lower())