Skip to content

Commit 1899827

Browse files
committed
Linting in tests.
1 parent c3184e0 commit 1899827

File tree

4 files changed

+61
-27
lines changed

4 files changed

+61
-27
lines changed

tests/logger_loguru/test_local_decorating.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
from newrelic.api.transaction import current_transaction
2121
from testing_support.fixtures import reset_core_stats_engine
2222
from testing_support.validators.validate_log_event_count import validate_log_event_count
23-
from testing_support.validators.validate_log_event_count_outside_transaction import validate_log_event_count_outside_transaction
23+
from testing_support.validators.validate_log_event_count_outside_transaction import (
24+
validate_log_event_count_outside_transaction,
25+
)
2426

2527

2628
def set_trace_ids():
@@ -31,6 +33,7 @@ def set_trace_ids():
3133
if trace:
3234
trace.guid = "abcdefgh"
3335

36+
3437
def exercise_logging(logger):
3538
set_trace_ids()
3639

@@ -42,7 +45,9 @@ def get_metadata_string(log_message, is_txn):
4245
assert host
4346
entity_guid = application_settings().entity_guid
4447
if is_txn:
45-
metadata_string = f"NR-LINKING|{entity_guid}|{host}|abcdefgh12345678|abcdefgh|Python%20Agent%20Test%20%28logger_loguru%29|"
48+
metadata_string = (
49+
f"NR-LINKING|{entity_guid}|{host}|abcdefgh12345678|abcdefgh|Python%20Agent%20Test%20%28logger_loguru%29|"
50+
)
4651
else:
4752
metadata_string = f"NR-LINKING|{entity_guid}|{host}|||Python%20Agent%20Test%20%28logger_loguru%29|"
4853
formatted_string = f"{log_message} {metadata_string}"
@@ -55,7 +60,7 @@ def test_local_log_decoration_inside_transaction(logger):
5560
@background_task()
5661
def test():
5762
exercise_logging(logger)
58-
assert logger.caplog.records[0] == get_metadata_string('C', True)
63+
assert logger.caplog.records[0] == get_metadata_string("C", True)
5964

6065
test()
6166

@@ -65,7 +70,7 @@ def test_local_log_decoration_outside_transaction(logger):
6570
@validate_log_event_count_outside_transaction(1)
6671
def test():
6772
exercise_logging(logger)
68-
assert logger.caplog.records[0] == get_metadata_string('C', False)
73+
assert logger.caplog.records[0] == get_metadata_string("C", False)
6974

7075
test()
7176

@@ -80,6 +85,6 @@ def patch(record):
8085
def test():
8186
patch_logger = logger.patch(patch)
8287
exercise_logging(patch_logger)
83-
assert logger.caplog.records[0] == get_metadata_string('C-PATCH', False)
88+
assert logger.caplog.records[0] == get_metadata_string("C-PATCH", False)
8489

8590
test()

tests/logger_loguru/test_log_forwarding.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
from newrelic.api.transaction import current_transaction
2121
from testing_support.fixtures import reset_core_stats_engine
2222
from testing_support.validators.validate_log_event_count import validate_log_event_count
23-
from testing_support.validators.validate_log_event_count_outside_transaction import validate_log_event_count_outside_transaction
23+
from testing_support.validators.validate_log_event_count_outside_transaction import (
24+
validate_log_event_count_outside_transaction,
25+
)
2426
from testing_support.validators.validate_log_events import validate_log_events
2527
from testing_support.validators.validate_log_events_outside_transaction import validate_log_events_outside_transaction
2628

@@ -33,23 +35,33 @@ def set_trace_ids():
3335
if trace:
3436
trace.guid = "abcdefgh"
3537

38+
3639
def exercise_logging(logger):
3740
set_trace_ids()
3841

3942
logger.warning("C")
4043
logger.error("D")
4144
logger.critical("E")
42-
45+
4346
assert len(logger.caplog.records) == 3
4447

4548

46-
_common_attributes_service_linking = {"timestamp": None, "hostname": None, "entity.name": "Python Agent Test (logger_loguru)", "entity.guid": None}
47-
_common_attributes_trace_linking = {"span.id": "abcdefgh", "trace.id": "abcdefgh12345678", **_common_attributes_service_linking}
49+
_common_attributes_service_linking = {
50+
"timestamp": None,
51+
"hostname": None,
52+
"entity.name": "Python Agent Test (logger_loguru)",
53+
"entity.guid": None,
54+
}
55+
_common_attributes_trace_linking = {
56+
"span.id": "abcdefgh",
57+
"trace.id": "abcdefgh12345678",
58+
**_common_attributes_service_linking,
59+
}
4860

4961
_test_logging_inside_transaction_events = [
5062
{"message": "C", "level": "WARNING", **_common_attributes_trace_linking},
5163
{"message": "D", "level": "ERROR", **_common_attributes_trace_linking},
52-
{"message": "E", "level": "CRITICAL", **_common_attributes_trace_linking},
64+
{"message": "E", "level": "CRITICAL", **_common_attributes_trace_linking},
5365
]
5466

5567

@@ -67,9 +79,10 @@ def test():
6779
_test_logging_outside_transaction_events = [
6880
{"message": "C", "level": "WARNING", **_common_attributes_service_linking},
6981
{"message": "D", "level": "ERROR", **_common_attributes_service_linking},
70-
{"message": "E", "level": "CRITICAL", **_common_attributes_service_linking},
82+
{"message": "E", "level": "CRITICAL", **_common_attributes_service_linking},
7183
]
7284

