Ticket #6444: 6444v3.patch

File 6444v3.patch, 6.5 KB (added by Stephen Solis, 9 years ago)

Addressed review suggestions

  • twisted/test/test_usage.py

     
    3636
    3737class ParseCorrectnessTest(unittest.TestCase):
    3838    """
    39     Test Options.parseArgs for correct values under good conditions.
     39    Test L{usage.Options.parseOptions} for correct values under
     40    good conditions.
    4041    """
    4142    def setUp(self):
    4243        """
     
    5354
    5455    def test_checkParameters(self):
    5556        """
    56         Checking that parameters have correct values.
     57        Parameters have correct values.
    5758        """
    5859        self.assertEqual(self.nice.opts['long'], "Alpha")
    5960        self.assertEqual(self.nice.opts['another'], "Beta")
     
    6263
    6364    def test_checkFlags(self):
    6465        """
    65         Checking that flags have correct values.
     66        Flags have correct values.
    6667        """
    6768        self.assertEqual(self.nice.opts['aflag'], 1)
    6869        self.assertEqual(self.nice.opts['flout'], 0)
    6970
    7071    def test_checkCustoms(self):
    7172        """
    72         Checking that custom flags and parameters have correct values.
     73        Custom flags and parameters have correct values.
    7374        """
    7475        self.assertEqual(self.nice.opts['myflag'], "PONY!")
    7576        self.assertEqual(self.nice.opts['myparam'], "Tofu WITH A PONY!")
     
    9697
    9798class TypedTestCase(unittest.TestCase):
    9899    """
    99     Test Options.parseArgs for options with forced types.
     100    Test L{usage.Options.parseOptions} for options with forced types.
    100101    """
    101102    def setUp(self):
    102103        self.usage = TypedOptions()
    103104
    104105    def test_defaultValues(self):
    105106        """
    106         Test parsing of default values.
     107        Default values are parsed.
    107108        """
    108109        argV = []
    109110        self.usage.parseOptions(argV)
     
    117118
    118119    def test_parsingValues(self):
    119120        """
    120         Test basic parsing of int and float values.
     121        int and float values are parsed.
    121122        """
    122123        argV = ("--fooint 912 --foofloat -823.1 "
    123124                "--eggint 32 --eggfloat 21").split()
     
    151152
    152153    def test_invalidValues(self):
    153154        """
    154         Check that passing wrong values raises an error.
     155        Passing wrong values raises an error.
    155156        """
    156157        argV = "--fooint egg".split()
    157158        self.assertRaises(usage.UsageError, self.usage.parseOptions, argV)
     
    177178
    178179class WrongTypedTestCase(unittest.TestCase):
    179180    """
    180     Test Options.parseArgs for wrong coerce options.
     181    Test L{usage.Options.parseOptions} for wrong coerce options.
    181182    """
    182183    def test_nonCallable(self):
    183184        """
    184         Check that using a non callable type fails.
     185        Using a non-callable type fails.
    185186        """
    186187        us =  WrongTypedOptions()
    187188        argV = "--barwrong egg".split()
     
    189190
    190191    def test_notCalledInDefault(self):
    191192        """
    192         Test that the coerce functions are not called if no values are
    193         provided.
     193        The coerce functions are not called if no values are provided.
    194194        """
    195195        us = WeirdCallableOptions()
    196196        argV = []
     
    198198
    199199    def test_weirdCallable(self):
    200200        """
    201         Test what happens when coerce functions raise errors.
     201        Errors raised by coerce functions are handled properly.
    202202        """
    203203        us = WeirdCallableOptions()
    204204        argV = "--foowrong blah".split()
     
    254254
    255255
    256256class SubCommandTest(unittest.TestCase):
    257 
     257    """
     258    Test L{usage.Options.parseOptions} for options with subcommands.
     259    """
    258260    def test_simpleSubcommand(self):
     261        """
     262        A subcommand is recognized.
     263        """
    259264        o = SubCommandOptions()
    260265        o.parseOptions(['--europian-swallow', 'inquisition'])
    261266        self.assertEqual(o['europian-swallow'], True)
     
    265270        self.assertEqual(o.subOptions['torture-device'], 'comfy-chair')
    266271
    267272    def test_subcommandWithFlagsAndOptions(self):
     273        """
     274        Flags and options of a subcommand are assigned.
     275        """
    268276        o = SubCommandOptions()
    269277        o.parseOptions(['inquisition', '--expect', '--torture-device=feather'])
    270278        self.assertEqual(o['europian-swallow'], False)
     
    274282        self.assertEqual(o.subOptions['torture-device'], 'feather')
    275283
    276284    def test_subcommandAliasWithFlagsAndOptions(self):
     285        """
     286        Flags and options of a subcommand alias are assigned.
     287        """
    277288        o = SubCommandOptions()
    278289        o.parseOptions(['inquest', '--expect', '--torture-device=feather'])
    279290        self.assertEqual(o['europian-swallow'], False)
     
    283294        self.assertEqual(o.subOptions['torture-device'], 'feather')
    284295
    285296    def test_anotherSubcommandWithFlagsAndOptions(self):
     297        """
     298        Flags and options of another subcommand are assigned.
     299        """
    286300        o = SubCommandOptions()
    287301        o.parseOptions(['holyquest', '--for-grail'])
    288302        self.assertEqual(o['europian-swallow'], False)
     
    292306        self.assertEqual(o.subOptions['for-grail'], True)
    293307
    294308    def test_noSubcommand(self):
     309        """
     310        If no subcommand is specified and no default subcommand is assigned,
     311        a subcommand will not be implied.
     312        """
    295313        o = SubCommandOptions()
    296314        o.parseOptions(['--europian-swallow'])
    297315        self.assertEqual(o['europian-swallow'], True)
     
    299317        self.failIf(hasattr(o, 'subOptions'))
    300318
    301319    def test_defaultSubcommand(self):
     320        """
     321        Flags and options in the default subcommand are assigned.
     322        """
    302323        o = SubCommandOptions()
    303324        o.defaultSubCommand = 'inquest'
    304325        o.parseOptions(['--europian-swallow'])
     
    309330        self.assertEqual(o.subOptions['torture-device'], 'comfy-chair')
    310331
    311332    def test_subCommandParseOptionsHasParent(self):
     333        """
     334        The parseOptions method from the Options object specified for the
     335        given subcommand is called.
     336        """
    312337        class SubOpt(usage.Options):
    313338            def parseOptions(self, *a, **kw):
    314339                self.sawParent = self.parent
     
    348373
    349374
    350375class HelpStringTest(unittest.TestCase):
     376    """
     377    Test generated help strings.
     378    """
    351379    def setUp(self):
    352380        """
    353381        Instantiate a well-behaved Options class.
  • twisted/topfiles/6444.doc

     
     1twisted.test.test_usage now has more accurate and correct docstrings.