Пример #1
0
 def setUp(self):
     self.files = FileCreator()
     self.alias_file = self.files.create_file('alias', '[toplevel]\n')
     self.alias_loader = AliasLoader(self.alias_file)
     self.session = mock.Mock(spec=Session)
     self.alias_cmd_injector = AliasCommandInjector(self.session,
                                                    self.alias_loader)
     self.command_table = {}
     self.parser = MainArgParser(command_table=self.command_table,
                                 version_string='version',
                                 description='description',
                                 argument_table={})
Пример #2
0
class TestAliasCommandInjector(unittest.TestCase):
    def setUp(self):
        self.files = FileCreator()
        self.alias_file = self.files.create_file("alias", "[toplevel]\n")
        self.alias_loader = AliasLoader(self.alias_file)
        self.session = mock.Mock(spec=Session)
        self.alias_cmd_injector = AliasCommandInjector(self.session, self.alias_loader)
        self.command_table = {}
        self.parser = MainArgParser(
            command_table=self.command_table, version_string="version", description="description", argument_table={}
        )

    def tearDown(self):
        self.files.remove_all()

    def test_service_alias_command(self):
        with open(self.alias_file, "a+") as f:
            f.write("my-alias = my-alias-value\n")

        self.alias_cmd_injector.inject_aliases(self.command_table, self.parser)
        self.assertIn("my-alias", self.command_table)
        self.assertIsInstance(self.command_table["my-alias"], ServiceAliasCommand)

    def test_external_alias_command(self):
        with open(self.alias_file, "a+") as f:
            f.write("my-alias = !my-alias-value\n")

        self.alias_cmd_injector.inject_aliases(self.command_table, self.parser)
        self.assertIn("my-alias", self.command_table)
        self.assertIsInstance(self.command_table["my-alias"], ExternalAliasCommand)

    def test_clobbers_builtins(self):
        builtin_cmd = mock.Mock(spec=CLICommand)
        self.command_table["builtin"] = builtin_cmd

        with open(self.alias_file, "a+") as f:
            f.write("builtin = my-alias-value\n")

        self.alias_cmd_injector.inject_aliases(self.command_table, self.parser)
        self.assertIn("builtin", self.command_table)
        self.assertIsInstance(self.command_table["builtin"], ServiceAliasCommand)

    def test_shadow_proxy_command(self):
        builtin_cmd = mock.Mock(spec=CLICommand)
        builtin_cmd.name = "builtin"
        self.command_table["builtin"] = builtin_cmd

        with open(self.alias_file, "a+") as f:
            f.write("builtin = builtin\n")

        self.alias_cmd_injector.inject_aliases(self.command_table, self.parser)

        self.command_table["builtin"]([], FakeParsedArgs(command="builtin"))
        # The builtin command should be passed to the alias
        # command when added to the table.
        builtin_cmd.assert_called_with([], FakeParsedArgs(command="builtin"))
Пример #3
0
 def setUp(self):
     self.files = FileCreator()
     self.alias_file = self.files.create_file("alias", "[toplevel]\n")
     self.alias_loader = AliasLoader(self.alias_file)
     self.session = mock.Mock(spec=Session)
     self.alias_cmd_injector = AliasCommandInjector(self.session, self.alias_loader)
     self.command_table = {}
     self.parser = MainArgParser(
         command_table=self.command_table, version_string="version", description="description", argument_table={}
     )
 def _add_aliases(self, command_table, parser):
     parser = self._create_parser(command_table)
     injector = AliasCommandInjector(self.session, self.alias_loader)
     injector.inject_aliases(command_table, parser)
Пример #5
0
 def _add_aliases(self, command_table, parser):
     parser = self._create_parser(command_table)
     injector = AliasCommandInjector(
         self.session, self.alias_loader)
     injector.inject_aliases(command_table, parser)
Пример #6
0
class TestAliasCommandInjector(unittest.TestCase):
    def setUp(self):
        self.files = FileCreator()
        self.alias_file = self.files.create_file('alias', '[toplevel]\n')
        self.alias_loader = AliasLoader(self.alias_file)
        self.session = mock.Mock(spec=Session)
        self.alias_cmd_injector = AliasCommandInjector(self.session,
                                                       self.alias_loader)
        self.command_table = {}
        self.parser = MainArgParser(command_table=self.command_table,
                                    version_string='version',
                                    description='description',
                                    argument_table={})

    def tearDown(self):
        self.files.remove_all()

    def test_service_alias_command(self):
        with open(self.alias_file, 'a+') as f:
            f.write('my-alias = my-alias-value\n')

        self.alias_cmd_injector.inject_aliases(self.command_table, self.parser)
        self.assertIn('my-alias', self.command_table)
        self.assertIsInstance(self.command_table['my-alias'],
                              ServiceAliasCommand)

    def test_external_alias_command(self):
        with open(self.alias_file, 'a+') as f:
            f.write('my-alias = !my-alias-value\n')

        self.alias_cmd_injector.inject_aliases(self.command_table, self.parser)
        self.assertIn('my-alias', self.command_table)
        self.assertIsInstance(self.command_table['my-alias'],
                              ExternalAliasCommand)

    def test_clobbers_builtins(self):
        builtin_cmd = mock.Mock(spec=CLICommand)
        self.command_table['builtin'] = builtin_cmd

        with open(self.alias_file, 'a+') as f:
            f.write('builtin = my-alias-value\n')

        self.alias_cmd_injector.inject_aliases(self.command_table, self.parser)
        self.assertIn('builtin', self.command_table)
        self.assertIsInstance(self.command_table['builtin'],
                              ServiceAliasCommand)

    def test_shadow_proxy_command(self):
        builtin_cmd = mock.Mock(spec=CLICommand)
        builtin_cmd.name = 'builtin'
        self.command_table['builtin'] = builtin_cmd

        with open(self.alias_file, 'a+') as f:
            f.write('builtin = builtin\n')

        self.alias_cmd_injector.inject_aliases(self.command_table, self.parser)

        self.command_table['builtin']([], FakeParsedArgs(command='builtin'))
        # The builtin command should be passed to the alias
        # command when added to the table.
        builtin_cmd.assert_called_with([], FakeParsedArgs(command='builtin'))