1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
import subprocess
import unittest
from commontest import RBBin
from rdiff_backup import Globals
from rdiffbackup import arguments, actions_mgr
class ArgumentsTest(unittest.TestCase):
"""
Test how the function 'parse' is parsing arguments, using the new interface.
"""
def test_new_help(self):
"""
- make sure that the new help is shown either with --new or by using an action
"""
output = subprocess.run([RBBin, b'--new', b'--help'],
capture_output=True)
self.assertIn(b"possible actions:", output.stdout)
self.assertEqual(0, output.returncode)
output = subprocess.run([RBBin, b'info', b'--help'],
capture_output=True)
self.assertIn(b"Output information", output.stdout)
self.assertEqual(Globals.RET_CODE_OK, output.returncode)
def test_error_return_code(self):
"""
- verify that a wrong arguments returns 1 instead of the standard 2
"""
output = subprocess.run([RBBin, b'--thisdoesntexist'],
capture_output=True)
self.assertIn(b"unrecognized arguments:", output.stderr)
self.assertEqual(Globals.RET_CODE_ERR, output.returncode)
def test_parse_function(self):
"""
- verify that the --version option exits and make a few more smoke tests of the parse option
"""
disc_actions = actions_mgr.get_actions_dict()
# verify that the --version option exits the program
with self.assertRaises(SystemExit):
values = arguments.parse(["--version"], "testing 0.0.1",
actions_mgr.get_generic_parsers(),
actions_mgr.get_parent_parsers_compat200(),
disc_actions)
# positive test of the parsing
values = arguments.parse(["list", "increments", "dummy_test_repo"], "testing 0.0.2",
actions_mgr.get_generic_parsers(),
actions_mgr.get_parent_parsers_compat200(),
disc_actions)
self.assertEqual("list", values.action)
self.assertEqual("increments", values.entity)
self.assertIn("dummy_test_repo", values.locations)
# negative test of the parsing due to too many or wrong arguments
with self.assertRaises(SystemExit):
values = arguments.parse(["backup", "from", "to", "toomuch"], "testing 0.0.3",
actions_mgr.get_generic_parsers(),
actions_mgr.get_parent_parsers_compat200(),
disc_actions)
with self.assertRaises(SystemExit):
values = arguments.parse(["restore", "--no-such-thing", "from", "to"], "testing 0.0.4",
actions_mgr.get_generic_parsers(),
actions_mgr.get_parent_parsers_compat200(),
disc_actions)
if __name__ == "__main__":
unittest.main()
|