def test_load(self):
        foo_config = FooConfig()
        foo_config.section = 'foo_section'

        HappyConfigParser.load('example.ini', foo_config)

        self.assertEqual(foo_config.section, 'foo_section')
        self.assertEqual(foo_config.example_name, 'abc')
        self.assertEqual(foo_config.example_port, 5432)
        self.assertTrue(foo_config.example_enable)
        self.assertEqual(foo_config.example_list, ['a', 'b', 'c', 'd'])
    def test_load_with_var(self):
        foo_config = FooConfig()
        foo_config.section = 'foo_section'

        HappyConfigParser.load_with_var('example.ini', {'log_dirname': 'log'}, foo_config)

        self.assertEqual(foo_config.section, 'foo_section')
        self.assertEqual(foo_config.example_name, 'abc')
        self.assertEqual(foo_config.example_port, 5432)
        self.assertTrue(foo_config.example_enable)
        self.assertEqual(foo_config.example_list, ['a', 'b', 'c', 'd'])
        self.assertEqual(foo_config.example_var, '/var/log')
    def test_loads(self):
        with open('example.ini') as f:
            foo_config = FooConfig()
            foo_config.section = 'foo_section'
            content = ''.join(f.readlines())
            HappyConfigParser._loads(content, foo_config)

            self.assertEqual(foo_config.section, 'foo_section')
            self.assertEqual(foo_config.example_name, 'abc')
            self.assertEqual(foo_config.example_port, 5432)
            self.assertTrue(foo_config.example_enable)
            self.assertEqual(foo_config.example_list, ['a', 'b', 'c', 'd'])
# @File    : common
# @Software: PyCharm

from pathlib import PurePath
from happy_python import HappyConfigParser
from happy_python import HappyLog
from config import ApiConfig, MqConfig

# 配置文件位置
CONFIG_DIR = PurePath(__file__).parent / 'configs'
CONFIG_FILENAME = str(CONFIG_DIR / 'common.ini')
LOG_CONFIG_FILENAME = str(CONFIG_DIR / 'log.ini')

# 加载api配置
api_config = ApiConfig()
HappyConfigParser.load(CONFIG_FILENAME, api_config)

# 加载mq配置
mq_config = MqConfig()
HappyConfigParser.load(CONFIG_FILENAME, mq_config)

# 加载log配置
hlog = HappyLog.get_instance(LOG_CONFIG_FILENAME)

# 爬取网页的间隔时间
delay = 3

# 网页域名到网站名字的映射
PLATFORM_MAP = {
    "zhipin": "boss直聘",
    "51job": "前程无忧",
Exemple #5
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2020/8/7 上午11:17
# @Author : 尹新
# @Site :
# @File : common
# @Software: PyCharm
from pathlib import PurePath

from happy_python import HappyConfigParser, HappyLog

from config import Config

CONFIG_DIR = PurePath(__file__).parent / 'resource'
CONFIG_FILENAME = str(CONFIG_DIR / 'default.ini')

config = Config()
HappyConfigParser.load(CONFIG_FILENAME, config)

hlog = HappyLog.get_instance()