def test_skipped_handling(self): self.mock_handler = mock.NonCallableMock() self.mock_readline.side_effect = ["1", "2", "3"] self.mock_wait.return_value = 1 with self.assertRaises(errors.HighlandError): utils.execute_command('command', self.mock_handler) assert self.mock_handler.called is False
def test_logged_output(self): self.mock_readline.side_effect = ["1", "2", "3"] utils.execute_command('command', self.mock_handler) assert self.mock_public_log.info.call_args_list == [ mock.call("1"), mock.call("2"), mock.call("3") ]
def test_error_message_for_missing_shbang(self): def side_effect(*args, **kwargs): oerr = OSError() oerr.errno = errno.ENOEXEC raise oerr self.mock_popen.side_effect = side_effect with self.assertRaises(errors.HighlandError) as herr: utils.execute_command('./path/to/command', self.mock_handler) self.mock_popen.assert_called_with('./path/to/command', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1) expected_msg = "Could not execute hook at './path/to/command'. Is it missing a #! line?" self.assertEqual(herr.exception.args[0], expected_msg)
def clone(source_type, source_url, source_branch, commit=None, private_key=None): """ Clone the source of the build context and set it as the working directory """ private_log.info("Starting to clone") if private_key: write_private_key(private_key) clone_commands = get_clone_commands(source_type, source_url, source_branch, commit) for clone_command in clone_commands: utils.execute_command(clone_command, convert_clone_error) if source_type == 'git': export_git_details() del os.environ['SOURCE_URL']
def test_error_handling(self): self.mock_readline.side_effect = ["1", "2", "3"] self.mock_wait.return_value = 1 with self.assertRaises(errors.HighlandError): utils.execute_command('command', self.mock_handler) self.mock_handler.assert_called_with("123")
def test_popen_args(self): utils.execute_command('command', self.mock_handler) self.mock_popen.assert_called_with('command', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1)
def run(name): hook_path = os.path.join('hooks', name) if os.path.isfile(hook_path): public_log.info('Executing {} hook...'.format(name)) utils.execute_command(hook_path, '{} hook failed!'.format(name)) return True
def remove_test_stack(test_path, build_code): cmd = [ 'docker-compose', '-f', test_path, '-p', build_code, 'rm', '--force', '-v' ] utils.execute_command(cmd)
def boot_test_stack(test_path, build_code): cmd = [ 'docker-compose', '-f', test_path, '-p', build_code, 'up', '-d', 'sut' ] msg = 'starting "sut" service in {}'.format(test_path) utils.execute_command(cmd, msg)
def build_test_stack(test_path, build_code): cmd = ['docker-compose', '-f', test_path, '-p', build_code, 'build'] msg = 'building {}'.format(test_path) utils.execute_command(cmd, msg)