+ added file for command testing

This commit is contained in:
Kevin Froman 2019-08-29 19:37:39 -05:00
parent e02e7dba87
commit 3ce0a617ae
3 changed files with 28 additions and 3 deletions

View File

@ -15,7 +15,9 @@
<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

View File

@ -36,7 +36,9 @@ def register_plugin_commands(cmd):
return True
def register():
"""Registers commands and handles help command processing"""
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)
for pl in onionrplugins.get_enabled_plugins():
pl = onionrplugins.get_plugin(pl)
@ -52,14 +54,16 @@ def register():
return arguments.get_help(cmd)
except AttributeError:
pass
return default
return default # Return the help string
PROGRAM_NAME = "onionr"
# Get the command
try:
cmd = sys.argv[1]
except IndexError:
cmd = ""
logger.debug("Detected Onionr run with no commands specified")
return
is_help_cmd = False
if cmd.replace('--', '').lower() == 'help': is_help_cmd = True

View 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()