Browse Source

+ added file for command testing

merge-requests/24/merge
Kevin Froman 2 years ago
parent
commit
3ce0a617ae
  1. 4
      README.md
  2. 8
      onionr/onionrcommands/parser/__init__.py
  3. 19
      onionr/tests/test_commands.py

4
README.md

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

8
onionr/onionrcommands/parser/__init__.py

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

19
onionr/tests/test_commands.py

@ -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…
Cancel
Save