Skip to content

Commit cd89cff

Browse files
ci: run tests for legacy versions
1 parent 6a9b3a4 commit cd89cff

File tree

5 files changed

+105
-18
lines changed

5 files changed

+105
-18
lines changed

.github/workflows/test.yml

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ jobs:
5353
fail-fast: false
5454
matrix:
5555
os: [ubuntu-22.04]
56-
# In the future, we need to add support for Python 2.7 and 3.4, as we officially
57-
# support those versions. However, support for those versions has been removed from
58-
# setup-python so we will need to find a workaround.
5956
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14', 'pypy2.7', 'pypy3.8']
6057
# os: [ubuntu-latest, windows-latest, macos-latest]
6158
# python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy-2.7', 'pypy-3.8']
@@ -95,3 +92,68 @@ jobs:
9592

9693
- name: Run admin integration tests on cassettes
9794
run: tox -e integration-admin -- --vcr-record=none
95+
96+
run-legacy:
97+
# actions/setup-python dropped support for Python 2.7 and 3.4, so we use
98+
# official Python Docker images instead to test those EOL-but-supported versions.
99+
name: Python ${{ matrix.python-version }} (legacy) on Linux
100+
runs-on: ubuntu-latest
101+
container:
102+
image: python:${{ matrix.python-version }}
103+
strategy:
104+
fail-fast: false
105+
matrix:
106+
python-version: ['2.7', '3.4']
107+
steps:
108+
# All actions/checkout versions now use Node.js >= 20 (glibc >= 2.25).
109+
# python:3.4 is Debian Stretch (glibc 2.24) so Node.js can't run there.
110+
# Use a plain git clone instead — no Node.js needed.
111+
- name: Checkout
112+
run: |
113+
git init .
114+
git remote add origin https://github.com/${{ github.repository }}
115+
git fetch --depth 1 origin ${{ github.sha }}
116+
git checkout FETCH_HEAD
117+
118+
- name: Set constraints for python2.7
119+
# Latest PyYaml supported version for python 2.7 is 5.4.1 which requires
120+
# cython<3 to build. See: https://github.com/yaml/pyyaml/issues/724
121+
if: ${{ matrix.python-version == '2.7' }}
122+
run: |
123+
echo "cython<3" > /tmp/constraints.txt
124+
echo "PIP_CONSTRAINT=/tmp/constraints.txt" >> $GITHUB_ENV
125+
126+
- name: Set constraints for python3.4
127+
# PyYAML 5.3+ dropped Python 3.4 support; vcrpy pulls it in.
128+
if: ${{ matrix.python-version == '3.4' }}
129+
run: |
130+
echo "PyYAML<5.3" > /tmp/constraints.txt
131+
echo "PIP_CONSTRAINT=/tmp/constraints.txt" >> $GITHUB_ENV
132+
133+
- name: Set TOXENV
134+
# Use tr instead of ${//} because the container runs sh, not bash.
135+
run: |
136+
version="${{ matrix.python-version }}"
137+
echo "TOXENV=py$(echo "$version" | tr -d '.')" >> $GITHUB_ENV
138+
139+
- name: Install tox
140+
# tox 4+ requires Python 3.7+; virtualenv 20.22+ dropped Python 2.7 support.
141+
run: pip install 'tox<4' 'virtualenv<20.22'
142+
143+
- name: Run unit tests
144+
# Disable origin detection: the job runs inside a Docker container, so
145+
# the client would detect the container ID and append |c:<id> to every
146+
# metric, which the tests don't expect.
147+
env:
148+
DD_ORIGIN_DETECTION_ENABLED: "false"
149+
run: tox
150+
151+
- name: Run integration tests on cassettes
152+
env:
153+
DD_ORIGIN_DETECTION_ENABLED: "false"
154+
run: tox -e integration -- --vcr-record=none
155+
156+
- name: Run admin integration tests on cassettes
157+
env:
158+
DD_ORIGIN_DETECTION_ENABLED: "false"
159+
run: tox -e integration-admin -- --vcr-record=none

