aboutsummaryrefslogtreecommitdiff
path: root/tests/helpers.py
blob: f64be061103c1e2bd1913f688b212ccf7a6b825c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ############################################################################ #
#                                                                              #
#                                                         :::      ::::::::    #
#    helpers.py                                         :+:      :+:    :+:    #
#                                                     +:+ +:+         +:+      #
#    By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+         #
#                                                 +#+#+#+#+#+   +#+            #
#    Created: 2021/03/02 14:37:38 by cacharle          #+#    #+#              #
#    Updated: 2021/03/02 17:45:28 by cacharle         ###   ########.fr        #
#                                                                              #
# ############################################################################ #

import contextlib

from minishell_test.config import Config


@contextlib.contextmanager
def config_context(**kwargs):
    prevs = {attr: getattr(Config, attr) for attr in kwargs.keys()}
    for attr, value in kwargs.items():
        setattr(Config, attr, value)
    try:
        yield
    finally:
        for attr, value in prevs.items():
            setattr(Config, attr, value)