def test_it_correctly_runs_command(self, call_mock): command = Command({'to': 'test', 'hop': 'go'}) context = MagicMock() context.args = ['foo', 'bar'] expected = 'test foo bar' result = command.run(context) call_mock.assert_called_with(expected, shell=True)
def test_it_correctly_runs_command(self, call_mock): command = Command({'to': 'test', 'hop': 'go'}) context = MagicMock() context.args = ['foo', 'bar'] expected = 'test foo bar' try: result = command.run(context) except SystemExit as e: self.assertTrue(isinstance(e.code, MagicMock)) call_mock.assert_called_with(expected, shell=True)
def test_run_command_returns_correct_exit_codes(self): command = Command({'to': 'ls &> /dev/null', 'hop': 'go'}) context = MagicMock() try: command.run(context) except SystemExit as e: self.assertEquals(e.code, 0) context.args = ['foo', 'bar'] try: command.run(context) except SystemExit as e: self.assertNotEquals(e.code, 0)
def test_it_correctly_generates_the_clickObject(self, click_command, pass_context): command = Command({'to': 'foo', 'hop': 'bar'}) test_func = MagicMock() test_func.return_value = 'test_command' pass_context.return_value = 'test_function' click_command.return_value = test_func result = command.setClickObject() self.assertEquals(result, 'test_command') pass_context.assert_called_with(command.run) test_func.assert_called_with('test_function') click_command.assert_called_with( name = command.getName(), help = command.data.get('description'), context_settings = { 'allow_extra_args': True, 'allow_interspersed_args': True, } )
def test_it_returns_the_value_of_self_clickObject(self): data = {'to': 'foo', 'hop': 'bar'} command = Command(data) command.clickObject = 'test' result = command.getClickObject() self.assertEquals(result, 'test')
def test_it_returns_the_correct_name(self): data = {'to': 'foo', 'hop': 'test hopping groups'} command = Command(data) result = command.getName() self.assertEquals(result, 'groups')
def test_it_returns_None_with_no_name_set(self): data = {'to': 'foo', 'hop': None} command = Command(data) result = command.getName() self.assertEquals(result, None)
def test_it_returns_the_correct_group_array(self): data = {'to': 'foo', 'hop': 'test hopping groups'} command = Command(data) result = command.getGroups() self.assertEquals(result, ['test', 'hopping'])
def test_it_returns_empty_an_array_when_groups_not_set(self): data = {'to': 'foo', 'hop': None} command = Command(data) result = command.getGroups() self.assertEquals(result, [])
def test_isValid_fails_when_to_data_None(self): data = {'to': None, 'hop': 'bar'} command = Command(data) self.assertFalse(command.isValid())
def test_isValid_fails_when_hop_data_None(self): data = {'to': 'foo', 'hop': None} command = Command(data) self.assertFalse(command.isValid())
def test_isValid_passes(self): data = {'to': 'foo', 'hop': 'bar'} command = Command(data) self.assertTrue(command.isValid())