Skip to content

Commit

Permalink
Use six from packages (#1117)
Browse files Browse the repository at this point in the history
* Use six from packages

* Fixup: no pre-commit hook

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
hmstepanek and mergify[bot] authored Apr 10, 2024
1 parent ce988a8 commit 6284d24
Show file tree
Hide file tree
Showing 18 changed files with 778 additions and 750 deletions.
2 changes: 1 addition & 1 deletion newrelic/packages/urllib3/contrib/securetransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import threading
import weakref

import six
from ..packages import six

from .. import util
from ..util.ssl_ import PROTOCOL_TLS_CLIENT
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_features/test_asgi_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import json

import pytest
import six
from bs4 import BeautifulSoup
from testing_support.asgi_testing import AsgiTest
from testing_support.fixtures import override_application_settings
Expand All @@ -34,6 +33,7 @@
get_browser_timing_header,
)
from newrelic.common.encoding_utils import deobfuscate
from newrelic.packages import six

_runtime_error_name = RuntimeError.__module__ + ":" + RuntimeError.__name__

Expand Down
2 changes: 1 addition & 1 deletion tests/agent_features/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import re
import sys

import six
import webtest
from testing_support.fixtures import override_application_settings
from testing_support.validators.validate_custom_parameters import (
Expand All @@ -35,6 +34,7 @@
from newrelic.api.web_transaction import web_transaction
from newrelic.api.wsgi_application import wsgi_application
from newrelic.common.encoding_utils import deobfuscate
from newrelic.packages import six

_runtime_error_name = RuntimeError.__module__ + ":" + RuntimeError.__name__

Expand Down
86 changes: 55 additions & 31 deletions tests/agent_features/test_browser_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,97 +13,121 @@
# limitations under the License.

import pytest
import six
import webtest
from testing_support.fixtures import (
capture_transaction_metrics,
override_application_settings,
)

from newrelic.api.wsgi_application import wsgi_application
from newrelic.packages import six

from testing_support.fixtures import (override_application_settings,
capture_transaction_metrics)

PAGE_CONTENTS = b'Hello World'
PAGE_CONTENTS = b"Hello World"

_browser_enabled_settings = {
'browser_monitoring.enabled': True,
"browser_monitoring.enabled": True,
}

_browser_disabled_settings = {
'browser_monitoring.enabled': False,
"browser_monitoring.enabled": False,
}


@wsgi_application()
def _app_list(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
start_response(status, response_headers)
return [PAGE_CONTENTS]


target_application_list = webtest.TestApp(_app_list)


@wsgi_application()
def _app_iter(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
start_response(status, response_headers)
yield PAGE_CONTENTS


target_application_iter = webtest.TestApp(_app_iter)


@wsgi_application()
def _app_str(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
start_response(status, response_headers)
return PAGE_CONTENTS


target_application_str = webtest.TestApp(_app_str)


@wsgi_application()
def _app_list_exc_1(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
start_response(status, response_headers)
1/0
1 / 0
return [PAGE_CONTENTS]


target_application_list_exc_1 = webtest.TestApp(_app_list_exc_1)


@wsgi_application()
def _app_list_exc_2(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
1/0
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
1 / 0
start_response(status, response_headers)
return [PAGE_CONTENTS]


target_application_list_exc_2 = webtest.TestApp(_app_list_exc_2)


@wsgi_application()
def _app_iter_exc_1(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
start_response(status, response_headers)
1/0
1 / 0
yield PAGE_CONTENTS


target_application_iter_exc_1 = webtest.TestApp(_app_iter_exc_1)


@wsgi_application()
def _app_iter_exc_2(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
1/0
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
1 / 0
start_response(status, response_headers)
yield PAGE_CONTENTS


target_application_iter_exc_2 = webtest.TestApp(_app_iter_exc_2)

_target_applications = [
target_application_list,
target_application_iter,
pytest.param(target_application_str, marks=pytest.mark.skipif(
six.PY3, reason='PY3 webtest expects type(byte) '
'so this test doesnt apply')),
pytest.param(
target_application_str,
marks=pytest.mark.skipif(six.PY3, reason="PY3 webtest expects type(byte) " "so this test doesnt apply"),
),
target_application_list_exc_1,
target_application_list_exc_2,
target_application_iter_exc_1,
target_application_iter_exc_2,
]

@pytest.mark.parametrize('target_application', _target_applications)

@pytest.mark.parametrize("target_application", _target_applications)
def test_metrics_same_with_and_without_browser_middleware(target_application):
with_browser_metrics = []
without_browser_metrics = []
Expand All @@ -112,7 +136,7 @@ def test_metrics_same_with_and_without_browser_middleware(target_application):
@override_application_settings(_browser_enabled_settings)
def run_app_with_browser():
try:
resp = target_application.get('/')
resp = target_application.get("/")
except ZeroDivisionError:
pass
else:
Expand All @@ -122,7 +146,7 @@ def run_app_with_browser():
@override_application_settings(_browser_disabled_settings)
def run_app_without_browser():
try:
resp = target_application.get('/')
resp = target_application.get("/")
except ZeroDivisionError:
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_features/test_exception_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.

import pytest
import six
from testing_support.fixtures import (
reset_core_stats_engine,
set_default_encoding,
Expand All @@ -25,6 +24,7 @@
from newrelic.api.application import application_instance as application
from newrelic.api.background_task import background_task
from newrelic.api.time_trace import notice_error
from newrelic.packages import six

# Turn off black formatting for this section of the code.
# While Python 2 has been EOL'd since 2020, New Relic still
Expand Down
Loading

0 comments on commit 6284d24

Please sign in to comment.