Skip to content

Commit

Permalink
chore(ci): bs4 & sanic framework test (#9371)
Browse files Browse the repository at this point in the history
Add BeautifulSoup and Sanic to the framework tests.  
Add a small fix in `ddtrace/internal/compat.py` to avoid raising an
error if we receive a mock instead of a string. There is the error:
https://github.com/DataDog/dd-trace-py/actions/runs/9223552867/job/25377041389#step:7:257

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.
- [x] If change touches code that signs or publishes builds or packages,
or handles credentials of any kind, I've requested a review from
`@DataDog/security-design-and-guidance`.


## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
avara1986 authored May 24, 2024
1 parent 6cfc798 commit 4e31278
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 34 deletions.
138 changes: 104 additions & 34 deletions .github/workflows/test_frameworks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,60 @@ jobs:
if: needs.needs-run.outputs.outcome == 'success'
run: cat debugger-expl.txt

# sanic-testsuite-22_12:
# runs-on: ubuntu-20.04
# needs: needs-run
# env:
# # Regression test for DataDog/dd-trace-py/issues/5722
# DD_UNLOAD_MODULES_FROM_SITECUSTOMIZE: true
# CMAKE_BUILD_PARALLEL_LEVEL: 12
# defaults:
# run:
# working-directory: sanic
# steps:
# - uses: actions/checkout@v4
# if: needs.needs-run.outputs.outcome == 'success'
# with:
# path: ddtrace
# - uses: actions/checkout@v4
# if: needs.needs-run.outputs.outcome == 'success'
# with:
# repository: sanic-org/sanic
# ref: v22.12.0
# path: sanic
# - uses: actions/setup-python@v5
# if: needs.needs-run.outputs.outcome == 'success'
# with:
# python-version: "3.11"
# - name: Install sanic and dependencies required to run tests
# if: needs.needs-run.outputs.outcome == 'success'
# run: pip3 install '.[test]' aioquic
# - name: Install ddtrace
# if: needs.needs-run.outputs.outcome == 'success'
# run: pip3 install ../ddtrace
# - name: Run tests
# if: needs.needs-run.outputs.outcome == 'success'
# run: ddtrace-run pytest -k "not test_add_signal and not test_ode_removes and not test_skip_touchup and not test_dispatch_signal_triggers and not test_keep_alive_connection_context and not test_redirect_with_params"
sanic-testsuite-22_12:
strategy:
matrix:
include:
# TODO: profiling fails with a timeout error
#- suffix: Profiling
# profiling: 1
# iast: 0
# appsec: 0
- suffix: IAST
profiling: 0
iast: 1
appsec: 0
- suffix: APPSEC
profiling: 0
iast: 0
appsec: 1
name: Sanic 22.12 (with ${{ matrix.suffix }})
runs-on: ubuntu-20.04
needs: needs-run
env:
DD_PROFILING_ENABLED: ${{ matrix.profiling }}
DD_IAST_ENABLED: ${{ matrix.iast }}
DD_APPSEC_ENABLED: ${{ matrix.appsec }}
DD_TESTING_RAISE: true
CMAKE_BUILD_PARALLEL_LEVEL: 12
DD_DEBUGGER_EXPL_OUTPUT_FILE: debugger-expl.txt
defaults:
run:
working-directory: sanic
steps:
- uses: actions/checkout@v4
if: needs.needs-run.outputs.outcome == 'success'
with:
path: ddtrace
- uses: actions/checkout@v4
if: needs.needs-run.outputs.outcome == 'success'
with:
repository: sanic-org/sanic
ref: v22.12.0
path: sanic
- uses: actions/setup-python@v5
if: needs.needs-run.outputs.outcome == 'success'
with:
python-version: "3.11"
- name: Install sanic and dependencies required to run tests
if: needs.needs-run.outputs.outcome == 'success'
run: pip3 install '.[test]' aioquic
- name: Install ddtrace
if: needs.needs-run.outputs.outcome == 'success'
run: pip3 install ../ddtrace
- name: Run tests
if: needs.needs-run.outputs.outcome == 'success'
run: ddtrace-run pytest -k "not test_no_exceptions_when_cancel_pending_request and not test_add_signal and not test_ode_removes and not test_skip_touchup and not test_dispatch_signal_triggers and not test_keep_alive_connection_context and not test_redirect_with_params"

django-testsuite-3_1:
strategy:
Expand Down Expand Up @@ -864,3 +884,53 @@ jobs:
- name: Debugger exploration results
if: needs.needs-run.outputs.outcome == 'success'
run: cat debugger-expl.txt

beautifulsoup-testsuite-4_12_3:
strategy:
matrix:
include:
# TODO: profiling is disabled due to a bug in the profiler paths
# - suffix: Profiling
# profiling: 1
# iast: 0
# appsec: 0
- suffix: IAST
profiling: 0
iast: 1
appsec: 0
- suffix: APPSEC
profiling: 0
iast: 0
appsec: 1
name: Beautifulsoup 4.12.3 (with ${{ matrix.suffix }})
runs-on: "ubuntu-latest"
needs: needs-run
env:
DD_TESTING_RAISE: true
DD_PROFILING_ENABLED: ${{ matrix.profiling }}
DD_IAST_ENABLED: ${{ matrix.iast }}
DD_APPSEC_ENABLED: ${{ matrix.appsec }}
CMAKE_BUILD_PARALLEL_LEVEL: 12
DD_DEBUGGER_EXPL_OUTPUT_FILE: debugger-expl.txt
steps:
- uses: actions/setup-python@v5
if: needs.needs-run.outputs.outcome == 'success'
with:
python-version: '3.9'
- uses: actions/checkout@v4
if: needs.needs-run.outputs.outcome == 'success'
with:
path: ddtrace
- name: Checkout beautifulsoup
if: needs.needs-run.outputs.outcome == 'success'
run: |
git clone -b 4.12.3 https://git.launchpad.net/beautifulsoup
- name: Install ddtrace
if: needs.needs-run.outputs.outcome == 'success'
run: pip install ddtrace
- name: Pytest fix
if: needs.needs-run.outputs.outcome == 'success'
run: pip install pytest==8.2.1
- name: Run tests
if: needs.needs-run.outputs.outcome == 'success'
run: cd beautifulsoup && ddtrace-run pytest
16 changes: 16 additions & 0 deletions ddtrace/internal/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,32 @@
def ensure_text(s, encoding="utf-8", errors="ignore") -> str:
if isinstance(s, str):
return s

if isinstance(s, bytes):
return s.decode(encoding, errors)

# Skip the check for Mock objects as they are used in tests
from unittest.mock import Mock

if isinstance(s, Mock):
return str(s)

raise TypeError("Expected str or bytes but received %r" % (s.__class__))


def ensure_binary(s, encoding="utf-8", errors="ignore") -> bytes:
if isinstance(s, bytes):
return s

# Skip the check for Mock objects as they are used in tests
from unittest.mock import Mock

if isinstance(s, Mock):
return bytes(s)

if not isinstance(s, str):
raise TypeError("Expected str or bytes but received %r" % (s.__class__))

return s.encode(encoding, errors)


Expand Down

0 comments on commit 4e31278

Please sign in to comment.