8000 pylint fixes for code and tests (#268) · sherlock666/botbuilder-python@de81087 · GitHub
[go: up one dir, main page]

Skip to content

Commit de81087

Browse files
authored
pylint fixes for code and tests (microsoft#268)
1 parent c6a6a69 commit de81087

File tree

5 files changed

+99
-84
lines changed

5 files changed

+99
-84
lines changed

libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/application_insights_telemetry_client.py

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import traceback
66
from typing import Dict
7-
from applicationinsights import TelemetryClient
7+
from applicationinsights import TelemetryClient # pylint: disable=no-name-in-module
88
from botbuilder.core.bot_telemetry_client import (
99
BotTelemetryClient,
1010
TelemetryDataPointType,
1111
)
1212
from .integration_post_data import IntegrationPostData
1313

14-
# pylint: disable=line-too-long
14+
1515
def bot_telemetry_processor(data, context) -> bool:
1616
""" Application Insights Telemetry Processor for Bot
1717
Traditional Web user and session ID's don't apply for Bots. This processor
@@ -92,8 +92,10 @@ def track_pageview(
9292
:param name: the name of the page that was viewed.
9393
:param url: the URL of the page that was viewed.
9494
:param duration: the duration of the page view in milliseconds. (defaults to: 0)
95-
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
96-
:param measurements: the set of custom measurements the client wants to attach to this data item. (defaults to: None)
95+
:param properties: the set of custom properties the client wants attached to this data item.
96+
(defaults to: None)
97+
:param measurements: the set of custom measurements the client wants to attach to this data item.
98+
(defaults to: None)
9799
"""
98100
self._client.track_pageview(name, url, duration, properties, measurements)
99101

@@ -110,8 +112,10 @@ def track_exception(
110112
:param exception_type: the type of the exception that was thrown.
111113
:param value: the exception that the client wants to send.
112114
:param tb: the traceback information as returned by :func:`sys.exc_info`.
113-
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
114-
:param measurements: the set of custom measurements the client wants to attach to this data item. (defaults to: None)
115+
:param properties: the set of custom properties the client wants attached to this data item.
116+
(defaults to: None)
117+
:param measurements: the set of custom measurements the client wants to attach to this data item.
118+
(defaults to: None)
115119
"""
116120
self._client.track_exception(
117121
exception_type, value, tb, properties, measurements
@@ -126,8 +130,10 @@ def track_event(
126130
"""
127131
Send information about a single event that has occurred in the context of the application.
128132
:param name: the data to associate to this event.
129-
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
130-
:param measurements: the set of custom measurements the client wants to attach to this data item. (defaults to: None)
133+
:param properties: the set of custom properties the client wants attached to this data item.
134+
(defaults to: None)
135+
:param measurements: the set of custom measurements the client wants to attach to this data item.
136+
(defaults to: None)
131137
"""
132138
self._client.track_event(name, properties=properties, measurements=measurements)
133139

@@ -148,10 +154,14 @@ def track_metric(
148154
:param value: The value of the metric that was captured.
149155
:param tel_type: The type of the metric. (defaults to: TelemetryDataPointType.aggregation`)
150156
:param count: the number of metrics that were aggregated into this data point. (defaults to: None)
151-
:param min_val: the minimum of all metrics collected that were aggregated into this data point. (defaults to: None)
152-
:param max_val: the maximum of all metrics collected that were aggregated into this data point. (defaults to: None)
153-
:param std_dev: the standard deviation of all metrics collected that were aggregated into this data point. (defaults to: None)
154-
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
157+
:param min_val: the minimum of all metrics collected that were aggregated into this data point.
158+
(defaults to: None)
159+
:param max_val: the maximum of all metrics collected that were aggregated into this data point.
160+
(defaults to: None)
161+
:param std_dev: the standard deviation of all metrics collected that were aggregated into this data point.
162+
(defaults to: None)
163+
:param properties: the set of custom properties the client wants attached to this data item.
164+
(defaults to: None)
155165
"""
156166
self._client.track_metric(
157167
name, value, tel_type, count, min_val, max_val, std_dev, properties
@@ -186,12 +196,15 @@ def track_request(
186196
:param name: The name for this request. All requests with the same name will be grouped together.
187197
:param url: The actual URL for this request (to show in individual request instances).
188198 F438
:param success: True if the request ended in success, False otherwise.
189-
:param start_time: the start time of the request. The value should look the same as the one returned by :func:`datetime.isoformat()` (defaults to: None)
199+
:param start_time: the start time of the request. The value should look the same as the one returned by
200+
:func:`datetime.isoformat()` (defaults to: None)
190201
:param duration: the number of milliseconds that this request lasted. (defaults to: None)
191202
:param response_code: the response code that this request returned. (defaults to: None)
192203
:param http_method: the HTTP method that triggered this request. (defaults to: None)
193-
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
194-
:param measurements: the set of custom measurements the client wants to attach to this data item. (defaults to: None)
204+
:param properties: the set of custom properties the client wants attached to this data item.
205+
(defaults to: None)
206+
:param measurements: the set of custom measurements the client wants to attach to this data item.
207+
(defaults to: None)
195208
:param request_id: the id for this request. If None, a new uuid will be generated. (defaults to: None)
196209
"""
197210
self._client.track_request(
@@ -222,15 +235,24 @@ def track_dependency(
222235
):
223236
"""
224237
Sends a single dependency telemetry that was captured for the application.
225-
:param name: the name of the command initiated with this dependency call. Low cardinality value. Examples are stored procedure name and URL path template.
226-
:param data: the command initiated by this dependency call. Examples are SQL statement and HTTP URL with all query parameters.
227-
:param type_name: the dependency type name. Low cardinality value for logical grouping of dependencies and interpretation of other fields like commandName and resultCode. Examples are SQL, Azure table, and HTTP. (default to: None)
228-
:param target: the target site of a dependency call. Examples are server name, host address. (default to: None)
229-
:param duration: the number of milliseconds that this dependency call lasted. (defaults to: None)
230-
:param success: true if the dependency call ended in success, false otherwise. (defaults to: None)
231-
:param result_code: the result code of a dependency call. Examples are SQL error code and HTTP status code. (defaults to: None)
238+
:param name: the name of the command initiated with this dependency call. Low cardinality value.
239+
Examples are stored procedure name and URL path template.
240+
:param data: the command initiated by this dependency call.
241+
Examples are SQL statement and HTTP URL with all query parameters.
242+
:param type_name: the dependency type name. Low cardinality value for logical grouping of dependencies and
243+
interpretation of other fields like commandName and resultCode. Examples are SQL, Azure table, and HTTP.
244+
(default to: None)
245+
:param target: the target site of a dependency call. Examples are server name, host address.
246+
(default to: None)
247+
:param duration: the number of milliseconds that this dependency call lasted.
248+
(defaults to: None)
249+
:param success: true if the dependency call ended in success, false otherwise.
250+
(defaults to: None)
251+
:param result_code: the result code of a dependency call. Examples are SQL error code and HTTP status code.
252+
(defaults to: None)
232253
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
233-
:param measurements: the set of custom measurements the client wants to attach to this data item. (defaults to: None)
254+
:param measurements: the set of custom measurements the client wants to attach to this data item.
255+
(defaults to: None)
234256
:param id: the id for this dependency call. If None, a new uuid will be generated. (defaults to: None)
235257
"""
236258
self._client.track_dependency(

libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/integration_post_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ def activity_json(self) -> json:
3535
body = json.loads(body_text) if body_text is not None else None
3636
return body
3737

38-
def get_request_body(self) -> str:
38+
def get_request_body(self) -> str: # pylint: disable=inconsistent-return-statements
3939
"""Retrieve the request body from flask/django middleware component."""
4040
if self.detect_flask():
4141
return retrieve_flask_body()
42-
else:
43-
if self.detect_django():
44-
# Retrieve from Middleware cache
45-
return retrieve_bot_body()
42+
43+
if self.detect_django():
44+
# Retrieve from Middleware cache
45+
return retrieve_bot_body()
4646

4747
def detect_flask(self) -> bool:
4848
"""Detects if running in flask."""

libraries/botbuilder-applicationinsights/tests/test_telemetry_waterfall.py

Lines changed: 28 additions & 34 deletions
< 1241 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
5-
import aiounittest
4+
from unittest.mock import patch
65
from typing import Dict
7-
from botbuilder.applicationinsights import ApplicationInsightsTelemetryClient
6+
import aiounittest
87
from botbuilder.core.adapters import TestAdapter, TestFlow
98
from botbuilder.schema import Activity
109
from botbuilder.core import (
@@ -16,19 +15,14 @@
1615
from botbuilder.dialogs import (
1716
Dialog,
1817
DialogSet,
19-
DialogState,
2018
WaterfallDialog,
21-
WaterfallStepContext,
2219
DialogTurnResult,
23-
DialogContext,
2420
DialogTurnStatus,
2521
)
26-
from unittest.mock import patch
27-
from unittest import skip
2822

29-
begin_message = Activity()
30-
begin_message.text = "begin"
31-
begin_message.type = "message"
23+
BEGIN_MESSAGE = Activity()
24+
BEGIN_MESSAGE.text = "begin"
25+
BEGIN_MESSAGE.type = "message"
3226

3327

3428
class TelemetryWaterfallTests(aiounittest.AsyncTestCase):
@@ -41,7 +35,7 @@ def test_none_telemetry_client(self):
4135
self.assertEqual(type(dialog.telemetry_client), NullTelemetryClient)
4236

4337
@patch("botbuilder.applicationinsights.ApplicationInsightsTelemetryClient")
44-
async def test_execute_sequence_waterfall_steps(self, MockTelemetry):
38+
async def test_execute_sequence_waterfall_steps(self, MockTelemetry): # pylint: disable=invalid-name
4539
# arrange
4640

4741
# Create new ConversationState with MemoryStorage and register the state as middleware.
@@ -62,17 +56,17 @@ async def step2(step) -> DialogTurnResult:
6256

6357
# act
6458

65-
mydialog = WaterfallDialog("test", [step1, step2])
66-
mydialog.telemetry_client = telemetry
67-
dialogs.add(mydialog)
59+
my_dialog = WaterfallDialog("test", [step1, step2])
60+
my_dialog.telemetry_client = telemetry
61+
dialogs.add(my_dialog)
6862

6963
# Initialize TestAdapter
7064
async def exec_test(turn_context: TurnContext) -> None:
7165

72-
dc = await dialogs.create_context(turn_context)
73-
results = await dc.continue_dialog()
66+
dialog_context = await dialogs.create_context(turn_context)
67+
results = await dialog_context.continue_dialog()
7468
if results.status == DialogTurnStatus.Empty:
75-
await dc.begin_dialog("test")
69+
await dialog_context.begin_dialog("test")
7670
else:
7771
if results.status == DialogTurnStatus.Complete:
7872
await turn_context.send_activity(results.result)
@@ -81,11 +75,11 @@ async def exec_test(turn_context: TurnContext) -> None:
8175

8276
adapt = TestAdapter(exec_test)
8377

84-
tf = TestFlow(None, adapt)
85-
tf2 = await tf.send(begin_message)
78+
test_flow = TestFlow(None, adapt)
79+
tf2 = await test_flow.send(BEGIN_MESSAGE)
8680
tf3 = await tf2.assert_reply("bot responding.")
8781
tf4 = await tf3.send("continue")
88-
tf5 = await tf4.assert_reply("ending WaterfallDialog.")
82+
await tf4.assert_reply("ending WaterfallDialog.")
8983

9084
# assert
9185

@@ -97,7 +91,7 @@ async def exec_test(turn_context: TurnContext) -> None:
9791
self.assert_telemetry_calls(telemetry, telemetry_calls)
9892

9993
@patch("botbuilder.applicationinsights.ApplicationInsightsTelemetryClient")
100-
async def test_ensure_end_dialog_called(self, MockTelemetry):
94+
async def test_ensure_end_dialog_called(self, MockTelemetry): # pylint: disable=invalid-name
10195
# arrange
10296

10397
# Create new ConversationState with MemoryStorage and register the state as middleware.
@@ -118,23 +112,23 @@ async def step2(step) -> DialogTurnResult:
118112

119113
# act
120114

121-
mydialog = WaterfallDialog("test", [step1, step2])
122-
mydialog.telemetry_client = telemetry
123-
dialogs.add(mydialog)
115+
my_dialog = WaterfallDialog("test", [step1, step2])
116+
my_dialog.telemetry_client = telemetry
117+
dialogs.add(my_dialog)
124118

125119
# Initialize TestAdapter
126120
async def exec_test(turn_context: TurnContext) -> None:
127121

128-
dc = await dialogs.create_context(turn_context)
129-
results = await dc.continue_dialog()
130-
if turn_context.responded == False:
131-
await dc.begin_dialog("test", None)
122+
dialog_context = await dialogs.create_context(turn_context)
123+
await dialog_context.continue_dialog()
124+
if not turn_context.responded:
125+
await dialog_context.begin_dialog("test", None)
132126
await convo_state.save_changes(turn_context)
133127

134128
adapt = TestAdapter(exec_test)
135129

136-
tf = TestFlow(None, adapt)
137-
tf2 = await tf.send(begin_message)
130+
test_flow = TestFlow(None, adapt)
131+
tf2 = await test_flow.send(BEGIN_MESSAGE)
138132
tf3 = await tf2.assert_reply("step1 response")
139133
tf4 = await tf3.send("continue")
140134
tf5 = await tf4.assert_reply("step2 response")
@@ -156,15 +150,15 @@ async def exec_test(turn_context: TurnContext) -> None:
156150
def assert_telemetry_call(
157151
self, telemetry_mock, index: int, event_name: str, props: Dict[str, str]
158152
) -> None:
159-
args, kwargs = telemetry_mock.track_event.call_args_list[index]
153+
args, kwargs = telemetry_mock.track_event.call_args_list[index] # pylint: disable=unused-variable
160154
self.assertEqual(args[0], event_name)
161155

162156
for key, val in props.items():
163157
self.assertTrue(
164158
key in args[1],
165159
msg=f"Could not find value {key} in {args[1]} for index {index}",
166160
)
167-
self.assertTrue(type(args[1]) == dict)
161+
self.assertTrue(isinstance(args[1], dict))
168162
self.assertTrue(val == args[1][key])
169163

170164
def assert_telemetry_calls(self, telemetry_mock, calls) -> None:
@@ -173,7 +167,7 @@ def assert_telemetry_calls(self, telemetry_mock, calls) -> None:
173167
self.assert_telemetry_call(telemetry_mock, index, event_name, props)
174168
index += 1
175169
if index != len(telemetry_mock.track_event.call_args_list):
176-
self.assertTrue(
170+
self.assertTrue( # pylint: disable=redundant-unittest-assert
177171
False,
178172
f"Found {len(telemetry_mock.track_event.call_args_list)} calls, testing for {index + 1}",
179173
)

libraries/botbuilder-core/botbuilder/core/bot_telemetry_client.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ def track_pageview(
3838
@abstractmethod
3939
def track_exception(
4040
self,
41-
type: type = None,
41+
exception_type: type = None,
4242
value: Exception = None,
4343
trace: traceback = None,
4444
properties: Dict[str, object] = None,
4545
measurements: Dict[str, object] = None,
4646
) -> None:
4747
"""
4848
Send information about a single exception that occurred in the application.
49-
:param type: the type of the exception that was thrown.
49+
:param exception_type: the type of the exception that was thrown.
5050
:param value: the exception that the client wants to send.
5151
:param trace: the traceback information as returned by :func:`sys.exc_info`.
5252
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
@@ -80,23 +80,22 @@ def track_metric(
8080
self,
8181
name: str,
8282
value: float,
83-
type: TelemetryDataPointType = None,
83+
tel_type: TelemetryDataPointType = None,
8484
count: int = None,
85-
min: float = None,
86-
max: float = None,
85+
min_val: float = None,
86+
max_val: float = None,
8787
std_dev: float = None,
8888
properties: Dict[str, object] = None,
8989
) -> NotImplemented:
9090
"""
9191
Send information about a single metric data point that was captured for the application.
9292
:param name: The name of the metric that was captured.
9393
:param value: The value of the metric that was captured.
94-
:param type: The type of the metric. (defaults to: TelemetryDataPointType.aggregation`)
94+
:param tel_type: The type of the metric. (defaults to: TelemetryDataPointType.aggregation`)
9595
:param count: the number of metrics that were aggregated into this data point. (defaults to: None)
96-
:param min: the minimum of all metrics collected that were aggregated into this data point. (defaults to: None)
97-
:param max: the maximum of all metrics collected that were aggregated into this data point. (defaults to: None)
96+
:param min_val: the minimum of all metrics collected that were aggregated into this data point. (defaults to: None)
97+
:param max_val: the maximum of all metrics collected that were aggregated into this data point. (defaults to: None)
9898
:param std_dev: the standard deviation of all metrics collected that were aggregated into this data point. \
99-
(defaults to: None)
10099
:param properties: the set of custom properties the client wants attached to this data item. (defaults to: None)
101100
"""
102101
raise NotImplementedError(
@@ -153,7 +152,7 @@ def track_dependency(
153152
self,
154153
name: str,
155154
data: str,
156-
type: str = None,
155+
type_name: str = None,
157156
target: str = None,
158157
duration: int = None,
159158
success: bool = None,
@@ -168,7 +167,7 @@ def track_dependency(
168167
Examples are stored procedure name and URL path template.
169168
:param data: the command initiated by this dependency call. \
170169
Examples are SQL statement and HTTP URL with all query parameters.
171-
:param type: the dependency type name. Low cardinality value for logical grouping of dependencies and \
170+
:param type_name: the dependency type name. Low cardinality value for logical grouping of dependencies and \
172171
interpretation of other fields like commandName and resultCode. Examples are SQL, Azure table, and HTTP. \
173172
(default to: None)
174173
:param target: the target site of a dependency call. Examples are server name, host address. (default to: None)

0 commit comments

Comments
 (0)
0