Skip to content

Commit

Permalink
Merge pull request #1148 from kyleknap/lineage-names
Browse files Browse the repository at this point in the history
Add ``lineage_names`` to commands
  • Loading branch information
kyleknap committed Feb 18, 2015
2 parents f332ca2 + 9e40bfb commit b9c2900
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
10 changes: 10 additions & 0 deletions awscli/clidriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def lineage(self):
# a list.
return [self]

@property
def lineage_names(self):
# Represents the lineage of a command in terms of command ``name``
return [cmd.name for cmd in self.lineage]

def __call__(self, args, parsed_globals):
"""Invoke CLI operation.
Expand Down Expand Up @@ -474,6 +479,11 @@ def lineage(self):
def lineage(self, value):
self._lineage = value

@property
def lineage_names(self):
# Represents the lineage of a command in terms of command ``name``
return [cmd.name for cmd in self.lineage]

@property
def arg_table(self):
if self._arg_table is None:
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,14 @@ def assert_lineage_names(self, ref_lineage_names):
actual_lineage_names = []
for cmd in command.lineage:
actual_lineage_names.append(cmd.name)


# Assert the actual names of each command in a lineage is as expected.
self.assertEqual(actual_lineage_names, ref_lineage_names)

# Assert that ``lineage_names`` for each command is in sync with what
# is actually in the command's ``lineage``.
self.assertEqual(command.lineage_names, actual_lineage_names)

def test_service_level_commands(self):
# Check a normal unchanged service command
self.assert_lineage_names(['ec2'])
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/customizations/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_load_subcommand_table_property(self):

def test_load_lineage(self):
self.assertEqual(self.command.lineage, [self.command])
self.assertEqual(self.command.lineage_names, [self.command.name])

def test_pass_lineage_to_child_command(self):
class MockCustomCommand(BasicCommand):
Expand All @@ -66,7 +67,12 @@ class MockCustomCommand(BasicCommand):
SUBCOMMANDS = [{'name': 'basic', 'command_class': BasicCommand}]

self.command = MockCustomCommand(self.session)
lineage = self.command.subcommand_table['basic'].lineage
subcommand = self.command.subcommand_table['basic']
lineage = subcommand.lineage
self.assertEqual(len(lineage), 2)
self.assertEqual(lineage[0], self.command)
self.assertIsInstance(lineage[1], BasicCommand)
self.assertEqual(
subcommand.lineage_names,
[self.command.name, subcommand.name]
)
21 changes: 17 additions & 4 deletions tests/unit/test_clidriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@ def test_name(self):
def test_lineage(self):
self.assertEqual(self.cmd.lineage, [self.cmd])

def test_lineage_names(self):
with self.assertRaises(NotImplementedError):
self.cmd.lineage_names

def test_arg_table(self):
self.assertEqual(self.cmd.arg_table, {})

Expand All @@ -744,9 +748,13 @@ def test_name(self):
self.assertEqual(self.cmd.name, 'bar')

def test_lineage(self):
cmd = CLICommand()
self.assertEqual(self.cmd.lineage, [self.cmd])
self.cmd.lineage = ['foo']
self.assertEqual(self.cmd.lineage, ['foo'])
self.cmd.lineage = [cmd]
self.assertEqual(self.cmd.lineage, [cmd])

def test_lineage_names(self):
self.assertEqual(self.cmd.lineage_names, ['foo'])

def test_pass_lineage_to_child(self):
# In order to introspect the service command's subcommands
Expand All @@ -756,6 +764,7 @@ def test_pass_lineage_to_child(self):
child_cmd = help_command.command_table['list-objects']
self.assertEqual(child_cmd.lineage,
[self.cmd, child_cmd])
self.assertEqual(child_cmd.lineage_names, ['foo', 'list-objects'])


class TestServiceOperation(unittest.TestCase):
Expand All @@ -769,9 +778,13 @@ def test_name(self):
self.assertEqual(self.cmd.name, 'bar')

def test_lineage(self):
cmd = CLICommand()
self.assertEqual(self.cmd.lineage, [self.cmd])
self.cmd.lineage = ['foo']
self.assertEqual(self.cmd.lineage, ['foo'])
self.cmd.lineage = [cmd]
self.assertEqual(self.cmd.lineage, [cmd])

def test_lineage_names(self):
self.assertEqual(self.cmd.lineage_names, ['foo'])


if __name__ == '__main__':
Expand Down

0 comments on commit b9c2900

Please sign in to comment.