Skip to content

Commit 1787f64

Browse files
[7.x] Start testing on Python 3.10
Co-authored-by: Seth Michael Larson <seth.larson@elastic.co>
1 parent ce6be4c commit 1787f64

File tree

6 files changed

+52
-13
lines changed

6 files changed

+52
-13
lines changed

.ci/test-matrix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PYTHON_VERSION:
1212
- 3.7
1313
- 3.8
1414
- 3.9
15+
- 3.10
1516

1617
PYTHON_CONNECTION_CLASS:
1718
- Urllib3HttpConnection

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Checkout Repository
1111
uses: actions/checkout@v1
1212
- name: Set up Python 3.7
13-
uses: actions/setup-python@v1
13+
uses: actions/setup-python@v2
1414
with:
1515
python-version: 3.7
1616
- name: Install dependencies
@@ -25,7 +25,7 @@ jobs:
2525
- name: Checkout Repository
2626
uses: actions/checkout@v1
2727
- name: Set up Python 3.7
28-
uses: actions/setup-python@v1
28+
uses: actions/setup-python@v2
2929
with:
3030
python-version: 3.7
3131
- name: Install dependencies
@@ -41,7 +41,7 @@ jobs:
4141
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
4242
experimental: [false]
4343
include:
44-
- python-version: 3.9-dev
44+
- python-version: 3.10.0-beta.2
4545
experimental: true
4646

4747
runs-on: ubuntu-latest
@@ -51,7 +51,7 @@ jobs:
5151
- name: Checkout Repository
5252
uses: actions/checkout@v1
5353
- name: Set Up Python - ${{ matrix.python-version }}
54-
uses: actions/setup-python@v1
54+
uses: actions/setup-python@v2
5555
with:
5656
python-version: ${{ matrix.python-version }}
5757
- name: Install Dependencies

dev-requirements.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ mock
66
sphinx<1.7
77
sphinx_rtd_theme
88
jinja2
9-
numpy
10-
pandas
9+
10+
# No wheels for Python 3.10 yet!
11+
numpy; python_version<"3.10"
12+
pandas; python_version<"3.10"
1113

1214
# PyYAML 5.3 dropped support for Python 3.4 while
1315
# not amending that requirement to the package. :(
14-
pyyaml<5.3
16+
pyyaml>=5.4; python_version>="3.6"
17+
pyyaml<5.3; python_version<"3.6"
1518

1619
isort
1720
black; python_version>="3.6"

