-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose ipc_main
with arguments instead of argparse
#175
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50a78e3
Expose new ipc function to use python arguments instead of argparse
aehernandez 7e227f9
Docs + clearer naming scheme (run_ipc implying that side effects happen)
aehernandez c77ac5f
Lint for cli/__init__.py
aehernandez 04f9d68
Mock-out LintOpts for reusage
aehernandez 9d955a1
Add tests for new run_ipc function
aehernandez c3410bb
Added required header comment to test file
aehernandez b0e9331
Pyre lint
aehernandez 5935d36
Use a temporary directory instead of files to support windows file ac…
aehernandez c572dcd
Added deprecation warning to ipc_main
aehernandez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,105 @@ | ||
# 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. | ||
|
||
import contextlib | ||
import io | ||
import json | ||
import os | ||
import tempfile | ||
from typing import Any, Dict | ||
|
||
from libcst.testing.utils import UnitTest | ||
|
||
from fixit.cli import run_ipc | ||
from fixit.cli.args import LintWorkers | ||
from fixit.cli.tests.test_lint_opts import generate_mock_lint_opt | ||
|
||
|
||
EXPECTED_SUCCESS_REPORT: Dict[str, Any] = json.loads( | ||
"""{"path": "fill-this-out", "status": "success", "reports": ["fake picklable report"]}""" | ||
) | ||
EXPECTED_FAILURE_REPORT: Dict[str, Any] = json.loads( | ||
"""{"path": "fill-this-out", "status": "failure", "reports": ["fake picklable report"]}""" | ||
) | ||
|
||
|
||
class IpcTest(UnitTest): | ||
def setUp(self) -> None: | ||
self.opts = generate_mock_lint_opt() | ||
|
||
def test_single_path_ipc(self) -> None: | ||
with io.StringIO() as buffer, tempfile.TemporaryDirectory() as prefix, contextlib.redirect_stdout( | ||
buffer | ||
): | ||
# create a valid file for the test to run against | ||
path = "path.py" | ||
|
||
with open(os.path.join(prefix, path), "w") as fd: | ||
fd.write("""test_str = 'hello world'""") | ||
|
||
run_ipc( | ||
opts=self.opts, | ||
paths=[path], | ||
prefix=prefix, | ||
workers=LintWorkers.USE_CURRENT_THREAD, | ||
) | ||
|
||
# get values from the buffer before we close it | ||
buffer.flush() | ||
output = buffer.getvalue() | ||
|
||
report = json.loads(output) | ||
|
||
target_report = EXPECTED_SUCCESS_REPORT.copy() | ||
target_report["path"] = os.path.join(prefix, path) | ||
|
||
self.assertDictEqual(report, target_report) | ||
|
||
def test_multi_path_ipc(self) -> None: | ||
with io.StringIO() as buffer, tempfile.TemporaryDirectory() as prefix, contextlib.redirect_stdout( | ||
buffer | ||
): | ||
path_a = "path_a.py" | ||
path_b = "path_b.py" | ||
# this path doesn't exist at all, but the runner should still handle it gracefully | ||
path_c = "does_not_exist.tmp" | ||
|
||
# create a valid file for the test to run against | ||
with open(os.path.join(prefix, path_a), "w") as fd_a: | ||
fd_a.write("""test_str = 'hello world'""") | ||
|
||
# now create an invalid one | ||
# mismatched tab-indent will do the trick | ||
with open(os.path.join(prefix, path_b), "w") as fd_b: | ||
fd_b.write("""\ta = 1\nb = 2""") | ||
|
||
run_ipc( | ||
opts=self.opts, | ||
paths=[path_a, path_b, path_c], | ||
prefix=prefix, | ||
workers=LintWorkers.USE_CURRENT_THREAD, | ||
) | ||
|
||
# get values from the buffer before we close it | ||
buffer.flush() | ||
output = buffer.getvalue() | ||
|
||
# each report is separated by a new-line | ||
reports = output.strip().split("\n") | ||
self.assertEqual(len(reports), 3) | ||
report_a, report_b, report_c = [json.loads(report) for report in reports] | ||
|
||
target_report_a = EXPECTED_SUCCESS_REPORT.copy() | ||
target_report_a["path"] = os.path.join(prefix, path_a) | ||
|
||
target_report_b = EXPECTED_FAILURE_REPORT.copy() | ||
target_report_b["path"] = os.path.join(prefix, path_b) | ||
|
||
target_report_c = EXPECTED_FAILURE_REPORT.copy() | ||
target_report_c["path"] = os.path.join(prefix, path_c) | ||
|
||
self.assertDictEqual(report_a, target_report_a) | ||
self.assertDictEqual(report_b, target_report_b) | ||
self.assertDictEqual(report_c, target_report_c) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's deprecate this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Added a deprecation warning using python's standard
warnings.warn
functionality.