def test_set_get_definition(self): """ Command.get/set_definition properly sets and gets definition """ command = SomeCommand() definition = InputDefinition() ret = command.set_definition(definition) self.assertEqual(command, ret, msg='.set_definition() implements a fluent interface') self.assertEqual(definition, command.get_definition(), msg='.set_definition() sets the current InputDefinition instance') command.set_definition([InputArgument('foo'), InputOption('bar')]) self.assertTrue(command.get_definition().has_argument('foo'), msg='.set_definition() also takes an array of InputArguments and InputOptions as an argument') self.assertTrue(command.get_definition().has_option('bar'), msg='.set_definition() also takes an array of InputArguments and InputOptions as an argument') command.set_definition(InputDefinition())
def test_merge_application_definition(self): """ Command.merge_application_definition() merges command and application. """ application1 = Application() application1.get_definition().add_arguments([InputArgument('foo')]) application1.get_definition().add_options([InputOption('bar')]) command = SomeCommand() command.set_application(application1) command.set_definition( InputDefinition([ InputArgument('bar'), InputOption('foo') ]) ) command.merge_application_definition() self.assertTrue(command.get_definition().has_argument('foo')) self.assertTrue(command.get_definition().has_option('foo')) self.assertTrue(command.get_definition().has_argument('bar')) self.assertTrue(command.get_definition().has_option('bar')) # It should not merge the definitions twice command.merge_application_definition() self.assertEqual(3, command.get_definition().get_argument_count())
def test_merge_application_definition_without_args_then_with_args_adds_args(self): application1 = Application() application1.get_definition().add_arguments([InputArgument('foo')]) application1.get_definition().add_options([InputOption('bar')]) command = SomeCommand() command.set_application(application1) command.set_definition(InputDefinition()) command.merge_application_definition(False) self.assertFalse(command.get_definition().has_argument('foo')) self.assertTrue(command.get_definition().has_option('bar')) command.merge_application_definition(True) self.assertTrue(command.get_definition().has_argument('foo')) # It should not merge the definitions twice command.merge_application_definition() self.assertEqual(2, command.get_definition().get_argument_count())