-
Notifications
You must be signed in to change notification settings - Fork 11
Makes v0.6.0 (soon to be v0.6.1) retro-compatible with v0.5.0 #82
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
Merged
se7entyse7en
merged 4 commits into
src-d:master
from
se7entyse7en:analyzer-servicer-default-func
Mar 20, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0c4ecaa
Do not ignore defined Notify{Review,Push}Event methods in analyzers i…
se7entyse7en cbd4f73
Changed lookout.sdk.pb.DataStub import
se7entyse7en 935d4de
Moved testing utilities
se7entyse7en 8053a25
Added test of gRPC unwrapped api
se7entyse7en 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 hidden or 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 hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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,39 @@ | ||
| import socket | ||
| from contextlib import closing | ||
|
|
||
|
|
||
| def find_free_port(): | ||
| with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s: | ||
| s.bind(('', 0)) | ||
| s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
| return s.getsockname()[1] | ||
|
|
||
|
|
||
| class LogFnTracker: | ||
|
|
||
| def __init__(self): | ||
| self.counter = {"unary": 0, "stream": 0} | ||
| self.logs = [] | ||
|
|
||
| def unary(self, log_fields, msg): | ||
| self._record(log_fields, msg, "unary") | ||
|
|
||
| def stream(self, log_fields, msg): | ||
| self._record(log_fields, msg, "stream") | ||
|
|
||
| def _record(self, log_fields, msg, key): | ||
| self.counter[key] += 1 | ||
| self.logs.append((log_fields.fields.copy(), msg)) | ||
|
|
||
|
|
||
| class TestWithRunningServicerMixin: | ||
|
|
||
| def setUp(self): | ||
| self._tracker = LogFnTracker() | ||
| self._target = "0.0.0.0:{}".format(find_free_port()) | ||
| self._server = self.build_server() | ||
| self._server.add_insecure_port(self._target) | ||
| self._server.start() | ||
|
|
||
| def tearDown(self): | ||
| self._server.stop(0) |
This file contains hidden or 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,41 @@ | ||
| import unittest | ||
|
|
||
| from lookout.sdk.grpc import create_channel, create_server | ||
| from lookout.sdk import event_pb2 | ||
| from lookout.sdk import pb | ||
| from lookout.sdk.test import mixins | ||
|
|
||
|
|
||
| class DummyAnalyzer(pb.AnalyzerServicer): | ||
|
|
||
| def NotifyReviewEvent(self, request, context): | ||
| return pb.EventResponse(comments=[pb.Comment(text='review')]) | ||
|
|
||
| def NotifyPushEvent(self, request, context): | ||
| return pb.EventResponse(comments=[pb.Comment(text='push')]) | ||
|
|
||
|
|
||
| class TestGRPCAnalyzerApi(mixins.TestWithRunningServicerMixin, | ||
| unittest.TestCase): | ||
|
|
||
| def build_server(self): | ||
| server = create_server(10) | ||
| pb.add_analyzer_to_server(DummyAnalyzer(), server) | ||
|
|
||
| return server | ||
|
|
||
| def test_review(self): | ||
| with create_channel(self._target) as channel: | ||
| stub = pb.AnalyzerStub(channel) | ||
| resp = stub.NotifyReviewEvent(event_pb2.ReviewEvent()) | ||
|
|
||
| self.assertEqual(len(resp.comments), 1) | ||
| self.assertEqual(resp.comments[0].text, 'review') | ||
|
|
||
| def test_push(self): | ||
| with create_channel(self._target) as channel: | ||
| stub = pb.AnalyzerStub(channel) | ||
| resp = stub.NotifyPushEvent(event_pb2.PushEvent()) | ||
|
|
||
| self.assertEqual(len(resp.comments), 1) | ||
| self.assertEqual(resp.comments[0].text, 'push') |
This file contains hidden or 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.
I knew it's 1 line change!
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.
yeah I was ignoring if the method is actually defined 😅.