Test setting, getting, and unsetting config values WARNING: This test will modify and completely remove a config section 'foo', both in the repo created in setUp() and in the user's global .gitconfig.
(self)
| 347 | |
| 348 | @pytest.mark.slow_test |
| 349 | def test_config(self): |
| 350 | """ |
| 351 | Test setting, getting, and unsetting config values |
| 352 | |
| 353 | WARNING: This test will modify and completely remove a config section |
| 354 | 'foo', both in the repo created in setUp() and in the user's global |
| 355 | .gitconfig. |
| 356 | """ |
| 357 | |
| 358 | def _clear_config(): |
| 359 | cmds = ( |
| 360 | ["git", "config", "--remove-section", "foo"], |
| 361 | ["git", "config", "--global", "--remove-section", "foo"], |
| 362 | ) |
| 363 | for cmd in cmds: |
| 364 | with salt.utils.files.fopen(os.devnull, "w") as devnull: |
| 365 | try: |
| 366 | subprocess.check_call(cmd, stderr=devnull) |
| 367 | except subprocess.CalledProcessError: |
| 368 | pass |
| 369 | |
| 370 | cfg_local = {"foo.single": ["foo"], "foo.multi": ["foo", "bar", "baz"]} |
| 371 | cfg_global = {"foo.single": ["abc"], "foo.multi": ["abc", "def", "ghi"]} |
| 372 | _clear_config() |
| 373 | try: |
| 374 | log.debug("Try to specify both single and multivar (should raise error)") |
| 375 | self.assertTrue( |
| 376 | "Only one of 'value' and 'multivar' is permitted" |
| 377 | in self.run_function( |
| 378 | "git.config_set", |
| 379 | ["foo.single"], |
| 380 | value=cfg_local["foo.single"][0], |
| 381 | multivar=cfg_local["foo.multi"], |
| 382 | cwd=self.repo, |
| 383 | ) |
| 384 | ) |
| 385 | log.debug("Try to set single local value without cwd (should raise error)") |
| 386 | self.assertTrue( |
| 387 | "'cwd' argument required unless global=True" |
| 388 | in self.run_function( |
| 389 | "git.config_set", |
| 390 | ["foo.single"], |
| 391 | value=cfg_local["foo.single"][0], |
| 392 | ) |
| 393 | ) |
| 394 | log.debug("Set single local value") |
| 395 | self.assertEqual( |
| 396 | self.run_function( |
| 397 | "git.config_set", |
| 398 | ["foo.single"], |
| 399 | value=cfg_local["foo.single"][0], |
| 400 | cwd=self.repo, |
| 401 | ), |
| 402 | cfg_local["foo.single"], |
| 403 | ) |
| 404 | log.debug("Set single global value") |
| 405 | self.assertEqual( |
| 406 | self.run_function( |
nothing calls this directly
no test coverage detected