+ added file for command testing

master
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> <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

View File

@ -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

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