-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from jimmylai/formatting_error
[codemod] add integration test for show errors from formatter subprocess call
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
) |