# Path: mcm/datastructures.py
# class CmdPathRow(dict):
# 
# 
#     def __str__(self):
#         bool_map = {True:'yes', False:'no', None:'""', '':'""'}
#         return ' '.join('{}={}'.format(key, bool_map.get(value, value)) for key, value in self.items())
# 
# 
#     def __hash__(self):
#         return hash(tuple(self.items()))
# 
# 
#     def __sub__(self, other):
#         '''Return new instance with key,valie pairs from self not listed in other.'''
# 
#         diff = dict(set(self.items()) - set(other.items()))
#         return CmdPathRow( diff )
# 
# 
#     def isunique(self, other, keys):
#         '''Test whether every key,value pair (from keys) is in other.'''
# 
#         pairs = set( (key,self[key]) for key in keys )
#         return pairs <= set(other.items())
# 
# def make_cmdpath(path, strategy):
#     attrs = dict()
#     attrs['absolute'] = pjoin('/', path ).rstrip('/')
#     attrs['strategy'] = strategy
#     path_attrs = MENU_PATHS[path]
#     attrs['keys'] = path_attrs['keys']
#     attrs['type'] = path_attrs['type']
#     attrs['modord'] = path_attrs['modord']
# 
#     return CmdPath(**attrs)


from mock import patch
from mcm.datastructures import CmdPathRow, make_cmdpath
import pytest

    def test_strategy_attribute_is_the_same_as_passed_in_function_call(self, paths_mock):
        cmd_path = make_cmdpath('/ip/address', strategy='exact')
        assert cmd_path.strategy == 'exact'

    def test_calls_getitem_on_paths_data_structure(self, paths_mock):
        make_cmdpath('/ip/address', strategy='exact')
        paths_mock.__getitem__.assert_called_once_with('/ip/address')

    def test_calling_getitem_on_paths_data_structure_riases_KeyError_when_path_is_missing(self, paths_mock):
        paths_mock.__getitem__.side_effect = KeyError
        with pytest.raises(KeyError):
            make_cmdpath('/ip/address', 'exact')


@pytest.mark.parametrize("data,expected", (
    ( {'enabled':True}, 'enabled=yes' ),
    ( {'enabled':False}, 'enabled=no' ),
    ( {'servers':None}, 'servers=""' ),
    ( {'servers':''}, 'servers=""' ),
    ))
def test_CmdPathRow_str(data, expected):
    assert str(CmdPathRow(data)) == expected


def test_sub_returns_CmdPathRow_instance():
    assert isinstance((CmdPathRow() - CmdPathRow()), CmdPathRow )


@pytest.mark.parametrize("wanted,present,expected",(

# Path: mcm/datastructures.py
# class CmdPathRow(dict):
# 
# 
#     def __str__(self):
#         bool_map = {True:'yes', False:'no', None:'""', '':'""'}
#         return ' '.join('{}={}'.format(key, bool_map.get(value, value)) for key, value in self.items())
# 
# 
#     def __hash__(self):
#         return hash(tuple(self.items()))
# 
# 
#     def __sub__(self, other):
#         '''Return new instance with key,valie pairs from self not listed in other.'''
# 
#         diff = dict(set(self.items()) - set(other.items()))
#         return CmdPathRow( diff )
# 
# 
#     def isunique(self, other, keys):
#         '''Test whether every key,value pair (from keys) is in other.'''
# 
#         pairs = set( (key,self[key]) for key in keys )
#         return pairs <= set(other.items())
# 
# def make_cmdpath(path, strategy):
#     attrs = dict()
#     attrs['absolute'] = pjoin('/', path ).rstrip('/')
#     attrs['strategy'] = strategy
#     path_attrs = MENU_PATHS[path]
#     attrs['keys'] = path_attrs['keys']
#     attrs['type'] = path_attrs['type']
#     attrs['modord'] = path_attrs['modord']
# 
#     return CmdPath(**attrs)


# Path: tests/test_datastructures.py
from mock import patch
from mcm.datastructures import CmdPathRow, make_cmdpath
import pytest


    def test_strategy_attribute_is_the_same_as_passed_in_function_call(self, paths_mock):
        cmd_path = make_cmdpath('/ip/address', strategy='exact')
        assert cmd_path.strategy == 'exact'

    def test_calls_getitem_on_paths_data_structure(self, paths_mock):
        make_cmdpath('/ip/address', strategy='exact')
        paths_mock.__getitem__.assert_called_once_with('/ip/address')

    def test_calling_getitem_on_paths_data_structure_riases_KeyError_when_path_is_missing(self, paths_mock):
        paths_mock.__getitem__.side_effect = KeyError
        with pytest.raises(KeyError):
            make_cmdpath('/ip/address', 'exact')


@pytest.mark.parametrize("data,expected", (
    ( {'enabled':True}, 'enabled=yes' ),
    ( {'enabled':False}, 'enabled=no' ),
    ( {'servers':None}, 'servers=""' ),
    ( {'servers':''}, 'servers=""' ),
    ))
def test_CmdPathRow_str(data, expected):
    assert str(CmdPathRow(data)) == expected


def test_sub_returns_CmdPathRow_instance():
    assert isinstance((CmdPathRow() - CmdPathRow()), CmdPathRow )


@pytest.mark.parametrize("wanted,present,expected",(

    (CmdPathRow(interface='ether1', disabled=False), CmdPathRow(interface='ether1', disabled=False), CmdPathRow()),