This commit is contained in:
parent
75ac0b2e07
commit
477d315890
3
Makefile
3
Makefile
@ -24,8 +24,10 @@ help::
|
|||||||
|
|
||||||
test::
|
test::
|
||||||
test_direct::
|
test_direct::
|
||||||
|
cp -p ${HOME}/.config/tox/DHTnodes.json /tmp/toxygen_nodes.json
|
||||||
PYTHONPATH=$${PWD}/src \
|
PYTHONPATH=$${PWD}/src \
|
||||||
sudo -u bin $(PYTHON) src/tox_wrapper/tests/tests_wrapper.py \
|
sudo -u bin $(PYTHON) src/tox_wrapper/tests/tests_wrapper.py \
|
||||||
|
--socket_timeout=10.0 \
|
||||||
--test_timeout=${iTEST_TIMEOUT} \
|
--test_timeout=${iTEST_TIMEOUT} \
|
||||||
--nodes_json=/tmp/toxygen_nodes.json \
|
--nodes_json=/tmp/toxygen_nodes.json \
|
||||||
--udp_enabled=True \
|
--udp_enabled=True \
|
||||||
@ -34,6 +36,7 @@ test_direct::
|
|||||||
test_proxy::
|
test_proxy::
|
||||||
PYTHONPATH=$${PWD}/src \
|
PYTHONPATH=$${PWD}/src \
|
||||||
$(PYTHON) src/tox_wrapper/tests/tests_wrapper.py \
|
$(PYTHON) src/tox_wrapper/tests/tests_wrapper.py \
|
||||||
|
--socket_timeout=15.0 \
|
||||||
--test_timeout=${iTEST_TIMEOUT} \
|
--test_timeout=${iTEST_TIMEOUT} \
|
||||||
--proxy_host=127.0.0.1 \
|
--proxy_host=127.0.0.1 \
|
||||||
--proxy_port=9050 \
|
--proxy_port=9050 \
|
||||||
|
@ -372,7 +372,7 @@ def oMainArgparser(_=None, iMode=0):
|
|||||||
# choices=['True', 'False'],
|
# choices=['True', 'False'],
|
||||||
# help='En/Disable saving history')
|
# help='En/Disable saving history')
|
||||||
parser.add_argument('--socket_timeout', type=float, default=fSOCKET_TIMEOUT,
|
parser.add_argument('--socket_timeout', type=float, default=fSOCKET_TIMEOUT,
|
||||||
help='Socket timeout set during bootstrap')
|
help='Socket timeout set during bootstrap in sec.')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def get_video_indexes() -> list:
|
def get_video_indexes() -> list:
|
||||||
@ -830,6 +830,7 @@ def sDNSLookup(host:str) -> str:
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
def bootstrap_udp(lelts:list, lToxes:list[int], oArgs=None, fsocket_timeout:float = fSOCKET_TIMEOUT) -> None:
|
def bootstrap_udp(lelts:list, lToxes:list[int], oArgs=None, fsocket_timeout:float = fSOCKET_TIMEOUT) -> None:
|
||||||
|
global lDEAD_BS
|
||||||
lelts = lDNSClean(lelts)
|
lelts = lDNSClean(lelts)
|
||||||
socket.setdefaulttimeout(fsocket_timeout)
|
socket.setdefaulttimeout(fsocket_timeout)
|
||||||
for oTox in lToxes:
|
for oTox in lToxes:
|
||||||
@ -848,6 +849,7 @@ def bootstrap_udp(lelts:list, lToxes:list[int], oArgs=None, fsocket_timeout:floa
|
|||||||
ip = sDNSLookup(host)
|
ip = sDNSLookup(host)
|
||||||
if not ip:
|
if not ip:
|
||||||
LOG.warn(f'bootstrap_udp to host={host} port={port} did not resolve ip={ip}')
|
LOG.warn(f'bootstrap_udp to host={host} port={port} did not resolve ip={ip}')
|
||||||
|
lDEAD_BS.append(host)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if type(port) == str:
|
if type(port) == str:
|
||||||
@ -874,6 +876,7 @@ def bootstrap_udp(lelts:list, lToxes:list[int], oArgs=None, fsocket_timeout:floa
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def bootstrap_tcp(lelts:list, lToxes:list, oArgs=None, fsocket_timeout:float = fSOCKET_TIMEOUT) -> None:
|
def bootstrap_tcp(lelts:list, lToxes:list, oArgs=None, fsocket_timeout:float = fSOCKET_TIMEOUT) -> None:
|
||||||
|
global lDEAD_BS
|
||||||
socket.setdefaulttimeout(fsocket_timeout)
|
socket.setdefaulttimeout(fsocket_timeout)
|
||||||
lelts = lDNSClean(lelts)
|
lelts = lDNSClean(lelts)
|
||||||
for oTox in lToxes:
|
for oTox in lToxes:
|
||||||
@ -886,8 +889,9 @@ def bootstrap_tcp(lelts:list, lToxes:list, oArgs=None, fsocket_timeout:float = f
|
|||||||
ip = sDNSLookup(host)
|
ip = sDNSLookup(host)
|
||||||
if not ip:
|
if not ip:
|
||||||
LOG.warn(f'bootstrap_tcp to {host} did not resolve ip={ip}')
|
LOG.warn(f'bootstrap_tcp to {host} did not resolve ip={ip}')
|
||||||
# continue
|
lDEAD_BS.append(host)
|
||||||
ip = host
|
continue
|
||||||
|
#? ip = host
|
||||||
if host.endswith('.onion') and stem:
|
if host.endswith('.onion') and stem:
|
||||||
l = lIntroductionPoints(host)
|
l = lIntroductionPoints(host)
|
||||||
if not l:
|
if not l:
|
||||||
|
@ -161,22 +161,24 @@ oAPP = App()
|
|||||||
|
|
||||||
class AliceTox(Tox):
|
class AliceTox(Tox):
|
||||||
|
|
||||||
def __init__(self, opts, app=None):
|
def __init__(self, opts, args, app=None):
|
||||||
|
|
||||||
super(AliceTox, self).__init__(opts, app=app)
|
super(AliceTox, self).__init__(opts, app=app)
|
||||||
self._address = self.self_get_address()
|
self._address = self.self_get_address()
|
||||||
self.name = 'alice'
|
self.name = 'alice'
|
||||||
self._opts = opts
|
self._opts = opts
|
||||||
self._app = app
|
self._app = app
|
||||||
|
self._args = args
|
||||||
|
|
||||||
class BobTox(Tox):
|
class BobTox(Tox):
|
||||||
|
|
||||||
def __init__(self, opts, app=None):
|
def __init__(self, opts, args, app=None):
|
||||||
super(BobTox, self).__init__(opts, app=app)
|
super(BobTox, self).__init__(opts, app=app)
|
||||||
self._address = self.self_get_address()
|
self._address = self.self_get_address()
|
||||||
self.name = 'bob'
|
self.name = 'bob'
|
||||||
self._opts = opts
|
self._opts = opts
|
||||||
self._app = app
|
self._app = app
|
||||||
|
self._args = args
|
||||||
|
|
||||||
class BaseThread(threading.Thread):
|
class BaseThread(threading.Thread):
|
||||||
|
|
||||||
@ -236,6 +238,7 @@ def prepare(self):
|
|||||||
LOG_WARN(f"bobs_on_self_connection_status DISAGREE {status}")
|
LOG_WARN(f"bobs_on_self_connection_status DISAGREE {status}")
|
||||||
|
|
||||||
def alices_on_self_connection_status(iTox, connection_state: int, *args) -> None:
|
def alices_on_self_connection_status(iTox, connection_state: int, *args) -> None:
|
||||||
|
global oTOX_OARGS
|
||||||
#FixMe connection_num
|
#FixMe connection_num
|
||||||
status = connection_state
|
status = connection_state
|
||||||
self.alice.dht_connected = status
|
self.alice.dht_connected = status
|
||||||
@ -256,8 +259,7 @@ def prepare(self):
|
|||||||
global bUSE_NOREQUEST
|
global bUSE_NOREQUEST
|
||||||
bUSE_NOREQUEST = oTOX_OARGS.norequest == 'True'
|
bUSE_NOREQUEST = oTOX_OARGS.norequest == 'True'
|
||||||
|
|
||||||
alice = AliceTox(opts, app=oAPP)
|
alice = AliceTox(opts, oTOX_OARGS, app=oAPP)
|
||||||
alice.oArgs = opts
|
|
||||||
alice.dht_connected = -1
|
alice.dht_connected = -1
|
||||||
alice.mycon_status = False
|
alice.mycon_status = False
|
||||||
alice.mycon_time = 1
|
alice.mycon_time = 1
|
||||||
@ -270,8 +272,7 @@ def prepare(self):
|
|||||||
else:
|
else:
|
||||||
LOG.debug(f"toxcore trace_enabled=False")
|
LOG.debug(f"toxcore trace_enabled=False")
|
||||||
|
|
||||||
bob = BobTox(opts, app=oAPP)
|
bob = BobTox(opts, oTOX_OARGS, app=oAPP)
|
||||||
bob.oArgs = opts
|
|
||||||
bob.dht_connected = -1
|
bob.dht_connected = -1
|
||||||
bob.mycon_status = False
|
bob.mycon_status = False
|
||||||
bob.mycon_time = 1
|
bob.mycon_time = 1
|
||||||
@ -287,7 +288,6 @@ class ToxSuite(unittest.TestCase):
|
|||||||
def setUpClass(cls) -> None:
|
def setUpClass(cls) -> None:
|
||||||
global oTOX_OARGS
|
global oTOX_OARGS
|
||||||
assert oTOX_OPTIONS
|
assert oTOX_OPTIONS
|
||||||
assert oTOX_OARGS
|
|
||||||
|
|
||||||
cls.lUdp = ts.generate_nodes(
|
cls.lUdp = ts.generate_nodes(
|
||||||
oArgs=oTOX_OARGS,
|
oArgs=oTOX_OARGS,
|
||||||
@ -413,6 +413,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
sleep(interval / 1000.0)
|
sleep(interval / 1000.0)
|
||||||
|
|
||||||
def call_bootstrap(self, num: Union[int, None] = None, lToxes:Union[list[int], None] =None, i:int =0, fsocket_timeout:float = fSOCKET_TIMEOUT) -> None:
|
def call_bootstrap(self, num: Union[int, None] = None, lToxes:Union[list[int], None] =None, i:int =0, fsocket_timeout:float = fSOCKET_TIMEOUT) -> None:
|
||||||
|
global oTOX_OARGS
|
||||||
if num == None: num=ts.iNODES
|
if num == None: num=ts.iNODES
|
||||||
if lToxes is None:
|
if lToxes is None:
|
||||||
lToxes = [self.alice, self.bob]
|
lToxes = [self.alice, self.bob]
|
||||||
@ -472,15 +473,15 @@ class ToxSuite(unittest.TestCase):
|
|||||||
+f" last={int(otox.mycon_time)}" )
|
+f" last={int(otox.mycon_time)}" )
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def loop_until_connected(self, num: Union[int, None] = None, fsocket_timeout:float = fSOCKET_TIMEOUT) -> bool:
|
def loop_until_connected(self, otox=None, num: Union[int, None] = None, fsocket_timeout:float = fSOCKET_TIMEOUT) -> bool:
|
||||||
"""
|
"""
|
||||||
t:on_self_connection_status
|
t:on_self_connection_status
|
||||||
t:self_get_connection_status
|
t:self_get_connection_status
|
||||||
"""
|
"""
|
||||||
global THRESHOLD
|
|
||||||
i = 0
|
i = 0
|
||||||
bRet = None
|
bRet = None
|
||||||
while i <= THRESHOLD :
|
if otox is None: otox = self.bob
|
||||||
|
while i <= otox._args.test_timeout :
|
||||||
if (self.alice.mycon_status and self.bob.mycon_status):
|
if (self.alice.mycon_status and self.bob.mycon_status):
|
||||||
bRet = True
|
bRet = True
|
||||||
break
|
break
|
||||||
@ -521,7 +522,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
+f" last={int(self.bob.mycon_time)}" )
|
+f" last={int(self.bob.mycon_time)}" )
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
THRESHOLD += 5
|
otox._args.test_timeout += 5
|
||||||
LOG.warning(f"loop_until_connected returning False {i}" \
|
LOG.warning(f"loop_until_connected returning False {i}" \
|
||||||
+f" BOB={self.bob.self_get_connection_status()}" \
|
+f" BOB={self.bob.self_get_connection_status()}" \
|
||||||
+f" ALICE={self.alice.self_get_connection_status()}" \
|
+f" ALICE={self.alice.self_get_connection_status()}" \
|
||||||
@ -529,9 +530,9 @@ class ToxSuite(unittest.TestCase):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def wait_objs_attr(self, objs: list, attr: str, fsocket_timeout:float = fSOCKET_TIMEOUT) -> bool:
|
def wait_objs_attr(self, objs: list, attr: str, fsocket_timeout:float = fSOCKET_TIMEOUT) -> bool:
|
||||||
global THRESHOLD
|
|
||||||
i = 0
|
i = 0
|
||||||
while i <= THRESHOLD:
|
otox = objs[0]
|
||||||
|
while i <= otox._args.test_timeout:
|
||||||
if i % 5 == 0:
|
if i % 5 == 0:
|
||||||
num = None
|
num = None
|
||||||
j = 0
|
j = 0
|
||||||
@ -543,15 +544,16 @@ class ToxSuite(unittest.TestCase):
|
|||||||
self.loop(100)
|
self.loop(100)
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
THRESHOLD += 1
|
otox._args.test_timeout += 1
|
||||||
LOG.warn(f"wait_objs_attr for {attr} i >= {THRESHOLD}")
|
LOG.warn(f"wait_objs_attr for {attr} i >= {otox._args.test_timeout}")
|
||||||
|
|
||||||
return all([getattr(obj, attr) is not None for obj in objs])
|
return all([getattr(obj, attr) is not None for obj in objs])
|
||||||
|
|
||||||
def wait_otox_attrs(self, obj, attrs: list[str], fsocket_timeout:float = fSOCKET_TIMEOUT) -> bool:
|
def wait_otox_attrs(self, obj, attrs: list[str], fsocket_timeout:float = fSOCKET_TIMEOUT) -> bool:
|
||||||
assert all(attrs), f"wait_otox_attrs {attrs}"
|
assert all(attrs), f"wait_otox_attrs {attrs}"
|
||||||
i = 0
|
i = 0
|
||||||
while i <= THRESHOLD:
|
otox = obj
|
||||||
|
while i <= otox._args.test_timeout:
|
||||||
if i % 5 == 0:
|
if i % 5 == 0:
|
||||||
num = None
|
num = None
|
||||||
j = 0
|
j = 0
|
||||||
@ -567,14 +569,14 @@ class ToxSuite(unittest.TestCase):
|
|||||||
self.loop(100)
|
self.loop(100)
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
LOG.warning(f"wait_otox_attrs i >= {THRESHOLD} attrs={attrs} results={[getattr(obj, attr) for attr in attrs]}")
|
LOG.warning(f"wait_otox_attrs i >= {otox._args.test_timeout} attrs={attrs} results={[getattr(obj, attr) for attr in attrs]}")
|
||||||
|
|
||||||
return all([getattr(obj, attr) for attr in attrs])
|
return all([getattr(obj, attr) for attr in attrs])
|
||||||
|
|
||||||
def wait_ensure_exec(self, method, args:list, fsocket_timeout:float = fSOCKET_TIMEOUT) -> bool:
|
def wait_ensure_exec(self, method, args:list, fsocket_timeout:float = fSOCKET_TIMEOUT) -> bool:
|
||||||
i = 0
|
i = 0
|
||||||
oRet = None
|
oRet = None
|
||||||
while i <= THRESHOLD:
|
while i <= self.bob._args.test_timeout:
|
||||||
if i % 5 == 0:
|
if i % 5 == 0:
|
||||||
j = i//5
|
j = i//5
|
||||||
self.call_bootstrap(num=None, lToxes=None, i=j, fsocket_timeout=fsocket_timeout)
|
self.call_bootstrap(num=None, lToxes=None, i=j, fsocket_timeout=fsocket_timeout)
|
||||||
@ -597,7 +599,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
sleep(3)
|
sleep(3)
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
LOG.error(f"wait_ensure_exec i >= {1*THRESHOLD}")
|
LOG.error(f"wait_ensure_exec i >= {1*self.bob._args.test_timeout}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return oRet
|
return oRet
|
||||||
@ -896,7 +898,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
LOG.info(f"group_is_connected SUCCESS connected iGrp={iGrp} n={otox.group_get_number_groups()}")
|
LOG.info(f"group_is_connected SUCCESS connected iGrp={iGrp} n={otox.group_get_number_groups()}")
|
||||||
try:
|
try:
|
||||||
bRet = self.group_until_connected(otox, iGrp, iMax=2*THRESHOLD)
|
bRet = self.group_until_connected(otox, iGrp, iMax=2*otox._args.test_timeout)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error(f"group_until_connected EXCEPTION {e}")
|
LOG.error(f"group_until_connected EXCEPTION {e}")
|
||||||
return -1
|
return -1
|
||||||
@ -964,9 +966,9 @@ class ToxSuite(unittest.TestCase):
|
|||||||
iRet = otox.friend_get_connection_status(fid)
|
iRet = otox.friend_get_connection_status(fid)
|
||||||
if iRet == TOX_CONNECTION['NONE']:
|
if iRet == TOX_CONNECTION['NONE']:
|
||||||
# LOG.debug(f"wait_friend_get_connection_status NOT CONNECTED i={i} {iRet}")
|
# LOG.debug(f"wait_friend_get_connection_status NOT CONNECTED i={i} {iRet}")
|
||||||
self.loop_until_connected()
|
self.loop_until_connected(otox)
|
||||||
else:
|
else:
|
||||||
LOG.info("wait_friend_get_connection_status {iRet}")
|
LOG.info(f"wait_friend_get_connection_status {iRet}")
|
||||||
return True
|
return True
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
@ -1103,6 +1105,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipIf(os.geteuid() != 0, 'must be root')
|
@unittest.skipIf(os.geteuid() != 0, 'must be root')
|
||||||
def test_bootstrap_iNmapInfo(self) -> None: # works
|
def test_bootstrap_iNmapInfo(self) -> None: # works
|
||||||
|
global oTOX_OARGS
|
||||||
# if os.environ['USER'] != 'root':
|
# if os.environ['USER'] != 'root':
|
||||||
# return
|
# return
|
||||||
iStatus = self.bob.self_get_connection_status()
|
iStatus = self.bob.self_get_connection_status()
|
||||||
@ -1405,7 +1408,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
if not self.get_connection_status():
|
if not self.get_connection_status():
|
||||||
LOG.warning(f"test_groups_join NOT CONNECTED")
|
LOG.warning(f"test_groups_join NOT CONNECTED")
|
||||||
self.loop_until_connected()
|
self.loop_until_connected(self.bob)
|
||||||
|
|
||||||
iGrp = self.otox_test_groups_join(self.bob)
|
iGrp = self.otox_test_groups_join(self.bob)
|
||||||
LOG.info(f"test_groups_join iGrp={iGrp}")
|
LOG.info(f"test_groups_join iGrp={iGrp}")
|
||||||
@ -1587,7 +1590,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
assert self.bob_add_alice_as_friend()
|
assert self.bob_add_alice_as_friend()
|
||||||
if not self.get_connection_status():
|
if not self.get_connection_status():
|
||||||
LOG.warning(f"test_user_status NOT CONNECTED self.get_connection_status")
|
LOG.warning(f"test_user_status NOT CONNECTED self.get_connection_status")
|
||||||
self.loop_until_connected()
|
self.loop_until_connected(self.bob)
|
||||||
|
|
||||||
self.bob.callback_friend_status(bobs_on_friend_set_status)
|
self.bob.callback_friend_status(bobs_on_friend_set_status)
|
||||||
self.warn_if_no_cb(self.bob, sSlot)
|
self.warn_if_no_cb(self.bob, sSlot)
|
||||||
@ -1619,6 +1622,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
t:friend_get_kill_remake
|
t:friend_get_kill_remake
|
||||||
t:on_friend_connection_status
|
t:on_friend_connection_status
|
||||||
"""
|
"""
|
||||||
|
global oTOX_OARGS
|
||||||
sSlot = 'friend_connection_status'
|
sSlot = 'friend_connection_status'
|
||||||
setattr(self.bob, sSlot, None)
|
setattr(self.bob, sSlot, None)
|
||||||
def bobs_on_friend_connection_status(iTox, friend_id, iStatus, *largs):
|
def bobs_on_friend_connection_status(iTox, friend_id, iStatus, *largs):
|
||||||
@ -1658,6 +1662,57 @@ class ToxSuite(unittest.TestCase):
|
|||||||
if hasattr(self, 'baid') and self.baid >= 0:
|
if hasattr(self, 'baid') and self.baid >= 0:
|
||||||
self.bob.friend_delete(self.baid)
|
self.bob.friend_delete(self.baid)
|
||||||
|
|
||||||
|
def test_alice_typing_status(self) -> None: # works
|
||||||
|
"""
|
||||||
|
t:on_friend_read_receipt
|
||||||
|
t:on_friend_typing
|
||||||
|
t:self_set_typing
|
||||||
|
t:friend_get_typing
|
||||||
|
t:friend_get_last_online
|
||||||
|
"""
|
||||||
|
|
||||||
|
sSlot = 'friend_typing'
|
||||||
|
LOG.info("test_typing_status bob adding alice")
|
||||||
|
#: Test typing status
|
||||||
|
def bob_on_friend_typing(iTox, fid:int, is_typing, *largs) -> None:
|
||||||
|
LOG_INFO(f"BOB_ON_friend_typing is_typing={is_typing} fid={fid}")
|
||||||
|
try:
|
||||||
|
assert fid == self.baid
|
||||||
|
if is_typing is True:
|
||||||
|
assert self.bob.friend_get_typing(fid) is True
|
||||||
|
except Exception as e:
|
||||||
|
LOG_ERROR(f"BOB_ON_friend_typing {e}")
|
||||||
|
setattr(self.bob, sSlot, True)
|
||||||
|
|
||||||
|
setattr(self.bob, sSlot, None)
|
||||||
|
try:
|
||||||
|
if bUSE_NOREQUEST:
|
||||||
|
assert self.both_add_as_friend_norequest()
|
||||||
|
else:
|
||||||
|
assert self.both_add_as_friend()
|
||||||
|
|
||||||
|
if not self.get_connection_status():
|
||||||
|
LOG.warning(f"test_friend_typing NOT CONNECTED")
|
||||||
|
self.loop_until_connected(self.bob)
|
||||||
|
|
||||||
|
self.bob.callback_friend_typing(bob_on_friend_typing)
|
||||||
|
self.warn_if_no_cb(self.bob, sSlot)
|
||||||
|
self.alice.self_set_typing(self.abid, False)
|
||||||
|
if not self.wait_otox_attrs(self.bob, [sSlot]):
|
||||||
|
LOG_WARN(f"bobs_on_friend_typing NO {sSlot}")
|
||||||
|
except AssertionError as e:
|
||||||
|
LOG.error(f"Failed test {e}")
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
LOG.error(f"test_alice_typing_status error={e}")
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
self.bob.callback_friend_typing(None)
|
||||||
|
if hasattr(self, 'baid') and self.baid >= 0:
|
||||||
|
self.bob.friend_delete(self.baid)
|
||||||
|
if hasattr(self, 'abid') and self.abid >= 0:
|
||||||
|
self.alice.friend_delete(self.abid)
|
||||||
|
|
||||||
@expectedFail('fails') # new name is empty
|
@expectedFail('fails') # new name is empty
|
||||||
def test_friend_name(self) -> None: # works!
|
def test_friend_name(self) -> None: # works!
|
||||||
"""
|
"""
|
||||||
@ -1714,9 +1769,8 @@ class ToxSuite(unittest.TestCase):
|
|||||||
self.bob.callback_friend_name(None)
|
self.bob.callback_friend_name(None)
|
||||||
self.warn_if_cb(self.bob, sSlot)
|
self.warn_if_cb(self.bob, sSlot)
|
||||||
|
|
||||||
|
|
||||||
@expectedFail('fails') # This client is currently not connected to the friend.
|
@expectedFail('fails') # This client is currently not connected to the friend.
|
||||||
def test_friend_message(self) -> None: # fails
|
def test_friend_message(self) -> None: # fails intermittently
|
||||||
"""
|
"""
|
||||||
t:on_friend_action
|
t:on_friend_action
|
||||||
t:on_friend_message
|
t:on_friend_message
|
||||||
@ -1813,13 +1867,17 @@ class ToxSuite(unittest.TestCase):
|
|||||||
sSlot = 'friend_read_receipt'
|
sSlot = 'friend_read_receipt'
|
||||||
try:
|
try:
|
||||||
# should be the receivers id
|
# should be the receivers id
|
||||||
assert fid == bob.baid or fid == alice.abid
|
if hasattr(bob, 'baid'):
|
||||||
|
assert fid == bob.baid
|
||||||
|
setattr(self.bob, sSlot, True)
|
||||||
|
elif hasattr(alice, 'abid'):
|
||||||
|
assert fid == alice.abid
|
||||||
|
setattr(self.alice, sSlot, True)
|
||||||
assert msg_id >= 0
|
assert msg_id >= 0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG_ERROR(f"their_on_read_reciept {sSlot} {e}")
|
LOG_ERROR(f"their_on_read_reciept {sSlot} {e}")
|
||||||
else:
|
else:
|
||||||
LOG_INFO(f"their_on_read_reciept {sSlot} fid={fid}")
|
LOG_INFO(f"their_on_read_reciept {sSlot} fid={fid}")
|
||||||
setattr(self.alice, sSlot, True)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if bUSE_NOREQUEST:
|
if bUSE_NOREQUEST:
|
||||||
@ -1865,57 +1923,6 @@ class ToxSuite(unittest.TestCase):
|
|||||||
if hasattr(self, 'abid') and self.abid >= 0:
|
if hasattr(self, 'abid') and self.abid >= 0:
|
||||||
self.alice.friend_delete(self.abid)
|
self.alice.friend_delete(self.abid)
|
||||||
|
|
||||||
def test_alice_typing_status(self) -> None: # works
|
|
||||||
"""
|
|
||||||
t:on_friend_read_receipt
|
|
||||||
t:on_friend_typing
|
|
||||||
t:self_set_typing
|
|
||||||
t:friend_get_typing
|
|
||||||
t:friend_get_last_online
|
|
||||||
"""
|
|
||||||
|
|
||||||
sSlot = 'friend_typing'
|
|
||||||
LOG.info("test_typing_status bob adding alice")
|
|
||||||
#: Test typing status
|
|
||||||
def bob_on_friend_typing(iTox, fid:int, is_typing, *largs) -> None:
|
|
||||||
LOG_INFO(f"BOB_ON_friend_typing is_typing={is_typing} fid={fid}")
|
|
||||||
try:
|
|
||||||
assert fid == self.baid
|
|
||||||
if is_typing is True:
|
|
||||||
assert self.bob.friend_get_typing(fid) is True
|
|
||||||
except Exception as e:
|
|
||||||
LOG_ERROR(f"BOB_ON_friend_typing {e}")
|
|
||||||
setattr(self.bob, sSlot, True)
|
|
||||||
|
|
||||||
setattr(self.bob, sSlot, None)
|
|
||||||
try:
|
|
||||||
if bUSE_NOREQUEST:
|
|
||||||
assert self.both_add_as_friend_norequest()
|
|
||||||
else:
|
|
||||||
assert self.both_add_as_friend()
|
|
||||||
|
|
||||||
if not self.get_connection_status():
|
|
||||||
LOG.warning(f"test_friend_typing NOT CONNECTED")
|
|
||||||
self.loop_until_connected()
|
|
||||||
|
|
||||||
self.bob.callback_friend_typing(bob_on_friend_typing)
|
|
||||||
self.warn_if_no_cb(self.bob, sSlot)
|
|
||||||
self.alice.self_set_typing(self.abid, False)
|
|
||||||
if not self.wait_otox_attrs(self.bob, [sSlot]):
|
|
||||||
LOG_WARN(f"bobs_on_friend_typing NO {sSlot}")
|
|
||||||
except AssertionError as e:
|
|
||||||
LOG.error(f"Failed test {e}")
|
|
||||||
raise
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"test_alice_typing_status error={e}")
|
|
||||||
raise
|
|
||||||
finally:
|
|
||||||
self.bob.callback_friend_typing(None)
|
|
||||||
if hasattr(self, 'baid') and self.baid >= 0:
|
|
||||||
self.bob.friend_delete(self.baid)
|
|
||||||
if hasattr(self, 'abid') and self.abid >= 0:
|
|
||||||
self.alice.friend_delete(self.abid)
|
|
||||||
|
|
||||||
@expectedFail('fails') # @unittest.skip('unfinished')
|
@expectedFail('fails') # @unittest.skip('unfinished')
|
||||||
def test_file_transfer(self) -> None: # unfinished
|
def test_file_transfer(self) -> None: # unfinished
|
||||||
"""
|
"""
|
||||||
@ -2061,7 +2068,7 @@ class ToxSuite(unittest.TestCase):
|
|||||||
sleep(1)
|
sleep(1)
|
||||||
else:
|
else:
|
||||||
LOG.error(f"test_file_transfer bob.file_send 2")
|
LOG.error(f"test_file_transfer bob.file_send 2")
|
||||||
raise AssertionError(f"test_file_transfer bob.file_send {THRESHOLD // 2}")
|
raise AssertionError(f"test_file_transfer bob.file_send {self.bob._args.test_timeout // 2}")
|
||||||
|
|
||||||
# UINT32_MAX
|
# UINT32_MAX
|
||||||
try:
|
try:
|
||||||
|
@ -122,12 +122,12 @@ else:
|
|||||||
self.iterate()
|
self.iterate()
|
||||||
|
|
||||||
|
|
||||||
def save_to_file(tox, fname) -> None:
|
def save_to_file(tox, fname: str) -> None:
|
||||||
data = tox.get_savedata()
|
data = tox.get_savedata()
|
||||||
with open(fname, 'wb') as f:
|
with open(fname, 'wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
def load_from_file(fname:str):
|
def load_from_file(fname: str) -> bytes:
|
||||||
assert os.path.exists(fname)
|
assert os.path.exists(fname)
|
||||||
return open(fname, 'rb').read()
|
return open(fname, 'rb').read()
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ class EchoBot():
|
|||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
if not self.on_connection_status:
|
if not self.on_connection_status:
|
||||||
def on_connection_status(iTox, iCon, *largs):
|
def on_connection_status(iTox, iCon, *largs) -> None:
|
||||||
LOG_info('ON_CONNECTION_STATUS - CONNECTED ' + repr(iCon))
|
LOG_info('ON_CONNECTION_STATUS - CONNECTED ' + repr(iCon))
|
||||||
self._tox.callback_self_connection_status(on_connection_status)
|
self._tox.callback_self_connection_status(on_connection_status)
|
||||||
LOG.info('setting on_connection_status callback ')
|
LOG.info('setting on_connection_status callback ')
|
||||||
@ -280,14 +280,14 @@ class EchoBot():
|
|||||||
LOG.info('on_friend_request Accepted.')
|
LOG.info('on_friend_request Accepted.')
|
||||||
save_to_file(self._tox, sDATA_FILE)
|
save_to_file(self._tox, sDATA_FILE)
|
||||||
|
|
||||||
def on_friend_message(self, friendId:int , message_type, message: Union[bytes,str]) -> None:
|
def on_friend_message(self, friendId: int, message_type: int, message: Union[bytes,str]) -> None:
|
||||||
name = self._tox.friend_get_name(friendId)
|
name = self._tox.friend_get_name(friendId)
|
||||||
LOG.debug(f"{name}, {message}, {message_type}")
|
LOG.debug(f"{name}, {message}, {message_type}")
|
||||||
yMessage = bytes(message, 'UTF-8')
|
yMessage = bytes(message, 'UTF-8')
|
||||||
self._tox.friend_send_message(friendId, TOX_MESSAGE_TYPE['NORMAL'], yMessage)
|
self._tox.friend_send_message(friendId, TOX_MESSAGE_TYPE['NORMAL'], yMessage)
|
||||||
LOG.info('EchoBot sent: %s' % message)
|
LOG.info('EchoBot sent: %s' % message)
|
||||||
|
|
||||||
def on_file_recv_chunk(self, fid, filenumber, position, data) -> None:
|
def on_file_recv_chunk(self, fid: int, filenumber, position, data) -> None:
|
||||||
filename = self.files[(fid, filenumber)]['filename']
|
filename = self.files[(fid, filenumber)]['filename']
|
||||||
size = self.files[(fid, filenumber)]['size']
|
size = self.files[(fid, filenumber)]['size']
|
||||||
LOG.debug(f"on_file_recv_chunk {fid} {filenumber} {filename} {position/float(size)*100}")
|
LOG.debug(f"on_file_recv_chunk {fid} {filenumber} {filename} {position/float(size)*100}")
|
||||||
@ -362,11 +362,7 @@ def oArgparse(lArgv):
|
|||||||
parser.add_argument('profile', type=str, nargs='?', default=None,
|
parser.add_argument('profile', type=str, nargs='?', default=None,
|
||||||
help='Path to Tox profile')
|
help='Path to Tox profile')
|
||||||
oArgs = parser.parse_args(lArgv)
|
oArgs = parser.parse_args(lArgv)
|
||||||
|
ts.clean_booleans(oArgs)
|
||||||
for key in ts.lBOOLEANS:
|
|
||||||
if key not in oArgs: continue
|
|
||||||
val = getattr(oArgs, key)
|
|
||||||
setattr(oArgs, key, bool(val))
|
|
||||||
|
|
||||||
if hasattr(oArgs, 'sleep'):
|
if hasattr(oArgs, 'sleep'):
|
||||||
if oArgs.sleep == 'qt':
|
if oArgs.sleep == 'qt':
|
||||||
@ -432,13 +428,13 @@ def iMain(oArgs) -> int:
|
|||||||
|
|
||||||
def main(lArgs=None) -> int:
|
def main(lArgs=None) -> int:
|
||||||
global oTOX_OARGS
|
global oTOX_OARGS
|
||||||
|
global oTOX_OPTIONS
|
||||||
global bIS_LOCAL
|
global bIS_LOCAL
|
||||||
if lArgs is None: lArgs = []
|
if lArgs is None: lArgs = []
|
||||||
oArgs = oArgparse(lArgs)
|
oArgs = oArgparse(lArgs)
|
||||||
bIS_LOCAL = oArgs.network in ['newlocal', 'localnew', 'local']
|
bIS_LOCAL = oArgs.network in ['newlocal', 'localnew', 'local']
|
||||||
oTOX_OARGS = oArgs
|
oTOX_OARGS = oArgs
|
||||||
setattr(oTOX_OARGS, 'bIS_LOCAL', bIS_LOCAL)
|
setattr(oTOX_OARGS, 'bIS_LOCAL', bIS_LOCAL)
|
||||||
global oTOX_OPTIONS
|
|
||||||
oTOX_OPTIONS = ts.oToxygenToxOptions(oArgs)
|
oTOX_OPTIONS = ts.oToxygenToxOptions(oArgs)
|
||||||
if coloredlogs:
|
if coloredlogs:
|
||||||
# https://pypi.org/project/coloredlogs/
|
# https://pypi.org/project/coloredlogs/
|
||||||
|
Loading…
Reference in New Issue
Block a user