コード例 #1
0
ファイル: test_cache.py プロジェクト: zillionare/omicron
    async def asyncSetUp(self) -> None:
        """Set up test fixtures, if any."""
        init_test_env()

        await clear_cache(cfg.redis.dsn)
        self.omega = await start_omega()
        await omicron.init()
        await cache.clear_bars_range("000001.XSHE", FrameType.MIN30)
コード例 #2
0
ファイル: test_syncjobs.py プロジェクト: zillionare/omega
    async def asyncSetUp(self) -> None:
        init_test_env()

        await emit.start(engine=emit.Engine.REDIS,
                         dsn=cfg.redis.dsn,
                         start_server=True)

        await self.create_quotes_fetcher()
        await omicron.init(aq)
コード例 #3
0
    async def asyncSetUp(self) -> None:
        init_test_env()

        await emit.start(engine=emit.Engine.REDIS, dsn=cfg.redis.dsn, start_server=True)

        await self.create_quotes_fetcher()
        await omicron.init(aq)
        home = Path(cfg.omega.home).expanduser()
        os.makedirs(str(home / "data/chksum"), exist_ok=True)

        self.omega = await start_omega()
コード例 #4
0
ファイル: test_valuation.py プロジェクト: zillionare/omicron
    async def asyncSetUp(self) -> None:
        self.cfg = init_test_env()
        self.omega = await start_omega()

        # hack: enable postgres during unittest
        self.cfg.postgres.enabled = True
        await omicron.init()
コード例 #5
0
ファイル: test_cli.py プロジェクト: zillionare/omega
    async def asyncSetUp(self) -> None:
        self.cfg = init_test_env()

        # disable catch up sync, since test_cli, jobs will be launched many times and cache might by empty
        redis = await aioredis.create_redis(self.cfg.redis.dsn)
        last_sync = arrow.now(self.cfg.tz).format("YYYY-MM-DD HH:mm:SS")
        await redis.set("jobs.bars_sync.stop", last_sync)
コード例 #6
0
ファイル: test_security.py プロジェクト: romepeng/omicron
    async def asyncSetUp(self) -> None:
        self.cfg = init_test_env()
        # check if omega is running
        self.omega = await start_omega()

        await omicron.init()

        self.securities = Securities()
        await self.securities.load()
コード例 #7
0
    async def test_start_logging(self):
        init_test_env()
        # remove handlers set by config file, if there is.
        root = logging.getLogger()
        root.handlers.clear()

        fmt = "%(asctime)s %(levelname)-1.1s %(process)d %(name)s:%(funcName)s:%(lineno)s | %(message)s"
        channel = "test_start_logging"
        redis_logger = logging.getLogger("test_redis")
        handler = rlog.RedisHandler(
            channel=channel,
            level=logging.DEBUG,
            host="localhost",
            port="6379",
            formatter=logging.Formatter(fmt),
        )

        redis_logger.addHandler(handler)

        _dir = "/tmp/omega/test_jobs"
        shutil.rmtree(_dir, ignore_errors=True)
        cfg4py.update_config({
            "logreceiver": {
                "klass": "omega.logging.receiver.redis.RedisLogReceiver",
                "dsn": "redis://localhost:6379",
                "channel": channel,
                "filename": "/tmp/omega/test_jobs/omega.log",
                "backup_count": 2,
                "max_bytes": "0.08K",
            }
        })

        await start_logging()
        for i in range(5):
            redis_logger.info("this is %sth test log", i)

        await asyncio.sleep(0.5)
        self.assertEqual(3, len(os.listdir(_dir)))
        with open(f"{_dir}/omega.log.2", "r", encoding="utf-8") as f:
            content = f.readlines()[0]
            msg = content.split("|")[1]
            self.assertEqual(" this is 2th test log\n", msg)
コード例 #8
0
    async def test_start_sync(self):
        init_test_env()
        port = find_free_port()
        url = f"http://localhost:{port}/jobs/sync_bars"
        job_server = None
        try:
            job_server = await start_job_server(port)
            sync_params = {
                "include": "000001.XSHE",
                "frame": FrameType.MIN60.value,
                "start": "2020-04-30",
                "stop": "2020-05-07",
            }

            async with aiohttp.ClientSession() as client:
                async with client.get(url, json=sync_params) as resp:
                    self.assertEqual(200, resp.status)
                    result = await resp.text()
                    print(result)
        finally:
            if job_server:
                job_server.kill()
コード例 #9
0
 async def test_init(self):
     init_test_env()
     await omicron.init()
     await cache.sys.delete("jobs.bars_sync.stop")
     try:
         cfg.omega.sync.bars = [{
             "frame": "1d",
             "start": "2020-01-02",
             "stop": "2020-01-03",
             "delay": 3,
             "cat": [],
             "include": "000001.XSHE",
             "exclude": "000001.XSHG",
         }]
         # disable init, just use cfg here
         with mock.patch("cfg4py.init"):
             await init(None, None)
             # won't trigger sync this time
             await init(None, None)
     finally:
         # cfg.omega.sync.bars = origin
         pass
コード例 #10
0
ファイル: __init__.py プロジェクト: zillionare/omega
 async def asyncSetUp(self) -> None:
     init_test_env()
     self.cfg = cfg4py.get_instance()
     self.omega = await start_omega()
     self.archive = await start_archive_server()
     await omicron.init()
コード例 #11
0
import unittest

import arrow
import numpy as np

import omicron
from omicron import cache
from omicron.core.timeframe import tf
from omicron.core.types import FrameType, SecurityType
from omicron.models.securities import Securities
from omicron.models.security import Security
from tests import init_test_env, start_omega

logger = logging.getLogger(__name__)

cfg = init_test_env()


class SecurityTest(unittest.IsolatedAsyncioTestCase):
    async def asyncSetUp(self) -> None:
        # check if omega is running
        self.omega = await start_omega()

        await omicron.init()

        self.securities = Securities()
        await self.securities.load()

    async def asyncTearDown(self) -> None:
        await omicron.shutdown()
        if self.omega is not None:
コード例 #12
0
ファイル: test_securities.py プロジェクト: romepeng/omicron
 async def asyncSetUp(self) -> None:
     """Set up test fixtures, if any."""
     init_test_env()
     self.omega = await start_omega()
     await omicron.init()
コード例 #13
0
 async def asyncSetUp(self) -> None:
     self.cfg = init_test_env()
コード例 #14
0
ファイル: test_web_interfaces.py プロジェクト: romepeng/omega
 async def asyncSetUp(self) -> None:
     init_test_env()
     self.cfg = cfg4py.get_instance()
     self.omega = await start_omega()
コード例 #15
0
    async def asyncSetUp(self) -> None:
        init_test_env()

        await self.create_quotes_fetcher()
        await omicron.init(aq)
コード例 #16
0
ファイル: test_cli.py プロジェクト: XuexuMa/omega
 def setUp(self) -> None:
     self.cfg = init_test_env()