import pytest
import asyncio.coroutines
import asyncio
from unittest.mock import MagicMock
import uuid

import gosmart
gosmart.setup(False)
import gosmart.status
import gosmart.parameters

known_guid = str(uuid.uuid4()).upper()
unknown_guid = str(uuid.uuid4()).upper()


def magic_coro():
    mock = MagicMock()
    return mock, asyncio.coroutine(mock)


@asyncio.coroutine
def wait():
    pending = asyncio.Task.all_tasks()
    relevant_tasks = [t for t in pending if ('test_' not in t._coro.__name__)]
    yield from asyncio.gather(*relevant_tasks)


@pytest.fixture(scope="function")
def status(monkeypatch):
    update_socket_location = MagicMock()
    status = gosmart.status.StatusUpdater(update_socket_location)
        return super(ParameterDict, self).__getitem__(attr)

    def __setitem__(self, attr, value):
        param = convert_parameter(value[1], value[0])
        super(ParameterDict, self).__setitem__(attr, param)

    def update(self, *args, **kwargs):
        update_dict = dict(*args, **kwargs)
        super(ParameterDict, self).update(
            {k: convert_parameter(v[1], v[0])
             for k, v in update_dict.items()})


if gosmart._parameters is None:
    try:
        gosmart.setup('parameters.yml')
    except Exception as e:
        try:
            gosmart.setup('/shared/input/parameters.yml')
        except Exception as f:
            print(e)
            print(f)
            print("To load Go-Smart parameters from a non-default location"
                  ", you should first run "
                  "gosmart.setup(parameters), where parameters is a "
                  "parameter definition YAML filename, a string list or "
                  "a dict, with string keys.")

if gosmart._check_declared:
    declared_parameters = gosmart._parameters
else:
import pytest
import asyncio.coroutines
import asyncio
from unittest.mock import MagicMock
import uuid

import gosmart
gosmart.setup(False)
import gosmart.dicts
import gosmart.parameters

known_guid = str(uuid.uuid4()).upper()
unknown_guid = str(uuid.uuid4()).upper()


def magic_coro():
    mock = MagicMock()
    return mock, asyncio.coroutine(mock)


@asyncio.coroutine
def wait():
    pending = asyncio.Task.all_tasks()
    relevant_tasks = [t for t in pending if ('test_' not in t._coro.__name__)]
    yield from asyncio.gather(*relevant_tasks)


@pytest.fixture(scope="function")
def dicts(monkeypatch):
    update_socket_location = MagicMock()
    dicts = gosmart.dicts.ParameterDict(update_socket_location)
            )

        return super(ParameterDict, self).__getitem__(attr)

    def __setitem__(self, attr, value):
        param = convert_parameter(value[1], value[0])
        super(ParameterDict, self).__setitem__(attr, param)

    def update(self, *args, **kwargs):
        update_dict = dict(*args, **kwargs)
        super(ParameterDict, self).update({k: convert_parameter(v[1], v[0]) for k, v in update_dict.items()})


if gosmart._parameters is None:
    try:
        gosmart.setup('parameters.yml')
    except Exception as e:
        try:
            gosmart.setup('/shared/input/parameters.yml')
        except Exception as f:
            print(e)
            print(f)
            print(
                "To load Go-Smart parameters from a non-default location"
                ", you should first run "
                "gosmart.setup(parameters), where parameters is a "
                "parameter definition YAML filename, a string list or "
                "a dict, with string keys."
            )

if gosmart._check_declared: