La question est comme dans le titre, comment puis-je simuler select.select par exemple pour tester ma fonction d'exécution de thread. la fonction de test échoue avecComment faire pour simuler un module intégré dans un thread
ready = select.select([self.sock], [], [], 5)
TypeError: fileno() returned a non-integer
et l'impression de type donne
type « builtin_function_or_method »clairement select.select ne se moque pas dans le périmètre du fil alors que dans le test, il est .. . (affirmer isinstance)
import select
import threading
RECEIVE_BYTES = 256
class Bar(threading.Thread):
def __init__(self, sock):
threading.Thread.__init__(self)
self.sock = sock
def run(self):
print type(select.select)
ready = select.select([self.sock],[],[],5)
if ready[0]:
print self.sock.recv(RECEIVE_BYTES)
l'essai est la suivante dans un autre module
def test_run(self):
with patch("select.select"):
select.select.return_value = [True]
mock_sock = MagicMock()
foo = Bar(mock_sock)
assert isinstance(select.select, MagicMock)
foo.start()
essais
sont exécutés par le nez
génial thx je vais régler mes problèmes de syntaxe ... – studioj