# Path: test/mock_device/mock_data.py
# def generate():
# 
# Path: test/mock_device/iec104device.py
# class IEC104Device:
#     def __init__(self, device, reader, writer):
#     async def receive(self):
#     def connection_lost(self):
#     def inc_ssn(self):
#     def inc_rsn(self):
#     def start_timer(self, timer_id):
#     def stop_timer(self, timer_id):
#     def on_timer0(self):
#     def on_timer1(self):
#     def on_timer2(self):
#     def on_timer3(self):
#     async def handle_u(self, frame):
#     async def handle_i(self, frame):
#     async def send_frame(self, frame, check=True):
#     async def check_to_send(self, frame):
#     def save_frame(self, frame, send=True):
#     async def generate_call_all_data(self):
#     def generate_call_power_data(self):
# def create_servers(io_loop):
# def run_server():
# 
# Path: pydatacoll/api_server.py
# HANDLER_TIME_OUT = config.getint('SERVER', 'web_timeout', fallback=10)
# class APIServer(ParamFunctionContainer):
#     def __init__(self, port: int = None, production: bool = None, io_loop: asyncio.AbstractEventLoop = None):
#     def _add_router(self):
#     def _install_plugins(self):
#     def _uninstall_plugins(self):
#     def stop_server(self):
#     def found_and_delete(self, match: str):
#     async def _read_data(request):
#     async def get_index(self, request):
#     async def get_redis_key(self, _):
#     async def get_device_protocol_list(self, _):
#     async def get_term_protocol_list(self, _):
#     async def get_formula_list(self, _):
#     async def get_formula(self, request):
#     async def get_device_list(self, _):
#     async def get_device(self, request):
#     async def get_term_list(self, _):
#     async def get_term(self, request):
#     async def get_item_list(self, _):
#     async def get_item(self, request):
#     async def get_device_term_list(self, request):
#     async def get_term_item_list(self, request):
#     async def get_term_item(self, request):
#     async def get_data_list(self, request):
#     async def get_data(self, request):
#     async def create_formula(self, request):
#     async def create_formula_batch(self, request):
#     async def update_formula(self, request):
#     async def del_formula(self, request):
#     async def del_formula_batch(self, request):
#     async def create_device(self, request):
#     async def create_device_batch(self, request):
#     async def update_device(self, request):
#     async def del_device(self, request):
#     async def del_device_batch(self, request):
#     async def create_term(self, request):
#     async def create_term_batch(self, request):
#     async def update_term(self, request):
#     async def del_term(self, request):
#     async def del_term_batch(self, request):
#     async def create_item(self, request):
#     async def create_item_batch(self, request):
#     async def update_item(self, request):
#     async def del_item(self, request):
#     async def del_item_batch(self, request):
#     async def create_term_item(self, request):
#     async def create_term_item_batch(self, request):
#     async def update_term_item(self, request):
#     async def del_term_item(self, request):
#     async def del_term_item_batch(self, request):
#     async def device_call(self, request):
#             async def reader(ch):
#     async def device_ctrl(self, request):
#             async def reader(ch):
#     async def formula_check(self, request):
#             async def reader(ch):
#     async def sql_check(self, request):
#             async def reader(ch):
# def main():


import asyncio
import aiohttp
import aioredis
import asynctest
import redis
    import ujson as json
    import json
import pydatacoll.utils.logger as my_logger
from pydatacoll.resources.protocol import *
from pydatacoll.resources.redis_key import *
from test.mock_device import mock_data, iec104device
from pydatacoll import api_server
from pydatacoll.utils.read_config import *
try:
except ImportError:


logger = my_logger.get_logger('TestInterface')


class RedisTest(asynctest.TestCase):
    async def test_connect_timeout(self):
        try:
            loop = asyncio.get_event_loop()
            reader, writer = await asyncio.open_connection(config.get('REDIS', 'host', fallback='127.0.0.1'),
                                                           config.getint('REDIS', 'port', fallback=6379), loop=loop)
            loop.call_later(1, lambda w: w.close(), writer)
            data = await reader.readexactly(100)
            logger.debug('Received: %r', data.decode())
            # print("data={}".format(data))
            self.assertEqual(len(data), 0)
        except asyncio.IncompleteReadError:
            logger.debug('stream closed!')
        except Exception as e:
            logger.error('e=', repr(e))

    async def test_redis_listen(self):
        pub_client = await aioredis.create_redis((config.get('REDIS', 'host', fallback='127.0.0.1'),
                                                  config.getint('REDIS', 'port', fallback=6379)),
                                                 db=config.getint('REDIS', 'db', fallback=1))

