Skip to content

Commit

Permalink
Merge pull request #289 from jimmylai/formatting_error
Browse files Browse the repository at this point in the history
[codemod] add integration test for show errors from formatter subprocess call
  • Loading branch information
Carl Meyer authored Apr 23, 2020
2 parents e5c80df + 675e91d commit 940647e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libcst/codemod/tests/codemod_formatter_error_input.py.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
# pyre-strict

import subprocess # noqa: F401
from contextlib import AsyncExitStack


def fun() -> None:
# this is an explicit syntax error to cause formatter error
async with AsyncExitStack() as stack:
stack
38 changes: 38 additions & 0 deletions libcst/codemod/tests/test_codemod_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
# pyre-strict


import subprocess
import sys

from libcst.testing.utils import UnitTest


class TestCodemodCLI(UnitTest):
def test_codemod_formatter_error_input(self) -> None:
rlt = subprocess.run(
[
"python",
"-m",
"libcst.tool",
"codemod",
"remove_unused_imports.RemoveUnusedImportsCommand",
"libcst/codemod/tests/codemod_formatter_error_input.py.txt",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
version = sys.version_info
if version[0] == 3 and version[1] == 6:
self.assertIn(
"ParserSyntaxError: Syntax Error @ 14:11.", rlt.stderr.decode("utf-8"),
)
else:
self.assertIn(
"error: cannot format -: Cannot parse: 13:10: async with AsyncExitStack() as stack:",
rlt.stderr.decode("utf-8"),
)

0 comments on commit 940647e

Please sign in to comment.