Linux ubuntu22 5.15.0-133-generic #144-Ubuntu SMP Fri Feb 7 20:47:38 UTC 2025 x86_64
nginx/1.18.0
: 128.199.27.159 | : 216.73.216.2
Cant Read [ /etc/named.conf ]
8.1.31
www-data
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
usr /
lib /
python3 /
dist-packages /
twisted /
test /
[ HOME SHELL ]
Name
Size
Permission
Action
__pycache__
[ DIR ]
drwxr-xr-x
__init__.py
475
B
-rw-r--r--
cert.pem.no_trailing_newline
1.38
KB
-rw-r--r--
crash_test_dummy.py
549
B
-rw-r--r--
ignore_test_failure.py
30.72
KB
-rw-r--r--
iosim.py
17.74
KB
-rw-r--r--
key.pem.no_trailing_newline
1.67
KB
-rw-r--r--
mock_win32process.py
1.27
KB
-rw-r--r--
myrebuilder1.py
151
B
-rw-r--r--
myrebuilder2.py
151
B
-rw-r--r--
plugin_basic.py
901
B
-rw-r--r--
plugin_extra1.py
392
B
-rw-r--r--
plugin_extra2.py
550
B
-rw-r--r--
process_cmdline.py
123
B
-rw-r--r--
process_echoer.py
214
B
-rw-r--r--
process_fds.py
984
B
-rw-r--r--
process_getargv.py
234
B
-rw-r--r--
process_getenv.py
268
B
-rw-r--r--
process_linger.py
297
B
-rw-r--r--
process_reader.py
178
B
-rw-r--r--
process_signal.py
220
B
-rw-r--r--
process_stdinreader.py
739
B
-rw-r--r--
process_tester.py
779
B
-rw-r--r--
process_tty.py
130
B
-rw-r--r--
process_twisted.py
1.15
KB
-rw-r--r--
proto_helpers.py
1.34
KB
-rw-r--r--
reflect_helper_IE.py
60
B
-rw-r--r--
reflect_helper_VE.py
81
B
-rw-r--r--
reflect_helper_ZDE.py
48
B
-rw-r--r--
server.pem
4.34
KB
-rw-r--r--
ssl_helpers.py
1.61
KB
-rw-r--r--
stdio_test_consumer.py
1.14
KB
-rw-r--r--
stdio_test_halfclose.py
2
KB
-rw-r--r--
stdio_test_hostpeer.py
1.06
KB
-rw-r--r--
stdio_test_lastwrite.py
1.13
KB
-rw-r--r--
stdio_test_loseconn.py
1.55
KB
-rw-r--r--
stdio_test_producer.py
1.45
KB
-rw-r--r--
stdio_test_write.py
902
B
-rw-r--r--
stdio_test_writeseq.py
894
B
-rw-r--r--
test_abstract.py
3.35
KB
-rw-r--r--
test_adbapi.py
25.56
KB
-rw-r--r--
test_amp.py
107.92
KB
-rw-r--r--
test_application.py
33.34
KB
-rw-r--r--
test_compat.py
17.75
KB
-rw-r--r--
test_context.py
1.43
KB
-rw-r--r--
test_cooperator.py
20.84
KB
-rw-r--r--
test_defer.py
121.86
KB
-rw-r--r--
test_defgen.py
10.38
KB
-rw-r--r--
test_dict.py
1.49
KB
-rw-r--r--
test_dirdbm.py
6.69
KB
-rw-r--r--
test_error.py
8.72
KB
-rw-r--r--
test_factories.py
4.46
KB
-rw-r--r--
test_fdesc.py
7.28
KB
-rw-r--r--
test_finger.py
1.85
KB
-rw-r--r--
test_formmethod.py
3.87
KB
-rw-r--r--
test_ftp.py
126.96
KB
-rw-r--r--
test_ftp_options.py
2.63
KB
-rw-r--r--
test_htb.py
3.08
KB
-rw-r--r--
test_ident.py
6.56
KB
-rw-r--r--
test_internet.py
45.38
KB
-rw-r--r--
test_iosim.py
8.7
KB
-rw-r--r--
test_iutils.py
13.31
KB
-rw-r--r--
test_lockfile.py
14.98
KB
-rw-r--r--
test_log.py
35.23
KB
-rw-r--r--
test_logfile.py
17.47
KB
-rw-r--r--
test_loopback.py
13.99
KB
-rw-r--r--
test_main.py
2.12
KB
-rw-r--r--
test_memcache.py
24.69
KB
-rw-r--r--
test_modules.py
17.02
KB
-rw-r--r--
test_monkey.py
5.39
KB
-rw-r--r--
test_paths.py
69.31
KB
-rw-r--r--
test_pcp.py
12.23
KB
-rw-r--r--
test_persisted.py
13.09
KB
-rw-r--r--
test_plugin.py
24.79
KB
-rw-r--r--
test_policies.py
32.29
KB
-rw-r--r--
test_postfix.py
4.32
KB
-rw-r--r--
test_process.py
85.16
KB
-rw-r--r--
test_protocols.py
7.16
KB
-rw-r--r--
test_randbytes.py
3.19
KB
-rw-r--r--
test_rebuild.py
7.15
KB
-rw-r--r--
test_reflect.py
23.9
KB
-rw-r--r--
test_roots.py
1.6
KB
-rw-r--r--
test_shortcut.py
1.92
KB
-rw-r--r--
test_sip.py
24.9
KB
-rw-r--r--
test_sob.py
5.53
KB
-rw-r--r--
test_socks.py
17.09
KB
-rw-r--r--
test_ssl.py
22.75
KB
-rw-r--r--
test_sslverify.py
113.89
KB
-rw-r--r--
test_stateful.py
1.97
KB
-rw-r--r--
test_stdio.py
12.43
KB
-rw-r--r--
test_strerror.py
5.12
KB
-rw-r--r--
test_strports.py
1.67
KB
-rw-r--r--
test_task.py
45.26
KB
-rw-r--r--
test_tcp.py
64.27
KB
-rw-r--r--
test_tcp_internals.py
12.73
KB
-rw-r--r--
test_text.py
6.22
KB
-rw-r--r--
test_threadable.py
3.26
KB
-rw-r--r--
test_threadpool.py
21.44
KB
-rw-r--r--
test_threads.py
12.9
KB
-rw-r--r--
test_tpfile.py
1.51
KB
-rw-r--r--
test_twistd.py
72.04
KB
-rw-r--r--
test_twisted.py
6.13
KB
-rw-r--r--
test_udp.py
24.43
KB
-rw-r--r--
test_unix.py
13.26
KB
-rw-r--r--
test_usage.py
22.76
KB
-rw-r--r--
testutils.py
5.06
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : test_usage.py
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Tests for L{twisted.python.usage}, a command line option parsing library. """ from twisted.python import usage from twisted.trial import unittest class WellBehaved(usage.Options): optParameters = [ ["long", "w", "default", "and a docstring"], ["another", "n", "no docstring"], ["longonly", None, "noshort"], ["shortless", None, "except", "this one got docstring"], ] optFlags = [ [ "aflag", "f", """ flagallicious docstringness for this here """, ], ["flout", "o"], ] def opt_myflag(self): self.opts["myflag"] = "PONY!" def opt_myparam(self, value): self.opts["myparam"] = f"{value} WITH A PONY!" class ParseCorrectnessTests(unittest.TestCase): """ Test L{usage.Options.parseOptions} for correct values under good conditions. """ def setUp(self): """ Instantiate and parseOptions a well-behaved Options class. """ self.niceArgV = ( "--long Alpha -n Beta " "--shortless Gamma -f --myflag " "--myparam Tofu" ).split() self.nice = WellBehaved() self.nice.parseOptions(self.niceArgV) def test_checkParameters(self): """ Parameters have correct values. """ self.assertEqual(self.nice.opts["long"], "Alpha") self.assertEqual(self.nice.opts["another"], "Beta") self.assertEqual(self.nice.opts["longonly"], "noshort") self.assertEqual(self.nice.opts["shortless"], "Gamma") def test_checkFlags(self): """ Flags have correct values. """ self.assertEqual(self.nice.opts["aflag"], 1) self.assertEqual(self.nice.opts["flout"], 0) def test_checkCustoms(self): """ Custom flags and parameters have correct values. """ self.assertEqual(self.nice.opts["myflag"], "PONY!") self.assertEqual(self.nice.opts["myparam"], "Tofu WITH A PONY!") class TypedOptions(usage.Options): optParameters = [ ["fooint", None, 392, "Foo int", int], ["foofloat", None, 4.23, "Foo float", float], ["eggint", None, None, "Egg int without default", int], ["eggfloat", None, None, "Egg float without default", float], ] def opt_under_score(self, value): """ This option has an underscore in its name to exercise the _ to - translation. """ self.underscoreValue = value opt_u = opt_under_score class TypedTests(unittest.TestCase): """ Test L{usage.Options.parseOptions} for options with forced types. """ def setUp(self): self.usage = TypedOptions() def test_defaultValues(self): """ Default values are parsed. """ argV = [] self.usage.parseOptions(argV) self.assertEqual(self.usage.opts["fooint"], 392) self.assertIsInstance(self.usage.opts["fooint"], int) self.assertEqual(self.usage.opts["foofloat"], 4.23) self.assertIsInstance(self.usage.opts["foofloat"], float) self.assertIsNone(self.usage.opts["eggint"]) self.assertIsNone(self.usage.opts["eggfloat"]) def test_parsingValues(self): """ int and float values are parsed. """ argV = ("--fooint 912 --foofloat -823.1 " "--eggint 32 --eggfloat 21").split() self.usage.parseOptions(argV) self.assertEqual(self.usage.opts["fooint"], 912) self.assertIsInstance(self.usage.opts["fooint"], int) self.assertEqual(self.usage.opts["foofloat"], -823.1) self.assertIsInstance(self.usage.opts["foofloat"], float) self.assertEqual(self.usage.opts["eggint"], 32) self.assertIsInstance(self.usage.opts["eggint"], int) self.assertEqual(self.usage.opts["eggfloat"], 21.0) self.assertIsInstance(self.usage.opts["eggfloat"], float) def test_underscoreOption(self): """ A dash in an option name is translated to an underscore before being dispatched to a handler. """ self.usage.parseOptions(["--under-score", "foo"]) self.assertEqual(self.usage.underscoreValue, "foo") def test_underscoreOptionAlias(self): """ An option name with a dash in it can have an alias. """ self.usage.parseOptions(["-u", "bar"]) self.assertEqual(self.usage.underscoreValue, "bar") def test_invalidValues(self): """ Passing wrong values raises an error. """ argV = "--fooint egg".split() self.assertRaises(usage.UsageError, self.usage.parseOptions, argV) class WrongTypedOptions(usage.Options): optParameters = [["barwrong", None, None, "Bar with wrong coerce", "he"]] class WeirdCallableOptions(usage.Options): def _bar(value): raise RuntimeError("Ouch") def _foo(value): raise ValueError("Yay") optParameters = [ ["barwrong", None, None, "Bar with strange callable", _bar], ["foowrong", None, None, "Foo with strange callable", _foo], ] class WrongTypedTests(unittest.TestCase): """ Test L{usage.Options.parseOptions} for wrong coerce options. """ def test_nonCallable(self): """ Using a non-callable type fails. """ us = WrongTypedOptions() argV = "--barwrong egg".split() self.assertRaises(TypeError, us.parseOptions, argV) def test_notCalledInDefault(self): """ The coerce functions are not called if no values are provided. """ us = WeirdCallableOptions() argV = [] us.parseOptions(argV) def test_weirdCallable(self): """ Errors raised by coerce functions are handled properly. """ us = WeirdCallableOptions() argV = "--foowrong blah".split() # ValueError is swallowed as UsageError e = self.assertRaises(usage.UsageError, us.parseOptions, argV) self.assertEqual(str(e), "Parameter type enforcement failed: Yay") us = WeirdCallableOptions() argV = "--barwrong blah".split() # RuntimeError is not swallowed self.assertRaises(RuntimeError, us.parseOptions, argV) class OutputTests(unittest.TestCase): def test_uppercasing(self): """ Error output case adjustment does not mangle options """ opt = WellBehaved() e = self.assertRaises(usage.UsageError, opt.parseOptions, ["-Z"]) self.assertEqual(str(e), "option -Z not recognized") class InquisitionOptions(usage.Options): optFlags = [ ("expect", "e"), ] optParameters = [ ("torture-device", "t", "comfy-chair", "set preferred torture device"), ] class HolyQuestOptions(usage.Options): optFlags = [ ("horseback", "h", "use a horse"), ("for-grail", "g"), ] class SubCommandOptions(usage.Options): optFlags = [ ("europian-swallow", None, "set default swallow type to Europian"), ] subCommands = [ ("inquisition", "inquest", InquisitionOptions, "Perform an inquisition"), ("holyquest", "quest", HolyQuestOptions, "Embark upon a holy quest"), ] class SubCommandTests(unittest.TestCase): """ Test L{usage.Options.parseOptions} for options with subcommands. """ def test_simpleSubcommand(self): """ A subcommand is recognized. """ o = SubCommandOptions() o.parseOptions(["--europian-swallow", "inquisition"]) self.assertTrue(o["europian-swallow"]) self.assertEqual(o.subCommand, "inquisition") self.assertIsInstance(o.subOptions, InquisitionOptions) self.assertFalse(o.subOptions["expect"]) self.assertEqual(o.subOptions["torture-device"], "comfy-chair") def test_subcommandWithFlagsAndOptions(self): """ Flags and options of a subcommand are assigned. """ o = SubCommandOptions() o.parseOptions(["inquisition", "--expect", "--torture-device=feather"]) self.assertFalse(o["europian-swallow"]) self.assertEqual(o.subCommand, "inquisition") self.assertIsInstance(o.subOptions, InquisitionOptions) self.assertTrue(o.subOptions["expect"]) self.assertEqual(o.subOptions["torture-device"], "feather") def test_subcommandAliasWithFlagsAndOptions(self): """ Flags and options of a subcommand alias are assigned. """ o = SubCommandOptions() o.parseOptions(["inquest", "--expect", "--torture-device=feather"]) self.assertFalse(o["europian-swallow"]) self.assertEqual(o.subCommand, "inquisition") self.assertIsInstance(o.subOptions, InquisitionOptions) self.assertTrue(o.subOptions["expect"]) self.assertEqual(o.subOptions["torture-device"], "feather") def test_anotherSubcommandWithFlagsAndOptions(self): """ Flags and options of another subcommand are assigned. """ o = SubCommandOptions() o.parseOptions(["holyquest", "--for-grail"]) self.assertFalse(o["europian-swallow"]) self.assertEqual(o.subCommand, "holyquest") self.assertIsInstance(o.subOptions, HolyQuestOptions) self.assertFalse(o.subOptions["horseback"]) self.assertTrue(o.subOptions["for-grail"]) def test_noSubcommand(self): """ If no subcommand is specified and no default subcommand is assigned, a subcommand will not be implied. """ o = SubCommandOptions() o.parseOptions(["--europian-swallow"]) self.assertTrue(o["europian-swallow"]) self.assertIsNone(o.subCommand) self.assertFalse(hasattr(o, "subOptions")) def test_defaultSubcommand(self): """ Flags and options in the default subcommand are assigned. """ o = SubCommandOptions() o.defaultSubCommand = "inquest" o.parseOptions(["--europian-swallow"]) self.assertTrue(o["europian-swallow"]) self.assertEqual(o.subCommand, "inquisition") self.assertIsInstance(o.subOptions, InquisitionOptions) self.assertFalse(o.subOptions["expect"]) self.assertEqual(o.subOptions["torture-device"], "comfy-chair") def test_subCommandParseOptionsHasParent(self): """ The parseOptions method from the Options object specified for the given subcommand is called. """ class SubOpt(usage.Options): def parseOptions(self, *a, **kw): self.sawParent = self.parent usage.Options.parseOptions(self, *a, **kw) class Opt(usage.Options): subCommands = [ ("foo", "f", SubOpt, "bar"), ] o = Opt() o.parseOptions(["foo"]) self.assertTrue(hasattr(o.subOptions, "sawParent")) self.assertEqual(o.subOptions.sawParent, o) def test_subCommandInTwoPlaces(self): """ The .parent pointer is correct even when the same Options class is used twice. """ class SubOpt(usage.Options): pass class OptFoo(usage.Options): subCommands = [ ("foo", "f", SubOpt, "quux"), ] class OptBar(usage.Options): subCommands = [ ("bar", "b", SubOpt, "quux"), ] oFoo = OptFoo() oFoo.parseOptions(["foo"]) oBar = OptBar() oBar.parseOptions(["bar"]) self.assertTrue(hasattr(oFoo.subOptions, "parent")) self.assertTrue(hasattr(oBar.subOptions, "parent")) self.failUnlessIdentical(oFoo.subOptions.parent, oFoo) self.failUnlessIdentical(oBar.subOptions.parent, oBar) class HelpStringTests(unittest.TestCase): """ Test generated help strings. """ def setUp(self): """ Instantiate a well-behaved Options class. """ self.niceArgV = ( "--long Alpha -n Beta " "--shortless Gamma -f --myflag " "--myparam Tofu" ).split() self.nice = WellBehaved() def test_noGoBoom(self): """ __str__ shouldn't go boom. """ try: self.nice.__str__() except Exception as e: self.fail(e) def test_whitespaceStripFlagsAndParameters(self): """ Extra whitespace in flag and parameters docs is stripped. """ # We test this by making sure aflag and it's help string are on the # same line. lines = [s for s in str(self.nice).splitlines() if s.find("aflag") >= 0] self.assertTrue(len(lines) > 0) self.assertTrue(lines[0].find("flagallicious") >= 0) class PortCoerceTests(unittest.TestCase): """ Test the behavior of L{usage.portCoerce}. """ def test_validCoerce(self): """ Test the answers with valid input. """ self.assertEqual(0, usage.portCoerce("0")) self.assertEqual(3210, usage.portCoerce("3210")) self.assertEqual(65535, usage.portCoerce("65535")) def test_errorCoerce(self): """ Test error path. """ self.assertRaises(ValueError, usage.portCoerce, "") self.assertRaises(ValueError, usage.portCoerce, "-21") self.assertRaises(ValueError, usage.portCoerce, "212189") self.assertRaises(ValueError, usage.portCoerce, "foo") class ZshCompleterTests(unittest.TestCase): """ Test the behavior of the various L{twisted.usage.Completer} classes for producing output usable by zsh tab-completion system. """ def test_completer(self): """ Completer produces zsh shell-code that produces no completion matches. """ c = usage.Completer() got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, ":some-option:") c = usage.Completer(descr="some action", repeat=True) got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, "*:some action:") def test_files(self): """ CompleteFiles produces zsh shell-code that completes file names according to a glob. """ c = usage.CompleteFiles() got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, ':some-option (*):_files -g "*"') c = usage.CompleteFiles("*.py") got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, ':some-option (*.py):_files -g "*.py"') c = usage.CompleteFiles("*.py", descr="some action", repeat=True) got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, '*:some action (*.py):_files -g "*.py"') def test_dirs(self): """ CompleteDirs produces zsh shell-code that completes directory names. """ c = usage.CompleteDirs() got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, ":some-option:_directories") c = usage.CompleteDirs(descr="some action", repeat=True) got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, "*:some action:_directories") def test_list(self): """ CompleteList produces zsh shell-code that completes words from a fixed list of possibilities. """ c = usage.CompleteList("ABC") got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, ":some-option:(A B C)") c = usage.CompleteList(["1", "2", "3"]) got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, ":some-option:(1 2 3)") c = usage.CompleteList(["1", "2", "3"], descr="some action", repeat=True) got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, "*:some action:(1 2 3)") def test_multiList(self): """ CompleteMultiList produces zsh shell-code that completes multiple comma-separated words from a fixed list of possibilities. """ c = usage.CompleteMultiList("ABC") got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, ":some-option:_values -s , 'some-option' A B C") c = usage.CompleteMultiList(["1", "2", "3"]) got = c._shellCode("some-option", usage._ZSH) self.assertEqual(got, ":some-option:_values -s , 'some-option' 1 2 3") c = usage.CompleteMultiList(["1", "2", "3"], descr="some action", repeat=True) got = c._shellCode("some-option", usage._ZSH) expected = "*:some action:_values -s , 'some action' 1 2 3" self.assertEqual(got, expected) def test_usernames(self): """ CompleteUsernames produces zsh shell-code that completes system usernames. """ c = usage.CompleteUsernames() out = c._shellCode("some-option", usage._ZSH) self.assertEqual(out, ":some-option:_users") c = usage.CompleteUsernames(descr="some action", repeat=True) out = c._shellCode("some-option", usage._ZSH) self.assertEqual(out, "*:some action:_users") def test_groups(self): """ CompleteGroups produces zsh shell-code that completes system group names. """ c = usage.CompleteGroups() out = c._shellCode("some-option", usage._ZSH) self.assertEqual(out, ":group:_groups") c = usage.CompleteGroups(descr="some action", repeat=True) out = c._shellCode("some-option", usage._ZSH) self.assertEqual(out, "*:some action:_groups") def test_hostnames(self): """ CompleteHostnames produces zsh shell-code that completes hostnames. """ c = usage.CompleteHostnames() out = c._shellCode("some-option", usage._ZSH) self.assertEqual(out, ":some-option:_hosts") c = usage.CompleteHostnames(descr="some action", repeat=True) out = c._shellCode("some-option", usage._ZSH) self.assertEqual(out, "*:some action:_hosts") def test_userAtHost(self): """ CompleteUserAtHost produces zsh shell-code that completes hostnames or a word of the form <username>@<hostname>. """ c = usage.CompleteUserAtHost() out = c._shellCode("some-option", usage._ZSH) self.assertTrue(out.startswith(":host | user@host:")) c = usage.CompleteUserAtHost(descr="some action", repeat=True) out = c._shellCode("some-option", usage._ZSH) self.assertTrue(out.startswith("*:some action:")) def test_netInterfaces(self): """ CompleteNetInterfaces produces zsh shell-code that completes system network interface names. """ c = usage.CompleteNetInterfaces() out = c._shellCode("some-option", usage._ZSH) self.assertEqual(out, ":some-option:_net_interfaces") c = usage.CompleteNetInterfaces(descr="some action", repeat=True) out = c._shellCode("some-option", usage._ZSH) self.assertEqual(out, "*:some action:_net_interfaces") class CompleterNotImplementedTests(unittest.TestCase): """ Using an unknown shell constant with the various Completer() classes should raise NotImplementedError """ def test_unknownShell(self): """ Using an unknown shellType should raise NotImplementedError """ classes = [ usage.Completer, usage.CompleteFiles, usage.CompleteDirs, usage.CompleteList, usage.CompleteMultiList, usage.CompleteUsernames, usage.CompleteGroups, usage.CompleteHostnames, usage.CompleteUserAtHost, usage.CompleteNetInterfaces, ] for cls in classes: try: action = cls() except BaseException: action = cls(None) self.assertRaises( NotImplementedError, action._shellCode, None, "bad_shell_type" ) class FlagFunctionTests(unittest.TestCase): """ Tests for L{usage.flagFunction}. """ class SomeClass: """ Dummy class for L{usage.flagFunction} tests. """ def oneArg(self, a): """ A one argument method to be tested by L{usage.flagFunction}. @param a: a useless argument to satisfy the function's signature. """ def noArg(self): """ A no argument method to be tested by L{usage.flagFunction}. """ def manyArgs(self, a, b, c): """ A multiple arguments method to be tested by L{usage.flagFunction}. @param a: a useless argument to satisfy the function's signature. @param b: a useless argument to satisfy the function's signature. @param c: a useless argument to satisfy the function's signature. """ def test_hasArg(self): """ L{usage.flagFunction} returns C{False} if the method checked allows exactly one argument. """ self.assertIs(False, usage.flagFunction(self.SomeClass().oneArg)) def test_noArg(self): """ L{usage.flagFunction} returns C{True} if the method checked allows exactly no argument. """ self.assertIs(True, usage.flagFunction(self.SomeClass().noArg)) def test_tooManyArguments(self): """ L{usage.flagFunction} raises L{usage.UsageError} if the method checked allows more than one argument. """ exc = self.assertRaises( usage.UsageError, usage.flagFunction, self.SomeClass().manyArgs ) self.assertEqual("Invalid Option function for manyArgs", str(exc)) def test_tooManyArgumentsAndSpecificErrorMessage(self): """ L{usage.flagFunction} uses the given method name in the error message raised when the method allows too many arguments. """ exc = self.assertRaises( usage.UsageError, usage.flagFunction, self.SomeClass().manyArgs, "flubuduf" ) self.assertEqual("Invalid Option function for flubuduf", str(exc)) class OptionsInternalTests(unittest.TestCase): """ Tests internal behavior of C{usage.Options}. """ def test_optionsAliasesOrder(self): """ Options which are synonyms to another option are aliases towards the longest option name. """ class Opts(usage.Options): def opt_very_very_long(self): """ This is an option method with a very long name, that is going to be aliased. """ opt_short = opt_very_very_long opt_s = opt_very_very_long opts = Opts() self.assertEqual( dict.fromkeys(["s", "short", "very-very-long"], "very-very-long"), { "s": opts.synonyms["s"], "short": opts.synonyms["short"], "very-very-long": opts.synonyms["very-very-long"], }, )
Close