Skip to content

Commit

Permalink
Merge pull request #526 from JMGuisadoG/master
Browse files Browse the repository at this point in the history
return diff exit code when reading from stdin too
  • Loading branch information
hhatto committed Feb 20, 2020
2 parents 107e29d + 881a3d8 commit fded37b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions autopep8.py
Expand Up @@ -4281,11 +4281,16 @@ def main(argv=None, apply_config=True):
assert not args.in_place

encoding = sys.stdin.encoding or get_encoding()
read_stdin = sys.stdin.read()
fixed_stdin = fix_code(read_stdin, args, encoding=encoding)

# LineEndingWrapper is unnecessary here due to the symmetry between
# standard in and standard out.
wrap_output(sys.stdout, encoding=encoding).write(
fix_code(sys.stdin.read(), args, encoding=encoding))
wrap_output(sys.stdout, encoding=encoding).write(fixed_stdin)

if hash(read_stdin) != hash(fixed_stdin):
if args.exit_code:
return EXIT_CODE_EXISTS_DIFF
else:
if args.in_place or args.diff:
args.files = list(set(args.files))
Expand Down
11 changes: 11 additions & 0 deletions test/test_autopep8.py
Expand Up @@ -5378,6 +5378,17 @@ def test_standard_in(self):
fixed,
process.communicate(line.encode('utf-8'))[0].decode('utf-8'))

def test_exit_code_should_be_set_when_standard_in(self):
line = 'print( 1 )\n'
process = Popen(list(AUTOPEP8_CMD_TUPLE) +
['--exit-code', '-'],
stdout=PIPE,
stdin=PIPE)
process.communicate(line.encode('utf-8'))[0].decode('utf-8')
self.assertEqual(
process.returncode,
autopep8.EXIT_CODE_EXISTS_DIFF)


class ConfigurationTests(unittest.TestCase):

Expand Down

0 comments on commit fded37b

Please sign in to comment.