added cleanup test and test-re-runner automation script
parent
4e053f1b30
commit
a8290e2ac3
|
@ -23,6 +23,16 @@
|
|||
"panel": "new"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Run test by name",
|
||||
"type": "shell",
|
||||
"command": "source venv/bin/activate; scripts/run-unit-test-by-name.py",
|
||||
"group": "test",
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Enable dev config",
|
||||
"type": "process",
|
||||
|
|
|
@ -4,3 +4,4 @@ passphrase-generator.py: very simple utility to generate and print a strong pass
|
|||
enable-dev-config.py/disable-dev-config.py: enable/disable dev default config setup
|
||||
block-spammer.py: attack tool for spamming blocks
|
||||
announce-attack.py: flood a node with false nodes
|
||||
run-unit-test-by-name: runs a unit test (no browser, runtime or intgegration test) by name
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
import json
|
||||
|
||||
input("enter to continue") # hack to avoid vscode term input
|
||||
|
||||
conf = json.load(open('static-data/default_config.json', 'r'))
|
||||
|
||||
block_pow = int(input("Block POW level:"))
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
from time import sleep
|
||||
|
||||
input("enter to continue") # hack to avoid vscode term input
|
||||
|
||||
test = input("test file name:")
|
||||
if not test.endswith('.py'):
|
||||
test += '.py'
|
||||
|
||||
if os.path.exists(f'tests/{test}'):
|
||||
try:
|
||||
while True:
|
||||
os.system(f'python3 tests/{test}')
|
||||
if input("Enter to run again or n to stop:").lower().strip() == 'n':
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
else:
|
||||
print('No test found')
|
|
@ -1,8 +1,10 @@
|
|||
"""
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
cleanup files
|
||||
cleanup run files
|
||||
"""
|
||||
import os
|
||||
|
||||
import filepaths
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -17,7 +19,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
import os, filepaths
|
||||
|
||||
|
||||
def _safe_remove(path):
|
||||
try:
|
||||
|
@ -25,8 +27,13 @@ def _safe_remove(path):
|
|||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def delete_run_files():
|
||||
_safe_remove(filepaths.public_API_host_file)
|
||||
_safe_remove(filepaths.private_API_host_file)
|
||||
_safe_remove(filepaths.daemon_mark_file)
|
||||
_safe_remove(filepaths.lock_file)
|
||||
"""Delete run files, do not error if not found.
|
||||
|
||||
Test: test_cleanup.py
|
||||
"""
|
||||
_safe_remove(filepaths.public_API_host_file)
|
||||
_safe_remove(filepaths.private_API_host_file)
|
||||
_safe_remove(filepaths.daemon_mark_file)
|
||||
_safe_remove(filepaths.lock_file)
|
||||
|
|
|
@ -42,7 +42,7 @@ def __event_caller(event_name, data = {}):
|
|||
plugins.disable(plugin, stop_event = False)
|
||||
except Exception as e:
|
||||
logger.warn('Event "%s" failed for plugin "%s".' % (event_name, plugin), terminal=True)
|
||||
logger.debug(str(e), terminal=True)
|
||||
logger.debug((event_name + ' - ' + plugin + ' - ' + str(e)), terminal=True)
|
||||
|
||||
def event(event_name, data = {}, threaded = True):
|
||||
'''
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys, os
|
||||
sys.path.append(".")
|
||||
sys.path.append("src/")
|
||||
import uuid
|
||||
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
||||
print("Test directory:", TEST_DIR)
|
||||
os.environ["ONIONR_HOME"] = TEST_DIR
|
||||
import unittest, json
|
||||
|
||||
from utils import identifyhome, createdirs
|
||||
createdirs.create_dirs()
|
||||
from etc.cleanup import delete_run_files
|
||||
import filepaths
|
||||
|
||||
|
||||
run_file_paths = [
|
||||
filepaths.public_API_host_file,
|
||||
filepaths.private_API_host_file,
|
||||
filepaths.daemon_mark_file,
|
||||
filepaths.lock_file]
|
||||
|
||||
def _run_paths_exist():
|
||||
for f in run_file_paths:
|
||||
if not os.path.exists(f):
|
||||
return False
|
||||
return True
|
||||
|
||||
class TestDeleteRunFiles(unittest.TestCase):
|
||||
def test_delete_run_files(self):
|
||||
for x in run_file_paths:
|
||||
with open(x, 'w') as f:
|
||||
f.write("")
|
||||
self.assertTrue(_run_paths_exist())
|
||||
delete_run_files()
|
||||
self.assertFalse(_run_paths_exist())
|
||||
|
||||
|
||||
|
||||
unittest.main()
|
Loading…
Reference in New Issue