summaryrefslogtreecommitdiffstats
path: root/tests/test_substitute.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:54:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:58:39 +0000
commit129a1fb4dbc375be0fa926964aa1be46a0cdbbef (patch)
tree04c0088df47415b24a5be1325d3656b8c3881c04 /tests/test_substitute.py
parentInitial commit. (diff)
downloaddebputy-129a1fb4dbc375be0fa926964aa1be46a0cdbbef.tar.xz
debputy-129a1fb4dbc375be0fa926964aa1be46a0cdbbef.zip
Adding upstream version 0.1.21.upstream/0.1.21
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_substitute.py')
-rw-r--r--tests/test_substitute.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_substitute.py b/tests/test_substitute.py
new file mode 100644
index 0000000..a83cc7f
--- /dev/null
+++ b/tests/test_substitute.py
@@ -0,0 +1,66 @@
+import pytest
+
+from debputy.architecture_support import faked_arch_table
+from debputy.dh_migration.models import (
+ DHMigrationSubstitution,
+ AcceptableMigrationIssues,
+ FeatureMigration,
+)
+from debputy.filesystem_scan import FSROOverlay
+from debputy.highlevel_manifest import MutableYAMLManifest
+from debputy.substitution import SubstitutionImpl, VariableContext
+
+MOCK_ENV = {
+ # This conflicts with the dpkg arch table intentionally (to ensure we can tell which one is being resolved)
+ "DEB_HOST_ARCHITECTURE": "i386",
+}
+MOCK_DPKG_ARCH_TABLE = faked_arch_table("amd64", build_arch="i386")
+MOCK_VARIABLE_CONTEXT = VariableContext(FSROOverlay.create_root_dir("debian", "debian"))
+
+
+@pytest.mark.parametrize(
+ "value,expected",
+ [
+ (
+ "unchanged",
+ "unchanged",
+ ),
+ (
+ "unchanged\\{{\n}}",
+ "unchanged\\{{\n}}",
+ ), # Newline is not an allowed part of a substitution
+ (
+ "{{token:DOUBLE_OPEN_CURLY_BRACE}}{{token:NL}}{{token:DOUBLE_CLOSE_CURLY_BRACE}}",
+ "{{\n}}",
+ ),
+ (
+ "{{token:DOUBLE_OPEN_CURLY_BRACE}}token:TAB}}{{token:TAB{{token:DOUBLE_CLOSE_CURLY_BRACE}}",
+ "{{token:TAB}}{{token:TAB}}",
+ ),
+ (
+ "/usr/lib/{{DEB_HOST_MULTIARCH}}",
+ f'/usr/lib/{MOCK_DPKG_ARCH_TABLE["DEB_HOST_MULTIARCH"]}',
+ ),
+ ],
+)
+def test_substitution_match(debputy_plugin_feature_set, value, expected) -> None:
+ subst = SubstitutionImpl(
+ plugin_feature_set=debputy_plugin_feature_set,
+ dpkg_arch_table=MOCK_DPKG_ARCH_TABLE,
+ environment=MOCK_ENV,
+ variable_context=MOCK_VARIABLE_CONTEXT,
+ )
+ replacement = subst.substitute(value, "test def")
+ assert replacement == expected
+
+
+def test_migrate_substitution() -> None:
+ feature_migration = FeatureMigration("test migration")
+ subst = DHMigrationSubstitution(
+ MOCK_DPKG_ARCH_TABLE,
+ AcceptableMigrationIssues(frozenset()),
+ feature_migration,
+ MutableYAMLManifest({}),
+ )
+ replacement = subst.substitute("usr/lib/${DEB_HOST_MULTIARCH}/foo", "test def")
+ assert replacement == "usr/lib/{{DEB_HOST_MULTIARCH}}/foo"