How to use autopep8 - 10 common examples

To help you get started, we’ve selected a few autopep8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hhatto / autopep8 / test / test_autopep8.py View on Github external
def test_get_diff_text_without_newline(self):
        # We ignore the first two lines since it differs on Python 2.6.
        self.assertEqual(
            """\
-foo
\\ No newline at end of file
+foo
""",
            '\n'.join(autopep8.get_diff_text(['foo'],
                                             ['foo\n'],
                                             '').split('\n')[3:]))
github hhatto / autopep8 / test / test_autopep8.py View on Github external
def test_get_diff_text(self):
        # We ignore the first two lines since it differs on Python 2.6.
        self.assertEqual(
            """\
-foo
+bar
""",
            '\n'.join(autopep8.get_diff_text(['foo\n'],
                                             ['bar\n'],
                                             '').split('\n')[3:]))
github Tadaboody / good_smell / tests / test_nested_for.py View on Github external
def normalize_formatting(code: str) -> str:
    """Returns a string of the code with normalized formatting(spaces, indents, newlines) for easier compares"""
    return autopep8.fix_code(code, options={"aggressive": 2})
github hhatto / autopep8 / test / test_suite.py View on Github external
def check(expected_filename, input_filename, aggressive):
    """Test and compare output.

    Return True on success.

    """
    got = autopep8.fix_file(
        input_filename,
        options=autopep8.parse_args([''] + aggressive * ['--aggressive']))

    try:
        with autopep8.open_with_encoding(expected_filename) as expected_file:
            expected = expected_file.read()
    except IOError:
        expected = None

    if expected == got:
        return True
    else:
        got_filename = expected_filename + '.err'
        encoding = autopep8.detect_encoding(input_filename)

        with autopep8.open_with_encoding(got_filename,
                                         encoding=encoding,
                                         mode='w') as got_file:
github jazzband / django-silk / silk / code_generation / django_test_client.py View on Github external
data=query_params,
                     lower_case_method=method,
                     content_type=content_type)
    else:
        if query_params:
            query_params = _encode_query_params(query_params)
            path += query_params
        if is_str_typ(data):
            data = "'%s'" % data
        r = t.render(path=path,
                     data=data,
                     lower_case_method=method,
                     query_params=query_params,
                     content_type=content_type)
    return autopep8.fix_code(
        r, options=autopep8.parse_args(['--aggressive', ''])
    )
github hhatto / autopep8 / test / test_suite.py View on Github external
input_filename,
        options=autopep8.parse_args([''] + aggressive * ['--aggressive']))

    try:
        with autopep8.open_with_encoding(expected_filename) as expected_file:
            expected = expected_file.read()
    except IOError:
        expected = None

    if expected == got:
        return True
    else:
        got_filename = expected_filename + '.err'
        encoding = autopep8.detect_encoding(input_filename)

        with autopep8.open_with_encoding(got_filename,
                                         encoding=encoding,
                                         mode='w') as got_file:
            got_file.write(got)

        print(
            '{begin}{got} does not match expected {expected}{end}'.format(
                begin=RED,
                got=got_filename,
                expected=expected_filename,
                end=END),
            file=sys.stdout)

        return False
github hhatto / autopep8 / test / test_suite.py View on Github external
def check(expected_filename, input_filename, aggressive):
    """Test and compare output.

    Return True on success.

    """
    got = autopep8.fix_file(
        input_filename,
        options=autopep8.parse_args([''] + aggressive * ['--aggressive']))

    try:
        with autopep8.open_with_encoding(expected_filename) as expected_file:
            expected = expected_file.read()
    except IOError:
        expected = None

    if expected == got:
        return True
    else:
        got_filename = expected_filename + '.err'
        encoding = autopep8.detect_encoding(input_filename)

        with autopep8.open_with_encoding(got_filename,
                                         encoding=encoding,
                                         mode='w') as got_file:
            got_file.write(got)

        print(
github hhatto / autopep8 / test / test_autopep8.py View on Github external
def temporary_file_context(text, suffix='', prefix=''):
    tempfile = mkstemp(suffix=suffix, prefix=prefix)
    os.close(tempfile[0])
    with autopep8.open_with_encoding(tempfile[1],
                                     encoding='utf-8',
                                     mode='w') as temp_file:
        temp_file.write(text)
    yield tempfile[1]
    os.remove(tempfile[1])
github myint / pyformat / test_acid.py View on Github external
def readlines(filename):
    """Return contents of file as a list of lines."""
    with autopep8.open_with_encoding(
            filename,
            encoding=autopep8.detect_encoding(filename)) as f:
        return f.readlines()
github hhatto / autopep8 / test / acid.py View on Github external
def check_syntax(filename, raise_error=False):
    """Return True if syntax is okay."""
    with autopep8.open_with_encoding(filename) as input_file:
        try:
            compile(input_file.read(), '', 'exec', dont_inherit=True)
            return True
        except (SyntaxError, TypeError, UnicodeDecodeError):
            if raise_error:
                raise
            else:
                return False