Skip to content

Commit 58b83d8

Browse files
authored
Added Windows CI. (opensearch-project#569)
Signed-off-by: dblock <dblock@amazon.com>
1 parent 56606ed commit 58b83d8

File tree

7 files changed

+45
-21
lines changed

7 files changed

+45
-21
lines changed

.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- { os: 'ubuntu-latest', python-version: "3.10" }
1515
- { os: 'ubuntu-latest', python-version: "3.11" }
1616
- { os: 'macos-latest', python-version: "3.11" }
17+
- { os: 'windows-latest', python-version: "3.11" }
1718

1819
name: test (os=${{ matrix.entry.os }}, python=${{ matrix.entry.python-version }})
1920
continue-on-error: ${{ matrix.entry.experimental || false }}

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1515
- Added a utf-8 header to all .py files ([#557](https://github.com/opensearch-project/opensearch-py/pull/557))
1616
- Added `samples`, `benchmarks` and `docs` to `nox -rs format` ([#556](https://github.com/opensearch-project/opensearch-py/pull/556))
1717
- Added guide on the document lifecycle API(s) ([#559](https://github.com/opensearch-project/opensearch-py/pull/559))
18+
- Added Windows CI ([#569](https://github.com/opensearch-project/opensearch-py/pull/569))
1819
### Changed
1920
- Generate `tasks` client from API specs ([#508](https://github.com/opensearch-project/opensearch-py/pull/508))
2021
- Generate `ingest` client from API specs ([#513](https://github.com/opensearch-project/opensearch-py/pull/513))

opensearchpy/_async/http_aiohttp.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ def __init__(
183183
ssl_context.check_hostname = False
184184
ssl_context.verify_mode = ssl.CERT_NONE
185185

186-
ca_certs = self.default_ca_certs() if ca_certs is None else ca_certs
186+
if ca_certs is None:
187+
ca_certs = self.default_ca_certs()
188+
187189
if verify_certs:
188190
if not ca_certs:
189191
raise ImproperlyConfigured(

opensearchpy/connection/base.py

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ def __eq__(self, other: object) -> bool:
138138
raise TypeError("Unsupported equality check for %s and %s" % (self, other))
139139
return self.__hash__() == other.__hash__()
140140

141+
def __lt__(self, other: object) -> bool:
142+
if not isinstance(other, Connection):
143+
raise TypeError("Unsupported lt check for %s and %s" % (self, other))
144+
return self.__hash__() < other.__hash__()
145+
141146
def __hash__(self) -> int:
142147
return id(self)
143148

test_opensearchpy/test_async/test_connection.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import aiohttp
3838
import pytest
3939
from _pytest.mark.structures import MarkDecorator
40-
from mock import patch
40+
from mock import MagicMock, patch
4141
from multidict import CIMultiDict
4242
from pytest import raises
4343

@@ -254,26 +254,29 @@ async def test_warns_if_using_non_default_ssl_kwargs_with_ssl_context(self) -> N
254254
== str(w[0].message)
255255
)
256256

257-
@patch("ssl.SSLContext.load_verify_locations")
258-
async def test_uses_given_ca_certs(
259-
self, load_verify_locations: Any, tmp_path: Any
260-
) -> None:
257+
@patch("ssl.SSLContext", return_value=MagicMock())
258+
async def test_uses_given_ca_certs(self, ssl_context: Any, tmp_path: Any) -> None:
261259
path = tmp_path / "ca_certs.pem"
262260
path.touch()
261+
ssl_context.return_value.load_verify_locations.return_value = None
263262
AIOHttpConnection(use_ssl=True, ca_certs=str(path))
264-
load_verify_locations.assert_called_once_with(cafile=str(path))
263+
ssl_context.return_value.load_verify_locations.assert_called_once_with(
264+
cafile=str(path)
265+
)
265266

266-
@patch("ssl.SSLContext.load_verify_locations")
267-
async def test_uses_default_ca_certs(self, load_verify_locations: Any) -> None:
267+
@patch("ssl.SSLContext", return_value=MagicMock())
268+
async def test_uses_default_ca_certs(self, ssl_context: Any) -> None:
269+
ssl_context.return_value.load_verify_locations.return_value = None
268270
AIOHttpConnection(use_ssl=True)
269-
load_verify_locations.assert_called_once_with(
271+
ssl_context.return_value.load_verify_locations.assert_called_once_with(
270272
cafile=Connection.default_ca_certs()
271273
)
272274

273-
@patch("ssl.SSLContext.load_verify_locations")
274-
async def test_uses_no_ca_certs(self, load_verify_locations: Any) -> None:
275+
@patch("ssl.SSLContext", return_value=MagicMock())
276+
async def test_uses_no_ca_certs(self, ssl_context: Any) -> None:
277+
ssl_context.return_value.load_verify_locations.return_value = None
275278
AIOHttpConnection(use_ssl=True, verify_certs=False)
276-
load_verify_locations.assert_not_called()
279+
ssl_context.return_value.load_verify_locations.assert_not_called()
277280

278281
async def test_trust_env(self) -> None:
279282
con: Any = AIOHttpConnection(trust_env=True)

test_opensearchpy/test_async/test_transport.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ async def test_add_connection(self) -> None:
272272

273273
async def test_request_will_fail_after_X_retries(self) -> None:
274274
t: Any = AsyncTransport(
275-
[{"exception": ConnectionError("abandon ship")}],
275+
[{"exception": ConnectionError(None, "abandon ship", Exception())}],
276276
connection_class=DummyConnection,
277277
)
278278

@@ -287,7 +287,7 @@ async def test_request_will_fail_after_X_retries(self) -> None:
287287

288288
async def test_failed_connection_will_be_marked_as_dead(self) -> None:
289289
t: Any = AsyncTransport(
290-
[{"exception": ConnectionError("abandon ship")}] * 2,
290+
[{"exception": ConnectionError(None, "abandon ship", Exception())}] * 2,
291291
connection_class=DummyConnection,
292292
)
293293

@@ -381,7 +381,10 @@ async def test_sniff_reuses_connection_instances_if_possible(self) -> None:
381381

382382
async def test_sniff_on_fail_triggers_sniffing_on_fail(self) -> None:
383383
t: Any = AsyncTransport(
384-
[{"exception": ConnectionError("abandon ship")}, {"data": CLUSTER_NODES}],
384+
[
385+
{"exception": ConnectionError(None, "abandon ship", Exception())},
386+
{"data": CLUSTER_NODES},
387+
],
385388
connection_class=DummyConnection,
386389
sniff_on_connection_fail=True,
387390
max_retries=0,
@@ -407,7 +410,10 @@ async def test_sniff_on_fail_failing_does_not_prevent_retires(
407410
) -> None:
408411
sniff_hosts.side_effect = [TransportError("sniff failed")]
409412
t: Any = AsyncTransport(
410-
[{"exception": ConnectionError("abandon ship")}, {"data": CLUSTER_NODES}],
413+
[
414+
{"exception": ConnectionError(None, "abandon ship", Exception())},
415+
{"data": CLUSTER_NODES},
416+
],
411417
connection_class=DummyConnection,
412418
sniff_on_connection_fail=True,
413419
max_retries=3,

test_opensearchpy/test_transport.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_add_connection(self) -> None:
266266

267267
def test_request_will_fail_after_X_retries(self) -> None:
268268
t: Any = Transport(
269-
[{"exception": ConnectionError("abandon ship")}],
269+
[{"exception": ConnectionError(None, "abandon ship", Exception())}],
270270
connection_class=DummyConnection,
271271
)
272272

@@ -275,7 +275,7 @@ def test_request_will_fail_after_X_retries(self) -> None:
275275

276276
def test_failed_connection_will_be_marked_as_dead(self) -> None:
277277
t: Any = Transport(
278-
[{"exception": ConnectionError("abandon ship")}] * 2,
278+
[{"exception": ConnectionError(None, "abandon ship", Exception())}] * 2,
279279
connection_class=DummyConnection,
280280
)
281281

@@ -349,7 +349,10 @@ def test_sniff_reuses_connection_instances_if_possible(self) -> None:
349349

350350
def test_sniff_on_fail_triggers_sniffing_on_fail(self) -> None:
351351
t: Any = Transport(
352-
[{"exception": ConnectionError("abandon ship")}, {"data": CLUSTER_NODES}],
352+
[
353+
{"exception": ConnectionError(None, "abandon ship", Exception())},
354+
{"data": CLUSTER_NODES},
355+
],
353356
connection_class=DummyConnection,
354357
sniff_on_connection_fail=True,
355358
max_retries=0,
@@ -366,7 +369,10 @@ def test_sniff_on_fail_failing_does_not_prevent_retires(
366369
) -> None:
367370
sniff_hosts.side_effect = [TransportError("sniff failed")]
368371
t: Any = Transport(
369-
[{"exception": ConnectionError("abandon ship")}, {"data": CLUSTER_NODES}],
372+
[
373+
{"exception": ConnectionError(None, "abandon ship", Exception())},
374+
{"data": CLUSTER_NODES},
375+
],
370376
connection_class=DummyConnection,
371377
sniff_on_connection_fail=True,
372378
max_retries=3,

0 commit comments

Comments
 (0)