aboutsummaryrefslogtreecommitdiff
path: root/tools/patman/test_settings.py
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-12-20 00:38:41 -0500
committerSimon Glass <sjg@chromium.org>2023-01-05 19:21:57 -0700
commit8f8d3f72f28732bff0dc6362a18e3ec55fba2ac1 (patch)
treec394a22cfbba42891732f9d27f94428164da53a4 /tools/patman/test_settings.py
parentdb16edd8ced27c06c075999ef95c6a1a57db98e0 (diff)
patman: additionally honor a local .patman config file
This enables versioning a project specific patman configuration file. It also makes it possible to declare the project name, which is not a useful thing to do in $HOME/.patman. A new test is added, along updated documentation. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/test_settings.py')
-rw-r--r--tools/patman/test_settings.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/patman/test_settings.py b/tools/patman/test_settings.py
new file mode 100644
index 0000000000..c768a2fc64
--- /dev/null
+++ b/tools/patman/test_settings.py
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2022 Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
+#
+
+import argparse
+import contextlib
+import os
+import sys
+import tempfile
+
+from patman import settings
+from patman import tools
+
+
+@contextlib.contextmanager
+def empty_git_repository():
+ with tempfile.TemporaryDirectory() as tmpdir:
+ os.chdir(tmpdir)
+ tools.run('git', 'init', raise_on_error=True)
+ yield tmpdir
+
+
+@contextlib.contextmanager
+def cleared_command_line_args():
+ old_value = sys.argv[:]
+ sys.argv = [sys.argv[0]]
+ try:
+ yield
+ finally:
+ sys.argv = old_value
+
+
+def test_git_local_config():
+ # Clearing the command line arguments is required, otherwise
+ # arguments passed to the test running such as in 'pytest -k
+ # filter' would be processed by _UpdateDefaults and fail.
+ with cleared_command_line_args():
+ with empty_git_repository():
+ with tempfile.NamedTemporaryFile() as global_config:
+ global_config.write(b'[settings]\n'
+ b'project=u-boot\n')
+ global_config.flush()
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-p', '--project', default='unknown')
+ subparsers = parser.add_subparsers(dest='cmd')
+ send = subparsers.add_parser('send')
+ send.add_argument('--no-check', action='store_false',
+ dest='check_patch', default=True)
+
+ # Test "global" config is used.
+ settings.Setup(parser, 'unknown', global_config.name)
+ args, _ = parser.parse_known_args([])
+ assert args.project == 'u-boot'
+ send_args, _ = send.parse_known_args([])
+ assert send_args.check_patch
+
+ # Test local config can shadow it.
+ with open('.patman', 'w', buffering=1) as f:
+ f.write('[settings]\n'
+ 'project: guix-patches\n'
+ 'check_patch: False\n')
+ settings.Setup(parser, 'unknown', global_config.name)
+ args, _ = parser.parse_known_args([])
+ assert args.project == 'guix-patches'
+ send_args, _ = send.parse_known_args([])
+ assert not send_args.check_patch