Added unittest for onionr subprocess module
This commit is contained in:
parent
061e2d1e01
commit
79639ba0af
@ -1,6 +1,7 @@
|
||||
from audioop import mul
|
||||
import multiprocessing
|
||||
|
||||
|
||||
def run_func_in_new_process(func, *args, **kwargs):
|
||||
queue = multiprocessing.Queue()
|
||||
|
||||
@ -14,9 +15,7 @@ def run_func_in_new_process(func, *args, **kwargs):
|
||||
else:
|
||||
queue.put(func())
|
||||
|
||||
|
||||
proc = multiprocessing.Process(target=_wrap_func, daemon=True)
|
||||
proc.start()
|
||||
return queue.get()
|
||||
|
||||
|
||||
|
31
tests/test_onionr_process.py
Normal file
31
tests/test_onionr_process.py
Normal file
@ -0,0 +1,31 @@
|
||||
import sys, os
|
||||
sys.path.append(".")
|
||||
sys.path.append("src/")
|
||||
import unittest, uuid
|
||||
|
||||
import requests
|
||||
|
||||
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
||||
print("Test directory:", TEST_DIR)
|
||||
os.environ["ONIONR_HOME"] = TEST_DIR
|
||||
import onionrprocess
|
||||
|
||||
class TestOnionrProcess(unittest.TestCase):
|
||||
def test_onionr_process(self):
|
||||
def _sub_proc():
|
||||
return 2
|
||||
def _sub_proc_arg(arg):
|
||||
return arg
|
||||
def _sub_proc_kwarg(arg=''):
|
||||
return arg
|
||||
def _sub_proc_kwarg_default(arg=4):
|
||||
return arg
|
||||
def _sub_proc_both(arg, arg2=5):
|
||||
return (arg, arg2)
|
||||
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc), 2)
|
||||
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc_arg, 3), 3)
|
||||
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc_kwarg, 4), 4)
|
||||
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc_kwarg_default), 4)
|
||||
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc_both, 6), (6, 5))
|
||||
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user