# Path: test/mock_device/mock_data.py
# def generate():
# 
# Path: test/mock_device/iec104device.py
# class IEC104Device:
#     def __init__(self, device, reader, writer):
#     async def receive(self):
#     def connection_lost(self):
#     def inc_ssn(self):
#     def inc_rsn(self):
#     def start_timer(self, timer_id):
#     def stop_timer(self, timer_id):
#     def on_timer0(self):
#     def on_timer1(self):
#     def on_timer2(self):
#     def on_timer3(self):
#     async def handle_u(self, frame):
#     async def handle_i(self, frame):
#     async def send_frame(self, frame, check=True):
#     async def check_to_send(self, frame):
#     def save_frame(self, frame, send=True):
#     async def generate_call_all_data(self):
#     def generate_call_power_data(self):
# def create_servers(io_loop):
# def run_server():
# 
# Path: pydatacoll/api_server.py
# HANDLER_TIME_OUT = config.getint('SERVER', 'web_timeout', fallback=10)
# class APIServer(ParamFunctionContainer):
#     def __init__(self, port: int = None, production: bool = None, io_loop: asyncio.AbstractEventLoop = None):
#     def _add_router(self):
#     def _install_plugins(self):
#     def _uninstall_plugins(self):
#     def stop_server(self):
#     def found_and_delete(self, match: str):
#     async def _read_data(request):
#     async def get_index(self, request):
#     async def get_redis_key(self, _):
#     async def get_device_protocol_list(self, _):
#     async def get_term_protocol_list(self, _):
#     async def get_formula_list(self, _):
#     async def get_formula(self, request):
#     async def get_device_list(self, _):
#     async def get_device(self, request):
#     async def get_term_list(self, _):
#     async def get_term(self, request):
#     async def get_item_list(self, _):
#     async def get_item(self, request):
#     async def get_device_term_list(self, request):
#     async def get_term_item_list(self, request):
#     async def get_term_item(self, request):
#     async def get_data_list(self, request):
#     async def get_data(self, request):
#     async def create_formula(self, request):
#     async def create_formula_batch(self, request):
#     async def update_formula(self, request):
#     async def del_formula(self, request):
#     async def del_formula_batch(self, request):
#     async def create_device(self, request):
#     async def create_device_batch(self, request):
#     async def update_device(self, request):
#     async def del_device(self, request):
#     async def del_device_batch(self, request):
#     async def create_term(self, request):
#     async def create_term_batch(self, request):
#     async def update_term(self, request):
#     async def del_term(self, request):
#     async def del_term_batch(self, request):
#     async def create_item(self, request):
#     async def create_item_batch(self, request):
#     async def update_item(self, request):
#     async def del_item(self, request):
#     async def del_item_batch(self, request):
#     async def create_term_item(self, request):
#     async def create_term_item_batch(self, request):
#     async def update_term_item(self, request):
#     async def del_term_item(self, request):
#     async def del_term_item_batch(self, request):
#     async def device_call(self, request):
#             async def reader(ch):
#     async def device_ctrl(self, request):
#             async def reader(ch):
#     async def formula_check(self, request):
#             async def reader(ch):
#     async def sql_check(self, request):
#             async def reader(ch):
# def main():


# Path: test/test_interface.py
import asyncio
import aiohttp
import aioredis
import asynctest
import redis
    import ujson as json
    import json
import pydatacoll.utils.logger as my_logger
from pydatacoll.resources.protocol import *
from pydatacoll.resources.redis_key import *
from test.mock_device import mock_data, iec104device
from pydatacoll import api_server
from pydatacoll.utils.read_config import *

try:
except ImportError:


logger = my_logger.get_logger('TestInterface')


class RedisTest(asynctest.TestCase):
    async def test_connect_timeout(self):
        try:
            loop = asyncio.get_event_loop()
            reader, writer = await asyncio.open_connection(config.get('REDIS', 'host', fallback='127.0.0.1'),
                                                           config.getint('REDIS', 'port', fallback=6379), loop=loop)
            loop.call_later(1, lambda w: w.close(), writer)
            data = await reader.readexactly(100)
            logger.debug('Received: %r', data.decode())
            # print("data={}".format(data))
            self.assertEqual(len(data), 0)
        except asyncio.IncompleteReadError:
            logger.debug('stream closed!')
        except Exception as e:
            logger.error('e=', repr(e))

    async def test_redis_listen(self):
        pub_client = await aioredis.create_redis((config.get('REDIS', 'host', fallback='127.0.0.1'),
                                                  config.getint('REDIS', 'port', fallback=6379)),
                                                 db=config.getint('REDIS', 'db', fallback=1))

        sub_client = await aioredis.create_redis((config.get('REDIS', 'host', fallback='127.0.0.1'),