enable/fix test_etcd.py

This commit is contained in:
FrankK-1234 2024-05-17 12:59:02 +02:00 committed by Asif Saif Uddin
parent e8175a1668
commit aec8faf034
2 changed files with 10 additions and 6 deletions

View File

@ -15,3 +15,4 @@ urllib3>=1.26.16; sys_platform != 'win32'
-r extras/brotli.txt -r extras/brotli.txt
-r extras/zstd.txt -r extras/zstd.txt
-r extras/sqlalchemy.txt -r extras/sqlalchemy.txt
-r extras/etcd.txt

View File

@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
from array import array
from queue import Empty from queue import Empty
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
@ -14,9 +15,11 @@ class test_Etcd:
def setup_method(self): def setup_method(self):
self.connection = Mock() self.connection = Mock()
self.connection._used_channel_ids = array('H')
self.connection.channel_max = 65535
self.connection.client.transport_options = {} self.connection.client.transport_options = {}
self.connection.client.port = 2739 self.connection.client.port = 2739
self.client = self.patch('etcd.Client').return_value self.client = self.patching('etcd.Client').return_value
self.channel = Channel(connection=self.connection) self.channel = Channel(connection=self.connection)
def test_driver_version(self): def test_driver_version(self):
@ -42,26 +45,26 @@ class test_Etcd:
queue = 'mynewqueue' queue = 'mynewqueue'
with patch('etcd.Lock'): with patch('etcd.Lock'):
self.client.write.return_value = self.patch('etcd.EtcdResult') self.client.write.return_value = self.patching('etcd.EtcdResult')
assert self.channel._new_queue(queue) assert self.channel._new_queue(queue)
self.client.delete.return_value = self.patch('etcd.EtcdResult') self.client.delete.return_value = self.patching('etcd.EtcdResult')
self.channel._delete(queue) self.channel._delete(queue)
def test_size(self): def test_size(self):
with patch('etcd.Lock'): with patch('etcd.Lock'):
self.client.read.return_value = self.patch( self.client.read.return_value = self.patching(
'etcd.EtcdResult', _children=[{}, {}]) 'etcd.EtcdResult', _children=[{}, {}])
assert self.channel._size('q') == 2 assert self.channel._size('q') == 2
def test_get(self): def test_get(self):
with patch('etcd.Lock'): with patch('etcd.Lock'):
self.client.read.return_value = self.patch( self.client.read.return_value = self.patching(
'etcd.EtcdResult', 'etcd.EtcdResult',
_children=[{'key': 'myqueue', 'modifyIndex': 1, 'value': '1'}]) _children=[{'key': 'myqueue', 'modifyIndex': 1, 'value': '1'}])
assert self.channel._get('myqueue') is not None assert self.channel._get('myqueue') is not None
def test_put(self): def test_put(self):
with patch('etcd.Lock'): with patch('etcd.Lock'):
self.client.write.return_value = self.patch('etcd.EtcdResult') self.client.write.return_value = self.patching('etcd.EtcdResult')
assert self.channel._put('myqueue', 'mydata') is None assert self.channel._put('myqueue', 'mydata') is None