def test_mutuallyExclusiveCornerCase(self): """ Exercise a corner-case of ZshArgumentsGenerator.makeExcludesDict() where the long option name already exists in the `excludes` dict being built. """ class OddFighterAceOptions(FighterAceExtendedOptions): # since "fokker", etc, are already defined as mutually- # exclusive on the super-class, defining them again here forces # the corner-case to be exercised. optFlags = [[ 'anatra', None, 'Select the Anatra DS as your dogfighter aircraft' ]] compData = Completions(mutuallyExclusive=[[ 'anatra', 'fokker', 'albatros', 'spad', 'bristol' ]]) opts = OddFighterAceOptions() ag = _shellcomp.ZshArgumentsGenerator(opts, 'ace', BytesIO()) expected = { 'albatros': set(['anatra', 'b', 'bristol', 'f', 'fokker', 's', 'spad']), 'anatra': set(['a', 'albatros', 'b', 'bristol', 'f', 'fokker', 's', 'spad']), 'bristol': set(['a', 'albatros', 'anatra', 'f', 'fokker', 's', 'spad']), 'fokker': set(['a', 'albatros', 'anatra', 'b', 'bristol', 's', 'spad']), 'spad': set(['a', 'albatros', 'anatra', 'b', 'bristol', 'f', 'fokker']) } self.assertEqual(ag.excludes, expected)
def test_mutuallyExclusiveCornerCase(self): """ Exercise a corner-case of ZshArgumentsGenerator.makeExcludesDict() where the long option name already exists in the `excludes` dict being built. """ class OddFighterAceOptions(FighterAceExtendedOptions): # since "fokker", etc, are already defined as mutually- # exclusive on the super-class, defining them again here forces # the corner-case to be exercised. optFlags = [[ "anatra", None, "Select the Anatra DS as your dogfighter aircraft" ]] compData = Completions(mutuallyExclusive=[[ "anatra", "fokker", "albatros", "spad", "bristol" ]]) opts = OddFighterAceOptions() ag = _shellcomp.ZshArgumentsGenerator(opts, "ace", BytesIO()) expected = { "albatros": {"anatra", "b", "bristol", "f", "fokker", "s", "spad"}, "anatra": {"a", "albatros", "b", "bristol", "f", "fokker", "s", "spad"}, "bristol": {"a", "albatros", "anatra", "f", "fokker", "s", "spad"}, "fokker": {"a", "albatros", "anatra", "b", "bristol", "s", "spad"}, "spad": {"a", "albatros", "anatra", "b", "bristol", "f", "fokker"}, } self.assertEqual(ag.excludes, expected)
def test_poorlyDescribedOptMethod(self): """ Test corner case fetching an option description from a method docstring """ opts = FighterAceOptions() argGen = _shellcomp.ZshArgumentsGenerator(opts, 'ace', None) descr = argGen.getDescription('silly') # docstring for opt_silly is useless so it should just use the # option name as the description self.assertEqual(descr, 'silly')
def test_accumulateAdditionalOptions(self): """ We pick up options that are only defined by having an appropriately named method on your Options class, e.g. def opt_foo(self, foo) """ opts = FighterAceExtendedOptions() ag = _shellcomp.ZshArgumentsGenerator(opts, 'ace', BytesIO()) self.assertIn('nocrash', ag.flagNameToDefinition) self.assertIn('nocrash', ag.allOptionsNameToDefinition) self.assertIn('difficulty', ag.paramNameToDefinition) self.assertIn('difficulty', ag.allOptionsNameToDefinition)
def test_optMethodsDontOverride(self): """ opt_* methods on Options classes should not override the data provided in optFlags or optParameters. """ class Options(usage.Options): optFlags = [['flag', 'f', 'A flag']] optParameters = [['param', 'p', None, 'A param']] def opt_flag(self): """ junk description """ def opt_param(self, param): """ junk description """ opts = Options() argGen = _shellcomp.ZshArgumentsGenerator(opts, 'ace', None) self.assertEqual(argGen.getDescription('flag'), 'A flag') self.assertEqual(argGen.getDescription('param'), 'A param')
def test_optMethodsDontOverride(self): """ opt_* methods on Options classes should not override the data provided in optFlags or optParameters. """ class Options(usage.Options): optFlags = [["flag", "f", "A flag"]] optParameters = [["param", "p", None, "A param"]] def opt_flag(self): """ junk description """ def opt_param(self, param): """ junk description """ opts = Options() argGen = _shellcomp.ZshArgumentsGenerator(opts, "ace", None) self.assertEqual(argGen.getDescription("flag"), "A flag") self.assertEqual(argGen.getDescription("param"), "A param")
def test_accumulateMetadata(self): """ Are `compData' attributes you can place on Options classes picked up correctly? """ opts = FighterAceExtendedOptions() ag = _shellcomp.ZshArgumentsGenerator(opts, 'ace', BytesIO()) descriptions = FighterAceOptions.compData.descriptions.copy() descriptions.update(FighterAceExtendedOptions.compData.descriptions) self.assertEqual(ag.descriptions, descriptions) self.assertEqual(ag.multiUse, set(FighterAceOptions.compData.multiUse)) self.assertEqual(ag.mutuallyExclusive, FighterAceOptions.compData.mutuallyExclusive) optActions = FighterAceOptions.compData.optActions.copy() optActions.update(FighterAceExtendedOptions.compData.optActions) self.assertEqual(ag.optActions, optActions) self.assertEqual(ag.extraActions, FighterAceOptions.compData.extraActions)