Skip to content
Snippets Groups Projects
test_build.py 1.49 KiB
Newer Older
Simon Rose's avatar
Simon Rose committed
from re import sub
Simon Rose's avatar
Simon Rose committed
import pytest
Simon Rose's avatar
Simon Rose committed
import subprocess
Simon Rose's avatar
Simon Rose committed
from distutils import dir_util
Simon Rose's avatar
Simon Rose committed
from git import Repo
from pathlib import Path
Simon Rose's avatar
Simon Rose committed
from .utils import *
Simon Rose's avatar
Simon Rose committed


TEST_DATA = Path(__file__).absolute().parent / "data"
Simon Rose's avatar
Simon Rose committed
MODULE_VERSION = "0.0.0+0"

DB_FILE = """record(ai, "TEST") {
    
}
"""

PATCH_FILE = """
diff --git database.db database.db
index 1806ff6..8701832 100644
--- database.db
+++ database.db
@@ -1,3 +1,3 @@
 record(ai, "TEST") {{
-    
+    field(DESC, "{desc}")
 }}
"""
Simon Rose's avatar
Simon Rose committed
@pytest.mark.parametrize(
    "wrapper",
    [{"templates": "database.db", "sources": "", "dbds": "", "headers": ""}],
    indirect=True,
)
def test_patch(wrapper):
Simon Rose's avatar
Simon Rose committed
    db_path = wrapper / TEST_MODULE_NAME / "database.db"
    with open(db_path, "w") as f:
        f.write(DB_FILE)

    patch_path = wrapper / "patch" / "Site" / MODULE_VERSION / "apply.p0.patch"
    patch_path.parent.mkdir(parents=True)
    with open(patch_path, "w") as f:
        f.write(PATCH_FILE.format(desc="OK"))
Simon Rose's avatar
Simon Rose committed
    rc, outs, _ = run_make(
Simon Rose's avatar
Simon Rose committed
        wrapper,
Simon Rose's avatar
Simon Rose committed
        "init",
Simon Rose's avatar
Simon Rose committed
        __DEBUG_VERSION=MODULE_VERSION,
Simon Rose's avatar
Simon Rose committed
    )
Simon Rose's avatar
Simon Rose committed
    assert rc == 0
Simon Rose's avatar
Simon Rose committed
    assert "You are in the local source mode" in outs.decode("utf-8")

    rc, _, _ = run_make(wrapper, "patch", __DEBUG_VERSION=MODULE_VERSION)
Simon Rose's avatar
Simon Rose committed
    assert rc == 0
Simon Rose's avatar
Simon Rose committed
    with open(db_path, "r") as f:
Simon Rose's avatar
Simon Rose committed
        db_contents = f.read()
    assert 'field(DESC, "OK")' in db_contents
    assert not "Bad" in db_contents

    run_make(wrapper, "build", __DEBUG_VERSION=MODULE_VERSION)
    assert any((wrapper / TEST_MODULE_NAME).glob("O.*"))