# -*- coding: utf-8 -*-
from functools import wraps

from .core import settings


class settings_stub(object):
    """
    A simple context manager (and decorator) class useful
    in tests which is necessary to change some
    setting in the safe way
    """

    def __init__(self, **kwargs):
        self.new_settings = kwargs
        self.old_settings = {}

    def __call__(self, func):
        @wraps(func)
        def inner(*args, **kwargs):
            with self:
                return func(*args, **kwargs)
        return inner

    def __enter__(self):
        for key, value in self.new_settings.items():
            if not hasattr(settings, key):
                raise ValueError(
                    'Your current settings do not '
                    'have a setting {}'.format(key)
                )
            self.old_settings[key] = getattr(settings, key)
            setattr(settings, key, value)

    def __exit__(self, ext_type, exc_value, traceback):
        for key, value in self.old_settings.items():
            setattr(settings, key, value)

@@ -629,28 +629,27 @@
  if 
-not hasattr(
+key not in 
 settings
 , ke
@@ -644,22 +644,22 @@
 settings
-, key)
+._dict
 :%0A      
@@ -849,24 +849,16 @@
 %5D = 
-getattr(
 settings
 , ke
@@ -857,14 +857,19 @@
 ings
-, key)
+._dict%5Bkey%5D
 %0A   
@@ -884,34 +884,32 @@
  set
-attr(settings, key,
+tings._dict%5Bkey%5D =
  value
-)
 %0A%0A  
@@ -1034,31 +1034,29 @@
  set
-attr(settings, key,
+tings._dict%5Bkey%5D =
  value
-)
 %0A

change settings stub to working with settings._dict instead setattr and getattr