2
# -*- mode: python; coding: utf-8; after-save-hook: (lambda () (let ((command (if (and (boundp 'tramp-file-name-structure) (string-match (car tramp-file-name-structure) (buffer-file-name))) (tramp-file-name-localname (tramp-dissect-file-name (buffer-file-name))) (buffer-file-name)))) (if (= (shell-command (format "%s --check" (shell-quote-argument command)) "*Test*") 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w)) (kill-buffer "*Test*")) (display-buffer "*Test*")))); -*-
2
# -*- after-save-hook: (lambda () (let ((command (if (fboundp 'file-local-name) (file-local-name (buffer-file-name)) (or (file-remote-p (buffer-file-name) 'localname) (buffer-file-name))))) (if (= (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (format "%s --test" (shell-quote-argument command)) nil "*Test*")) 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w))) (progn (with-current-buffer "*Test*" (compilation-mode)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); coding: utf-8 -*-
4
4
# Mandos Monitor - Control and monitor the Mandos server
1780
1780
self.assert_command_from_args(["--is-enabled", "client"],
1781
1781
command.IsEnabled)
1783
def assert_command_from_args(self, args, command_cls,
1783
def assert_command_from_args(self, args, command_cls, length=1,
1784
clients=None, **cmd_attrs):
1785
1785
"""Assert that parsing ARGS should result in an instance of
1786
1786
COMMAND_CLS with (optionally) all supplied attributes (CMD_ATTRS)."""
1787
1787
options = self.parser.parse_args(args)
1788
1788
check_option_syntax(self.parser, options)
1789
1789
commands = commands_from_options(options)
1790
self.assertEqual(1, len(commands))
1791
command = commands[0]
1792
self.assertIsInstance(command, command_cls)
1790
self.assertEqual(length, len(commands))
1791
for command in commands:
1792
if isinstance(command, command_cls):
1795
self.assertIsInstance(command, command_cls)
1796
if clients is not None:
1797
self.assertEqual(clients, options.client)
1793
1798
for key, value in cmd_attrs.items():
1794
1799
self.assertEqual(value, getattr(command, key))
1801
def assert_commands_from_args(self, args, commands, clients=None):
1802
for cmd in commands:
1803
self.assert_command_from_args(args, cmd,
1804
length=len(commands),
1796
1807
def test_is_enabled_short(self):
1797
1808
self.assert_command_from_args(["-V", "client"],
1798
1809
command.IsEnabled)
2003
def test_manual_page_example_1(self):
2004
self.assert_command_from_args("--verbose".split(),
2009
def test_manual_page_example_2(self):
2010
self.assert_command_from_args(
2011
"--verbose foo1.example.org foo2.example.org".split(),
2012
command.PrintTable, clients=["foo1.example.org",
2013
"foo2.example.org"],
2016
def test_manual_page_example_3(self):
2017
self.assert_command_from_args("--enable --all".split(),
2021
def test_manual_page_example_4(self):
2022
self.assert_commands_from_args(
2023
("--timeout=PT5M --interval=PT1M foo1.example.org"
2024
" foo2.example.org").split(),
2025
[command.SetTimeout, command.SetInterval],
2026
clients=["foo1.example.org", "foo2.example.org"])
2028
def test_manual_page_example_5(self):
2029
self.assert_command_from_args("--approve --all".split(),
1992
2034
class TestCommand(unittest.TestCase):
1993
2035
"""Abstract class for tests of command classes"""