+ added file for command testing
This commit is contained in:
parent
e02e7dba87
commit
3ce0a617ae
@ -15,7 +15,9 @@
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
**The main repository for this software is at https://gitlab.com/beardog/Onionr/**
|
**The main repository for this software is at https://GitLab.com/beardog/Onionr/**
|
||||||
|
|
||||||
|
**The Github page is a mirror, do not submit PRs or issues there.**
|
||||||
|
|
||||||
# About
|
# About
|
||||||
|
|
||||||
|
@ -36,7 +36,9 @@ def register_plugin_commands(cmd):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
|
"""Registers commands and handles help command processing"""
|
||||||
def get_help_message(cmd: str, default: str = 'No help available for this command'):
|
def get_help_message(cmd: str, default: str = 'No help available for this command'):
|
||||||
|
"""Return help message for a given command, supports plugin commands"""
|
||||||
pl_cmd = plugin_command(cmd)
|
pl_cmd = plugin_command(cmd)
|
||||||
for pl in onionrplugins.get_enabled_plugins():
|
for pl in onionrplugins.get_enabled_plugins():
|
||||||
pl = onionrplugins.get_plugin(pl)
|
pl = onionrplugins.get_plugin(pl)
|
||||||
@ -52,14 +54,16 @@ def register():
|
|||||||
return arguments.get_help(cmd)
|
return arguments.get_help(cmd)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
return default
|
return default # Return the help string
|
||||||
|
|
||||||
PROGRAM_NAME = "onionr"
|
PROGRAM_NAME = "onionr"
|
||||||
|
|
||||||
|
# Get the command
|
||||||
try:
|
try:
|
||||||
cmd = sys.argv[1]
|
cmd = sys.argv[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
cmd = ""
|
logger.debug("Detected Onionr run with no commands specified")
|
||||||
|
return
|
||||||
|
|
||||||
is_help_cmd = False
|
is_help_cmd = False
|
||||||
if cmd.replace('--', '').lower() == 'help': is_help_cmd = True
|
if cmd.replace('--', '').lower() == 'help': is_help_cmd = True
|
||||||
|
19
onionr/tests/test_commands.py
Normal file
19
onionr/tests/test_commands.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
|
import sys, os
|
||||||
|
sys.path.append(".")
|
||||||
|
import unittest, uuid
|
||||||
|
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
|
||||||
|
print("Test directory:", TEST_DIR)
|
||||||
|
os.environ["ONIONR_HOME"] = TEST_DIR
|
||||||
|
from onionrcommands import parser
|
||||||
|
class OnionrTests(unittest.TestCase):
|
||||||
|
def test_no_command(self):
|
||||||
|
testargs = ["onionr.py"]
|
||||||
|
with patch.object(sys, 'argv', testargs):
|
||||||
|
parser.register()
|
||||||
|
def test_version_command(self):
|
||||||
|
testargs = ["onionr.py", "version"]
|
||||||
|
with patch.object(sys, 'argv', testargs):
|
||||||
|
parser.register()
|
||||||
|
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user