test_patches.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: UTF-8 -*-
  2. # Copyright (c) 2020 The ungoogled-chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. from pathlib import Path
  6. import os
  7. import shutil
  8. import pytest
  9. from .. import patches
  10. def test_find_and_check_patch():
  11. assert isinstance(patches.find_and_check_patch(), Path)
  12. with pytest.raises(ValueError):
  13. patches.find_and_check_patch(patch_bin_path=Path('/this/should/not/exist'))
  14. with pytest.raises(RuntimeError):
  15. # Use comamnd "false" to return non-zero exit code
  16. patches.find_and_check_patch(patch_bin_path=Path('/bin/false'))
  17. def test_patch_from_which():
  18. # We assume GNU patch is already installed to PATH
  19. assert patches._find_patch_from_which()
  20. def test_patch_from_env():
  21. os.environ['PATCH_BIN'] = 'patch'
  22. assert patches._find_patch_from_env() == Path(shutil.which('patch'))
  23. os.environ['PATCH_BIN'] = shutil.which('patch')
  24. assert patches._find_patch_from_env() == Path(shutil.which('patch'))
  25. del os.environ['PATCH_BIN']
  26. assert patches._find_patch_from_env() is None