def test_ClangFormat_ClangTimeout(mocker): """Test that ClangTimeout is raised if clang-format returns with SIGKILL.""" mock_Popen = mocker.patch("subprocess.Popen") mock_Popen.return_value = MockProcess(9) with test.Raises(errors.ClangTimeout): clang.ClangFormat("", ".cpp") # ClangTimeout inherits from ClangException. with test.Raises(errors.ClangException): clang.ClangFormat("", ".cpp")
def test_ClangFormat_process_command(mocker): """Test the clang-format comand which is run.""" mock_Popen = mocker.patch("subprocess.Popen") mock_Popen.return_value = MockProcess(0) clang.ClangFormat("", ".cpp") subprocess.Popen.assert_called_once() cmd = subprocess.Popen.call_args_list[0][0][0] assert cmd[:3] == ["timeout", "-s9", "60"]
def test_ClangFormat_process_command(mocker): """Test the clang-format comand which is run.""" mock_Popen = mocker.patch('subprocess.Popen') mock_Popen.return_value = MockProcess(0) clang.ClangFormat('', '.cpp') subprocess.Popen.assert_called_once() cmd = subprocess.Popen.call_args_list[0][0][0] assert cmd[:3] == ['timeout', '-s9', '60']
def ClangFormat(text: str) -> str: """Run clang-format on a source to enforce code style. Args: text: The source code to run through clang-format. Returns: The output of clang-format. Raises: ClangFormatException: In case of an error. ClangTimeout: If clang-format does not complete before timeout_seconds. """ return clang.ClangFormat(text, '.java')
def test_ClangFormat_empty_file(): """Test the preprocessor output with an empty file.""" assert clang.ClangFormat("", ".cpp") == ""
def test_ClangFormat_ClangException(mocker): """Test that ClangException is raised if clang-format returns non-zero.""" mock_Popen = mocker.patch("subprocess.Popen") mock_Popen.return_value = MockProcess(1) with test.Raises(errors.ClangFormatException): clang.ClangFormat("", ".cpp")
def test_ClangFormat_empty_file(): """Test the preprocessor output with an empty file.""" assert clang.ClangFormat('', '.cpp') == ''