# Path: confduino/util.py
# class AutoBunch (Munch):
# 
#     def __getattr__(self, k):
#         '''
#         Bunch is created for missing keys:
# 
#         >>> x=AutoBunch()
#         >>> x.mega.name = 'xy'
#         '''
#         try:
#             return self[k]
#         except KeyError:
#             #            raise AttributeError(k)
#             self[k] = AutoBunch()
#             return self[k]
# 
#     def __setattr__(self, k, v):
#         """Recursive.
# 
#         >>> x=AutoBunch()
#         >>> setattr(x, 'mega.name', 'xy')
# 
#         """
#         k2, _, k3 = k.partition('.')
#         if k3:
#             self.__getattr__(k2).__setattr__(k3, v)
#         else:
#             Munch.__setattr__(self, k, v)
# 
# def bunch2properties(parent, data):
#     lines = []
#     try:
#         for key, value in data.items():
#             # recursive call
#             lines += bunch2properties(parent + '.' + key, value)
#     except AttributeError:
#         lines += [parent + '=' + str(data)]
#     return lines


from confduino.util import AutoBunch, bunch2properties
from nose.tools import eq_
    x = AutoBunch()
    check_keys(x.keys(), [])

    x.a = 3
    check_keys(x.keys(), ['a'])
    eq_(x['a'], 3)
    eq_(x.a, 3)


def test_2():
    x = AutoBunch()
    x.a.b = 3
    check_keys(x.keys(), ['a'])
    eq_(x['a']['b'], 3)
    eq_(x.a.b, 3)
    eq_(x['a'].b, 3)
    eq_(x.a['b'], 3)

    lines = bunch2properties('x', x)


def test_setattr():
    x = AutoBunch()
    setattr(x, 'a.b', 3)
    check_keys(x.keys(), ['a'])
    eq_(x['a']['b'], 3)
    eq_(x.a.b, 3)
    eq_(x['a'].b, 3)
    eq_(x.a['b'], 3)


# Path: confduino/util.py
# class AutoBunch (Munch):
# 
#     def __getattr__(self, k):
#         '''
#         Bunch is created for missing keys:
# 
#         >>> x=AutoBunch()
#         >>> x.mega.name = 'xy'
#         '''
#         try:
#             return self[k]
#         except KeyError:
#             #            raise AttributeError(k)
#             self[k] = AutoBunch()
#             return self[k]
# 
#     def __setattr__(self, k, v):
#         """Recursive.
# 
#         >>> x=AutoBunch()
#         >>> setattr(x, 'mega.name', 'xy')
# 
#         """
#         k2, _, k3 = k.partition('.')
#         if k3:
#             self.__getattr__(k2).__setattr__(k3, v)
#         else:
#             Munch.__setattr__(self, k, v)
# 
# def bunch2properties(parent, data):
#     lines = []
#     try:
#         for key, value in data.items():
#             # recursive call
#             lines += bunch2properties(parent + '.' + key, value)
#     except AttributeError:
#         lines += [parent + '=' + str(data)]
#     return lines


# Path: tests/test_bunch.py
from confduino.util import AutoBunch, bunch2properties
from nose.tools import eq_

    x = AutoBunch()
    check_keys(x.keys(), [])

    x.a = 3
    check_keys(x.keys(), ['a'])
    eq_(x['a'], 3)
    eq_(x.a, 3)


def test_2():
    x = AutoBunch()
    x.a.b = 3
    check_keys(x.keys(), ['a'])
    eq_(x['a']['b'], 3)
    eq_(x.a.b, 3)
    eq_(x['a'].b, 3)
    eq_(x.a['b'], 3)

    lines = bunch2properties('x', x)


def test_setattr():
    x = AutoBunch()
    setattr(x, 'a.b', 3)
    check_keys(x.keys(), ['a'])
    eq_(x['a']['b'], 3)
    eq_(x.a.b, 3)
    eq_(x['a'].b, 3)
    eq_(x.a['b'], 3)


    lines = bunch2properties('x', x)