rnsh/tests/test_args.py
Aaron Heise 27664df0b3 Several test-driven fixes
- Improved test suite exposed several issues with the handling of
command line arguments which are now fixed
- Fixed a race condition that would cause remote characters to be
  lost intermittently when running remote commands that finish
  immediately.
- Added automated testing that actually spins up a random listener
  and initiator in a private Reticulum network and passes data
  between them, uncovering more issues which are now fixed.
- Fixed (hopefully) an issue where `rnsh` doesn't know what
  version it is.
2023-02-14 15:42:55 -06:00

77 lines
2.4 KiB
Python

import rnsh.args
import shlex
import docopt
def test_program_args():
docopt_threw = False
try:
args = rnsh.args.Args(shlex.split("rnsh -l -n one two three"))
assert args.listen
assert args.program == "one"
assert args.program_args == ["two", "three"]
assert args.command_line == ["one", "two", "three"]
except docopt.DocoptExit:
docopt_threw = True
assert not docopt_threw
def test_program_args_dash():
docopt_threw = False
try:
args = rnsh.args.Args(shlex.split("rnsh -l -n -- one -l -C"))
assert args.listen
assert args.program == "one"
assert args.program_args == ["-l", "-C"]
assert args.command_line == ["one", "-l", "-C"]
except docopt.DocoptExit:
docopt_threw = True
assert not docopt_threw
def test_program_initiate_no_args():
docopt_threw = False
try:
args = rnsh.args.Args(shlex.split("rnsh one"))
assert not args.listen
assert args.destination == "one"
assert args.command_line == []
except docopt.DocoptExit:
docopt_threw = True
assert not docopt_threw
def test_program_initiate_dash_args():
docopt_threw = False
try:
args = rnsh.args.Args(shlex.split("rnsh --config ~/Projects/rnsh/testconfig -s test -vvvvvvv a5f72aefc2cb3cdba648f73f77c4e887 -- -l"))
assert not args.listen
assert args.config == "~/Projects/rnsh/testconfig"
assert args.service_name == "test"
assert args.verbose == 7
assert args.destination == "a5f72aefc2cb3cdba648f73f77c4e887"
assert args.command_line == ["-l"]
except docopt.DocoptExit:
docopt_threw = True
assert not docopt_threw
def test_program_listen_config_print():
docopt_threw = False
try:
args = rnsh.args.Args(shlex.split("rnsh -l --config testconfig -p"))
assert args.listen
assert args.config == "testconfig"
assert args.print_identity
assert args.command_line == []
except docopt.DocoptExit:
docopt_threw = True
assert not docopt_threw
def test_split_at():
a, b = rnsh.args._split_array_at(["one", "two", "three"], "two")
assert a == ["one"]
assert b == ["three"]
def test_split_at_not_found():
a, b = rnsh.args._split_array_at(["one", "two", "three"], "four")
assert a == ["one", "two", "three"]
assert b == []