datadog/dogshell/wrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def parse_options(raw_args=None):
413413
if is_p3k():
414414
cmd = " ".join(args)
415415
else:
416-
cmd = b" ".join(a.encode("utf-8") for a in args).decode("utf-8")
416+
cmd = b" ".join(a if isinstance(a, bytes) else a.encode("utf-8") for a in args).decode("utf-8")
417417

418418
return options, cmd
419419

tests/integration/dogshell/test_dogshell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def test_security_monitoring_rules(self, dogshell, get_unique, tmp_path):
750750
"type": "log_detection"
751751
}
752752

753-
with open(rule_file, "w") as f:
753+
with open(str(rule_file), "w") as f:
754754
json.dump(rule_data, f)
755755

756756
# Create rule
@@ -772,7 +772,7 @@ def test_security_monitoring_rules(self, dogshell, get_unique, tmp_path):
772772
updated_name = "Updated Rule {}".format(unique)
773773
rule_data["name"] = updated_name
774774

775-
with open(rule_file, "w") as f:
775+
with open(str(rule_file), "w") as f:
776776
json.dump(rule_data, f)
777777

778778
out, _, _ = dogshell(["security-monitoring", "rules", "update", rule_id, "--file", str(rule_file)])

tests/unit/dogstatsd/test_max_sample_metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
import threading
23
import unittest
34
from mock import patch

tox.ini

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ envlist =
99
# black - see comments below
1010

1111
[testenv]
12-
passenv = DD_TEST_CLIENT*
12+
passenv =
13+
DD_TEST_CLIENT*
14+
DD_ORIGIN_DETECTION_ENABLED
1315
usedevelop = true
1416
deps =
1517
click
@@ -23,24 +25,43 @@ commands =
2325
!integration: pytest -v tests/unit {posargs}
2426
integration: pytest -v tests/integration -m "not admin_needed" {posargs}
2527

28+
[testenv:integration]
29+
# Use skip_install + PYTHONPATH so this env works on Python 3.4 too
30+
# (hatchling can't be built there). requests must be listed explicitly
31+
# since it is a runtime dep normally pulled in by the package install.
32+
skip_install = true
33+
setenv = PYTHONPATH = {toxinidir}
34+
deps =
35+
{[testenv]deps}
36+
requests>=2.6.0
37+
typing
38+
2639
[testenv:integration-admin]
27-
passenv = DD_TEST_CLIENT*
28-
usedevelop = true
40+
skip_install = true
41+
setenv = PYTHONPATH = {toxinidir}
2942
deps =
30-
click
31-
freezegun
32-
mock
33-
pytest
34-
pytest-vcr
35-
python-dateutil
36-
vcrpy
43+
{[testenv]deps}
44+
requests>=2.6.0
45+
typing
3746
commands =
3847
pytest -v tests/integration -m "admin_needed" {posargs}
3948

49+
[testenv:py34]
50+
# hatchling (the build backend in pyproject.toml) cannot be installed on
51+
# Python 3.4 because it transitively requires pluggy>=1.0.0 which has no
52+
# Python-3.4-compatible release. Skip the package install and expose the
53+
# source via PYTHONPATH instead, adding the runtime deps explicitly.
54+
skip_install = true
55+
setenv = PYTHONPATH = {toxinidir}
56+
deps =
57+
{[testenv]deps}
58+
requests>=2.6.0
59+
typing
60+
4061
[testenv:flake8]
4162
skip_install = true
4263
deps =
43-
flake8==3.7.9
64+
flake8==7.1.2
4465
commands = flake8 datadog
4566

4667
# Black isn't safe to run while support is being maintained for python2.7, but
@@ -61,7 +82,10 @@ commands =
6182

6283
[flake8]
6384
max-line-length = 120
64-
ignore = E203,W503
85+
# E203, W503: formatting disagreements with black
86+
# F401: pyflakes 3.x no longer tracks # type: comment usages, producing false
87+
# positives for all typing imports used only in PEP 484 type comments.
88+
ignore = E203,W503,F401
6589

6690
[pytest]
6791
markers =

0 commit comments

Comments
 (0)