34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
import unittest
|
|
from pathlib import Path
|
|
import build
|
|
import tempfile
|
|
import subprocess
|
|
from unittest.mock import patch
|
|
|
|
|
|
class BuildContract(unittest.TestCase):
|
|
def test_real_git_source_rejects_wrong_revision_and_dirty_checkout(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
source = Path(directory)
|
|
def git(*args):
|
|
return subprocess.check_output(["git", "-C", str(source), *args], stderr=subprocess.STDOUT).decode().strip()
|
|
git("init", "--quiet")
|
|
(source / "source.txt").write_text("fixture")
|
|
git("add", "source.txt")
|
|
git("-c", "user.name=karl", "-c", "user.email=fixture@invalid", "commit", "--quiet", "-m", "fixture")
|
|
with self.assertRaises(ValueError):
|
|
build.validate_source(source)
|
|
with patch.object(build, "UPSTREAM", git("rev-parse", "HEAD")):
|
|
build.validate_source(source)
|
|
(source / "source.txt").write_text("changed")
|
|
with self.assertRaises(ValueError):
|
|
build.validate_source(source)
|
|
|
|
def test_shared_helpers_load_without_running_build_or_downloading(self):
|
|
self.assertTrue(callable(build.shared_helper("build_runtime.py").bundle_windows_crt))
|
|
self.assertTrue(callable(build.shared_helper("provision_vulkan.py").provision))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|