# Path: tests/base.py
# class BaseTestCase(unittest.TestCase):
#     maxDiff = None
# 
#     def setUp(self):
#         self.client = MagicMock()
#         self.cluster = Cluster(self.client, compiler=Compiler_5_0)
#         self.index = Index(self.cluster, 'test')
# 
#     def assert_expression(self, expr, expected, compiler=None):
#         compiler = compiler or Compiler_5_0
#         self.assertEqual(expr.to_dict(compiler=compiler), expected)
# 
# Path: elasticmagic/util.py
# def merge_params(params, args, kwargs):
#     assert isinstance(args, Iterable), args
#     assert isinstance(kwargs, Mapping), kwargs
#     new = dict()
#     for a in args:
#         new.update(a)
#     new.update(kwargs)
#     return type(params)(params, **new)
# 
# Path: elasticmagic/expression.py
# class Params(Expression, Mapping):
#     __visit_name__ = 'params'
# 
#     def __init__(self, *args, **kwargs):
#         params = {}
#         for d in args:
#             params.update(d)
#         params.update(kwargs)
#         self._params = {}
#         for k, v in clean_params(params).items():
#             if k.endswith('_') and not k.startswith('_'):
#                 k = k.rstrip('_')
#             self._params[k] = v
# 
#     def _collect_doc_classes(self):
#         return collect_doc_classes(self._params)
# 
#     def __len__(self):
#         return len(self._params)
# 
#     def __iter__(self):
#         return iter(self._params)
# 
#     def __getitem__(self, key):
#         return self._params[key]
# 
#     def __contains__(self, key):
#         return key in self._params


from .base import BaseTestCase
from elasticmagic.util import merge_params
from elasticmagic.expression import Params



class UtilsTest(BaseTestCase):

    def test_merge_params(self):
        original = Params()
        self.assertEqual(tuple(original.items()), ())

        p = merge_params(original, (), {})
        self.assertEqual(original, p)
        self.assertIsNot(original, p)

        p = merge_params(original, ({'key': 'value'},), {})
        self.assertEqual(tuple(p.items()), (('key', 'value'),))
        self.assertNotEqual(original, p)
        self.assertIsNot(original, p)


# Path: tests/base.py
# class BaseTestCase(unittest.TestCase):
#     maxDiff = None
# 
#     def setUp(self):
#         self.client = MagicMock()
#         self.cluster = Cluster(self.client, compiler=Compiler_5_0)
#         self.index = Index(self.cluster, 'test')
# 
#     def assert_expression(self, expr, expected, compiler=None):
#         compiler = compiler or Compiler_5_0
#         self.assertEqual(expr.to_dict(compiler=compiler), expected)
# 
# Path: elasticmagic/util.py
# def merge_params(params, args, kwargs):
#     assert isinstance(args, Iterable), args
#     assert isinstance(kwargs, Mapping), kwargs
#     new = dict()
#     for a in args:
#         new.update(a)
#     new.update(kwargs)
#     return type(params)(params, **new)
# 
# Path: elasticmagic/expression.py
# class Params(Expression, Mapping):
#     __visit_name__ = 'params'
# 
#     def __init__(self, *args, **kwargs):
#         params = {}
#         for d in args:
#             params.update(d)
#         params.update(kwargs)
#         self._params = {}
#         for k, v in clean_params(params).items():
#             if k.endswith('_') and not k.startswith('_'):
#                 k = k.rstrip('_')
#             self._params[k] = v
# 
#     def _collect_doc_classes(self):
#         return collect_doc_classes(self._params)
# 
#     def __len__(self):
#         return len(self._params)
# 
#     def __iter__(self):
#         return iter(self._params)
# 
#     def __getitem__(self, key):
#         return self._params[key]
# 
#     def __contains__(self, key):
#         return key in self._params


# Path: tests/test_utils.py
from .base import BaseTestCase
from elasticmagic.util import merge_params
from elasticmagic.expression import Params




class UtilsTest(BaseTestCase):

    def test_merge_params(self):
        original = Params()
        self.assertEqual(tuple(original.items()), ())

        p = merge_params(original, (), {})
        self.assertEqual(original, p)
        self.assertIsNot(original, p)

        p = merge_params(original, ({'key': 'value'},), {})
        self.assertEqual(tuple(p.items()), (('key', 'value'),))
        self.assertNotEqual(original, p)
        self.assertIsNot(original, p)


        p = merge_params(original, (), dict(key='value'))