elasticsearch/_async/http_aiohttp.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ def __init__(
167167

168168
self.ssl_assert_fingerprint = ssl_assert_fingerprint
169169
if self.use_ssl and ssl_context is None:
170-
ssl_context = ssl.SSLContext(ssl_version or ssl.PROTOCOL_TLS)
170+
if ssl_version is None:
171+
ssl_context = ssl.create_default_context()
172+
else:
173+
ssl_context = ssl.SSLContext(ssl_version)
171174

172175
# Convert all sentinel values to their actual default
173176
# values if not using an SSLContext.
@@ -180,8 +183,8 @@ def __init__(
180183
ssl_context.verify_mode = ssl.CERT_REQUIRED
181184
ssl_context.check_hostname = True
182185
else:
183-
ssl_context.verify_mode = ssl.CERT_NONE
184186
ssl_context.check_hostname = False
187+
ssl_context.verify_mode = ssl.CERT_NONE
185188

186189
ca_certs = CA_CERTS if ca_certs is None else ca_certs
187190
if verify_certs:

test_elasticsearch/test_async/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async def test_nowarn_when_test_uses_https_if_verify_certs_is_off(self):
265265
use_ssl=True, verify_certs=False, ssl_show_warn=False
266266
)
267267
await con._create_aiohttp_session()
268-
assert 0 == len(w)
268+
assert w == []
269269

270270
assert isinstance(con.session, aiohttp.ClientSession)
271271

@@ -277,7 +277,7 @@ def test_no_warning_when_using_ssl_context(self):
277277
ctx = ssl.create_default_context()
278278
with warnings.catch_warnings(record=True) as w:
279279
AIOHttpConnection(ssl_context=ctx)
280-
assert 0 == len(w), str([x.message for x in w])
280+
assert w == [], str([x.message for x in w])
281281

282282
def test_warns_if_using_non_default_ssl_kwargs_with_ssl_context(self):
283283
for kwargs in (

test_elasticsearch/test_serializer.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
from datetime import datetime
2222
from decimal import Decimal
2323

24-
import numpy as np
25-
import pandas as pd
24+
try:
25+
import numpy as np
26+
import pandas as pd
27+
except ImportError:
28+
np = pd = None
2629

2730
from elasticsearch.exceptions import ImproperlyConfigured, SerializationError
2831
from elasticsearch.serializer import (
@@ -35,6 +38,11 @@
3538
from .test_cases import SkipTest, TestCase
3639

3740

41+
def requires_numpy_and_pandas():
42+
if np is None or pd is None:
43+
raise SkipTest("Test requires numpy or pandas to be available")
44+
45+
3846
class TestJSONSerializer(TestCase):
3947
def test_datetime_serialization(self):
4048
self.assertEqual(
@@ -43,6 +51,8 @@ def test_datetime_serialization(self):
4351
)
4452

4553
def test_decimal_serialization(self):
54+
requires_numpy_and_pandas()
55+
4656
if sys.version_info[:2] == (2, 6):
4757
raise SkipTest("Float rounding is broken in 2.6.")
4858
self.assertEqual('{"d":3.8}', JSONSerializer().dumps({"d": Decimal("3.8")}))
@@ -56,9 +66,13 @@ def test_uuid_serialization(self):
5666
)
5767

5868
def test_serializes_numpy_bool(self):
69+
requires_numpy_and_pandas()
70+
5971
self.assertEqual('{"d":true}', JSONSerializer().dumps({"d": np.bool_(True)}))
6072

6173
def test_serializes_numpy_integers(self):
74+
requires_numpy_and_pandas()
75+
6276
ser = JSONSerializer()
6377
for np_type in (
6478
np.int_,
@@ -78,6 +92,8 @@ def test_serializes_numpy_integers(self):
7892
self.assertEqual(ser.dumps({"d": np_type(1)}), '{"d":1}')
7993

8094
def test_serializes_numpy_floats(self):
95+
requires_numpy_and_pandas()
96+
8197
ser = JSONSerializer()
8298
for np_type in (
8399
np.float_,
@@ -89,12 +105,16 @@ def test_serializes_numpy_floats(self):
89105
)
90106

91107
def test_serializes_numpy_datetime(self):
108+
requires_numpy_and_pandas()
109+
92110
self.assertEqual(
93111
'{"d":"2010-10-01T02:30:00"}',
94112
JSONSerializer().dumps({"d": np.datetime64("2010-10-01T02:30:00")}),
95113
)
96114

97115
def test_serializes_numpy_ndarray(self):
116+
requires_numpy_and_pandas()
117+
98118
self.assertEqual(
99119
'{"d":[0,0,0,0,0]}',
100120
JSONSerializer().dumps({"d": np.zeros((5,), dtype=np.uint8)}),
@@ -106,24 +126,32 @@ def test_serializes_numpy_ndarray(self):
106126
)
107127

108128
def test_serializes_numpy_nan_to_nan(self):
129+
requires_numpy_and_pandas()
130+
109131
self.assertEqual(
110132
'{"d":NaN}',
111133
JSONSerializer().dumps({"d": np.nan}),
112134
)
113135

114136
def test_serializes_pandas_timestamp(self):
137+
requires_numpy_and_pandas()
138+
115139
self.assertEqual(
116140
'{"d":"2010-10-01T02:30:00"}',
117141
JSONSerializer().dumps({"d": pd.Timestamp("2010-10-01T02:30:00")}),
118142
)
119143

120144
def test_serializes_pandas_series(self):
145+
requires_numpy_and_pandas()
146+
121147
self.assertEqual(
122148
'{"d":["a","b","c","d"]}',
123149
JSONSerializer().dumps({"d": pd.Series(["a", "b", "c", "d"])}),
124150
)
125151

126152
def test_serializes_pandas_na(self):
153+
requires_numpy_and_pandas()
154+
127155
if not hasattr(pd, "NA"): # pandas.NA added in v1
128156
raise SkipTest("pandas.NA required")
129157
self.assertEqual(
@@ -132,11 +160,15 @@ def test_serializes_pandas_na(self):
132160
)
133161

134162
def test_raises_serialization_error_pandas_nat(self):
163+
requires_numpy_and_pandas()
164+
135165
if not hasattr(pd, "NaT"):
136166
raise SkipTest("pandas.NaT required")
137167
self.assertRaises(SerializationError, JSONSerializer().dumps, {"d": pd.NaT})
138168

139169
def test_serializes_pandas_category(self):
170+
requires_numpy_and_pandas()
171+
140172
cat = pd.Categorical(["a", "c", "b", "a"], categories=["a", "b", "c"])
141173
self.assertEqual(
142174
'{"d":["a","c","b","a"]}',

0 commit comments

Comments
 (0)