85+
7386
@reset_core_stats_engine()
7487
def test_logging_outside_transaction(logger):
7588
@validate_log_events_outside_transaction(_test_logging_outside_transaction_events)
@@ -96,6 +109,7 @@ def test():
96109
_test_patcher_application_captured_event = {"message": "C-PATCH", "level": "WARNING"}
97110
_test_patcher_application_captured_event.update(_common_attributes_trace_linking)
98111

112+
99113
@reset_core_stats_engine()
100114
def test_patcher_application_captured(logger):
101115
def patch(record):
@@ -112,9 +126,11 @@ def test():
112126

113127
test()
114128

129+
115130
_test_logger_catch_event = {"level": "ERROR"} # Message varies wildly, can't be included in test
116131
_test_logger_catch_event.update(_common_attributes_trace_linking)
117132

133+
118134
@reset_core_stats_engine()
119135
def test_logger_catch(logger):
120136
@validate_log_events([_test_logger_catch_event])
@@ -132,5 +148,5 @@ def throw():
132148
throw()
133149
except ValueError:
134150
pass
135-
151+
136152
test()

tests/logger_loguru/test_metrics.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414

1515
from newrelic.api.background_task import background_task
1616
from testing_support.fixtures import reset_core_stats_engine
17-
from testing_support.validators.validate_custom_metrics_outside_transaction import validate_custom_metrics_outside_transaction
17+
from testing_support.validators.validate_custom_metrics_outside_transaction import (
18+
validate_custom_metrics_outside_transaction,
19+
)
1820
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
1921

2022

2123
def exercise_logging(logger):
2224
logger.warning("C")
2325
logger.error("D")
2426
logger.critical("E")
25-
27+
2628
assert len(logger.caplog.records) == 3
2729

2830

@@ -33,6 +35,7 @@ def exercise_logging(logger):
3335
("Logging/lines/CRITICAL", 1),
3436
]
3537

38+
3639
@reset_core_stats_engine()
3740
def test_logging_metrics_inside_transaction(logger):
3841
@validate_transaction_metrics(

tests/logger_loguru/test_settings.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
from testing_support.fixtures import override_application_settings
2323
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
2424

25+
2526
def get_metadata_string(log_message, is_txn):
2627
host = platform.uname().node
2728
assert host
2829
entity_guid = application_settings().entity_guid
2930
if is_txn:
30-
metadata_string = f"NR-LINKING|{entity_guid}|{host}|abcdefgh12345678|abcdefgh|Python%20Agent%20Test%20%28internal_logging%29|"
31+
metadata_string = (
32+
f"NR-LINKING|{entity_guid}|{host}|abcdefgh12345678|abcdefgh|Python%20Agent%20Test%20%28internal_logging%29|"
33+
)
3134
else:
3235
metadata_string = f"NR-LINKING|{entity_guid}|{host}|||Python%20Agent%20Test%20%28internal_logging%29|"
3336
formatted_string = f"{log_message} {metadata_string}"
@@ -49,10 +52,12 @@ def basic_logging(logger):
4952
@pytest.mark.parametrize("feature_setting,subfeature_setting,expected", _settings_matrix)
5053
@reset_core_stats_engine()
5154
def test_log_forwarding_settings(logger, feature_setting, subfeature_setting, expected):
52-
@override_application_settings({
53-
"application_logging.enabled": feature_setting,
54-
"application_logging.forwarding.enabled": subfeature_setting,
55-
})
55+
@override_application_settings(
56+
{
57+
"application_logging.enabled": feature_setting,
58+
"application_logging.forwarding.enabled": subfeature_setting,
59+
}
60+
)
5661
@validate_log_event_count(1 if expected else 0)
5762
@background_task()
5863
def test():
@@ -65,10 +70,12 @@ def test():
6570
@pytest.mark.parametrize("feature_setting,subfeature_setting,expected", _settings_matrix)
6671
@reset_core_stats_engine()
6772
def test_local_decorating_settings(logger, feature_setting, subfeature_setting, expected):
68-
@override_application_settings({
69-
"application_logging.enabled": feature_setting,
70-
"application_logging.local_decorating.enabled": subfeature_setting,
71-
})
73+
@override_application_settings(
74+
{
75+
"application_logging.enabled": feature_setting,
76+
"application_logging.local_decorating.enabled": subfeature_setting,
77+
}
78+
)
7279
@background_task()
7380
def test():
7481
basic_logging(logger)
@@ -86,10 +93,13 @@ def test():
8693
@reset_core_stats_engine()
8794
def test_log_metrics_settings(logger, feature_setting, subfeature_setting, expected):
8895
metric_count = 1 if expected else None
89-
@override_application_settings({
90-
"application_logging.enabled": feature_setting,
91-
"application_logging.metrics.enabled": subfeature_setting,
92-
})
96+
97+
@override_application_settings(
98+
{
99+
"application_logging.enabled": feature_setting,
100+
"application_logging.metrics.enabled": subfeature_setting,
101+
}
102+
)
93103
@validate_transaction_metrics(
94104
"test_settings:test_log_metrics_settings.<locals>.test",
95105
custom_metrics=[

0 commit comments

Comments
 (0)