• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python common.patch_yaml_files函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.common.patch_yaml_files函数的典型用法代码示例。如果您正苦于以下问题:Python patch_yaml_files函数的具体用法?Python patch_yaml_files怎么用?Python patch_yaml_files使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了patch_yaml_files函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_config_component_platform_fail_validation

    def test_config_component_platform_fail_validation(self):
        """Test errors if component & platform not found."""
        files = {
            'component.yaml': BASE_CONFIG + 'http:\n  password: err123',
        }
        with patch_yaml_files(files):
            res = check_config.check(get_test_config_dir('component.yaml'))
            change_yaml_files(res)
            self.assertDictEqual({
                'components': {},
                'except': {'http': {'password': 'err123'}},
                'secret_cache': {},
                'secrets': {},
                'yaml_files': ['.../component.yaml']
            }, res)

        files = {
            'platform.yaml': (BASE_CONFIG + 'mqtt:\n\n'
                              'light:\n  platform: mqtt_json'),
        }
        with patch_yaml_files(files):
            res = check_config.check(get_test_config_dir('platform.yaml'))
            change_yaml_files(res)
            self.assertDictEqual({
                'components': {'mqtt': {'keepalive': 60, 'port': 1883,
                                        'protocol': '3.1.1'}},
                'except': {'light.mqtt_json': {'platform': 'mqtt_json'}},
                'secret_cache': {},
                'secrets': {},
                'yaml_files': ['.../platform.yaml']
            }, res)
开发者ID:gazzer82,项目名称:home-assistant,代码行数:31,代码来源:test_check_config.py


示例2: test_component_platform_not_found

    def test_component_platform_not_found(self, isfile_patch):
        """Test errors if component or platform not found."""
        # Make sure they don't exist
        set_component('beer', None)
        files = {
            YAML_CONFIG_FILE: BASE_CONFIG + 'beer:',
        }
        with patch_yaml_files(files):
            res = check_config.check(get_test_config_dir())
            assert res['components'].keys() == {'homeassistant'}
            assert res['except'] == {
                check_config.ERROR_STR: ['Component not found: beer']}
            assert res['secret_cache'] == {}
            assert res['secrets'] == {}
            assert len(res['yaml_files']) == 1

        set_component('light.beer', None)
        files = {
            YAML_CONFIG_FILE: BASE_CONFIG + 'light:\n  platform: beer',
        }
        with patch_yaml_files(files):
            res = check_config.check(get_test_config_dir())
            assert res['components'].keys() == {'homeassistant', 'light'}
            assert res['components']['light'] == []
            assert res['except'] == {
                check_config.ERROR_STR: [
                    'Platform not found: light.beer',
                ]}
            assert res['secret_cache'] == {}
            assert res['secrets'] == {}
            assert len(res['yaml_files']) == 1
开发者ID:TheRealLink,项目名称:home-assistant,代码行数:31,代码来源:test_check_config.py


示例3: test_include_yaml

    def test_include_yaml(self):
        """Test include yaml."""
        with patch_yaml_files({'test.yaml': 'value'}):
            conf = 'key: !include test.yaml'
            with io.StringIO(conf) as file:
                doc = yaml.yaml.safe_load(file)
                assert doc["key"] == "value"

        with patch_yaml_files({'test.yaml': None}):
            conf = 'key: !include test.yaml'
            with io.StringIO(conf) as file:
                doc = yaml.yaml.safe_load(file)
                assert doc["key"] == {}
开发者ID:Teagan42,项目名称:home-assistant,代码行数:13,代码来源:test_yaml.py


示例4: test_include_yaml

 def test_include_yaml(self):
     """Test include yaml."""
     with patch_yaml_files({"test.yaml": "value"}):
         conf = "key: !include test.yaml"
         with io.StringIO(conf) as file:
             doc = yaml.yaml.safe_load(file)
             assert doc["key"] == "value"
开发者ID:GadgetReactor,项目名称:home-assistant,代码行数:7,代码来源:test_yaml.py


示例5: test_reading_broken_yaml_config

    def test_reading_broken_yaml_config(self):  # pylint: disable=no-self-use
        """Test when known devices contains invalid data."""
        files = {
            "empty.yaml": "",
            "nodict.yaml": "100",
            "badkey.yaml": "@:\n  name: Device",
            "noname.yaml": "my_device:\n",
            "allok.yaml": "My Device:\n  name: Device",
            "oneok.yaml": ("My Device!:\n  name: Device\n" "bad_device:\n  nme: Device"),
        }
        args = {"hass": self.hass, "consider_home": timedelta(seconds=60)}
        with patch_yaml_files(files):
            assert device_tracker.load_config("empty.yaml", **args) == []
            assert device_tracker.load_config("nodict.yaml", **args) == []
            assert device_tracker.load_config("noname.yaml", **args) == []
            assert device_tracker.load_config("badkey.yaml", **args) == []

            res = device_tracker.load_config("allok.yaml", **args)
            assert len(res) == 1
            assert res[0].name == "Device"
            assert res[0].dev_id == "my_device"

            res = device_tracker.load_config("oneok.yaml", **args)
            assert len(res) == 1
            assert res[0].name == "Device"
            assert res[0].dev_id == "my_device"
开发者ID:MartinHjelmare,项目名称:home-assistant,代码行数:26,代码来源:test_init.py


示例6: test_secrets

    def test_secrets(self, mock_get_loop):
        """Test secrets config checking method."""
        files = {
            get_test_config_dir('secret.yaml'): (
                BASE_CONFIG +
                'http:\n'
                '  api_password: !secret http_pw'),
            'secrets.yaml': ('logger: debug\n'
                             'http_pw: abc123'),
        }
        self.maxDiff = None

        with patch_yaml_files(files):
            config_path = get_test_config_dir('secret.yaml')
            secrets_path = get_test_config_dir('secrets.yaml')

            res = check_config.check(config_path)
            change_yaml_files(res)

            # convert secrets OrderedDict to dict for assertequal
            for key, val in res['secret_cache'].items():
                res['secret_cache'][key] = dict(val)

            self.assertDictEqual({
                'components': {'http': {'api_password': 'abc123',
                                        'server_port': 8123}},
                'except': {},
                'secret_cache': {secrets_path: {'http_pw': 'abc123'}},
                'secrets': {'http_pw': 'abc123'},
                'yaml_files': ['.../secret.yaml', '.../secrets.yaml']
            }, res)
开发者ID:krzynio,项目名称:home-assistant,代码行数:31,代码来源:test_check_config.py


示例7: test_reading_broken_yaml_config

    def test_reading_broken_yaml_config(self):
        """Test when known devices contains invalid data."""
        files = {'empty.yaml': '',
                 'nodict.yaml': '100',
                 'badkey.yaml': '@:\n  name: Device',
                 'noname.yaml': 'my_device:\n',
                 'allok.yaml':  'My Device:\n  name: Device',
                 'oneok.yaml':  ('My Device!:\n  name: Device\n'
                                 'bad_device:\n  nme: Device')}
        args = {'hass': self.hass, 'consider_home': timedelta(seconds=60)}
        with patch_yaml_files(files):
            assert device_tracker.load_config('empty.yaml', **args) == []
            assert device_tracker.load_config('nodict.yaml', **args) == []
            assert device_tracker.load_config('noname.yaml', **args) == []
            assert device_tracker.load_config('badkey.yaml', **args) == []

            res = device_tracker.load_config('allok.yaml', **args)
            assert len(res) == 1
            assert res[0].name == 'Device'
            assert res[0].dev_id == 'my_device'

            res = device_tracker.load_config('oneok.yaml', **args)
            assert len(res) == 1
            assert res[0].name == 'Device'
            assert res[0].dev_id == 'my_device'
开发者ID:ManHammer,项目名称:home-assistant,代码行数:25,代码来源:test_init.py


示例8: test_secrets

    def test_secrets(self, isfile_patch):
        """Test secrets config checking method."""
        secrets_path = get_test_config_dir('secrets.yaml')

        files = {
            get_test_config_dir(YAML_CONFIG_FILE): BASE_CONFIG + (
                'http:\n'
                '  api_password: !secret http_pw'),
            secrets_path: (
                'logger: debug\n'
                'http_pw: abc123'),
        }

        with patch_yaml_files(files):

            res = check_config.check(get_test_config_dir(), True)

            assert res['except'] == {}
            assert res['components'].keys() == {'homeassistant', 'http'}
            assert res['components']['http'] == {
                'api_password': 'abc123',
                'cors_allowed_origins': [],
                'ip_ban_enabled': True,
                'login_attempts_threshold': -1,
                'server_host': '0.0.0.0',
                'server_port': 8123,
                'trusted_networks': [],
                'use_x_forwarded_for': False}
            assert res['secret_cache'] == {secrets_path: {'http_pw': 'abc123'}}
            assert res['secrets'] == {'http_pw': 'abc123'}
            assert normalize_yaml_files(res) == [
                '.../configuration.yaml', '.../secrets.yaml']
开发者ID:TheRealLink,项目名称:home-assistant,代码行数:32,代码来源:test_check_config.py


示例9: test_component_platform_not_found

    def test_component_platform_not_found(self, mock_get_loop):
        """Test errors if component or platform not found."""
        files = {
            'badcomponent.yaml': BASE_CONFIG + 'beer:',
            'badplatform.yaml': BASE_CONFIG + 'light:\n  platform: beer',
        }
        with patch_yaml_files(files):
            res = check_config.check(get_test_config_dir('badcomponent.yaml'))
            change_yaml_files(res)
            self.assertDictEqual({}, res['components'])
            self.assertDictEqual({check_config.ERROR_STR:
                                  ['Component not found: beer']},
                                 res['except'])
            self.assertDictEqual({}, res['secret_cache'])
            self.assertDictEqual({}, res['secrets'])
            self.assertListEqual(['.../badcomponent.yaml'], res['yaml_files'])

            res = check_config.check(get_test_config_dir('badplatform.yaml'))
            change_yaml_files(res)
            self.assertDictEqual({'light': []}, res['components'])
            self.assertDictEqual({check_config.ERROR_STR:
                                  ['Platform not found: light.beer']},
                                 res['except'])
            self.assertDictEqual({}, res['secret_cache'])
            self.assertDictEqual({}, res['secrets'])
            self.assertListEqual(['.../badplatform.yaml'], res['yaml_files'])
开发者ID:krzynio,项目名称:home-assistant,代码行数:26,代码来源:test_check_config.py


示例10: test_async_added_to_hass

def test_async_added_to_hass(hass):
    """Test restoring state."""
    attr = {
        device_tracker.ATTR_LONGITUDE: 18,
        device_tracker.ATTR_LATITUDE: -33,
        device_tracker.ATTR_LATITUDE: -33,
        device_tracker.ATTR_SOURCE_TYPE: 'gps',
        device_tracker.ATTR_GPS_ACCURACY: 2,
        device_tracker.ATTR_BATTERY: 100
    }
    mock_restore_cache(hass, [State('device_tracker.jk', 'home', attr)])

    path = hass.config.path(device_tracker.YAML_DEVICES)

    files = {
        path: 'jk:\n  name: JK Phone\n  track: True',
    }
    with patch_yaml_files(files):
        yield from device_tracker.async_setup(hass, {})

    state = hass.states.get('device_tracker.jk')
    assert state
    assert state.state == 'home'

    for key, val in attr.items():
        atr = state.attributes.get(key)
        assert atr == val, "{}={} expected: {}".format(key, atr, val)
开发者ID:ManHammer,项目名称:home-assistant,代码行数:27,代码来源:test_init.py


示例11: test_include_dir_merge_named_recursive

    def test_include_dir_merge_named_recursive(self, mock_walk):
        """Test include dir merge named yaml."""
        mock_walk.return_value = [
            ['/tmp', ['tmp2', '.ignore', 'ignore'], ['first.yaml']],
            ['/tmp/tmp2', [], ['second.yaml', 'third.yaml']],
            ['/tmp/ignore', [], ['.ignore.yaml']]
        ]

        with patch_yaml_files({
            '/tmp/first.yaml': 'key1: one',
            '/tmp/tmp2/second.yaml': 'key2: two',
            '/tmp/tmp2/third.yaml': 'key3: three\nkey4: four'
        }):
            conf = "key: !include_dir_merge_named /tmp"
            with io.StringIO(conf) as file:
                assert '.ignore' in mock_walk.return_value[0][1], \
                    "Expecting .ignore in here"
                doc = yaml.yaml.safe_load(file)
                assert 'tmp2' in mock_walk.return_value[0][1]
                assert '.ignore' not in mock_walk.return_value[0][1]
                assert doc["key"] == {
                    "key1": "one",
                    "key2": "two",
                    "key3": "three",
                    "key4": "four"
                }
开发者ID:Teagan42,项目名称:home-assistant,代码行数:26,代码来源:test_yaml.py


示例12: test_component_platform_not_found

    def test_component_platform_not_found(self):
        """Test errors if component or platform not found."""
        # Make sure they don't exist
        set_component('beer', None)
        set_component('light.beer', None)
        files = {
            'badcomponent.yaml': BASE_CONFIG + 'beer:',
            'badplatform.yaml': BASE_CONFIG + 'light:\n  platform: beer',
        }
        with patch_yaml_files(files):
            res = check_config.check(get_test_config_dir('badcomponent.yaml'))
            change_yaml_files(res)
            self.assertDictEqual({}, res['components'])
            self.assertDictEqual({
                    check_config.ERROR_STR: [
                        'Component not found: beer',
                        'Setup failed for beer: Component not found.']
                }, res['except'])
            self.assertDictEqual({}, res['secret_cache'])
            self.assertDictEqual({}, res['secrets'])
            self.assertListEqual(['.../badcomponent.yaml'], res['yaml_files'])

            res = check_config.check(get_test_config_dir('badplatform.yaml'))
            change_yaml_files(res)
            assert res['components'] == {'light': [], 'group': None}
            assert res['except'] == {
                check_config.ERROR_STR: [
                    'Platform not found: light.beer',
                ]}
            self.assertDictEqual({}, res['secret_cache'])
            self.assertDictEqual({}, res['secrets'])
            self.assertListEqual(['.../badplatform.yaml'], res['yaml_files'])
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:32,代码来源:test_check_config.py


示例13: test_config_component_platform_fail_validation

    def test_config_component_platform_fail_validation(self):
        """Test errors if component & platform not found."""
        files = {
            'component.yaml': BASE_CONFIG + 'http:\n  password: err123',
        }
        with patch_yaml_files(files):
            res = check_config.check(get_test_config_dir('component.yaml'))
            change_yaml_files(res)

            self.assertDictEqual({}, res['components'])
            res['except'].pop(check_config.ERROR_STR)
            self.assertDictEqual(
                {'http': {'password': 'err123'}},
                res['except']
            )
            self.assertDictEqual({}, res['secret_cache'])
            self.assertDictEqual({}, res['secrets'])
            self.assertListEqual(['.../component.yaml'], res['yaml_files'])

        files = {
            'platform.yaml': (BASE_CONFIG + 'mqtt:\n\n'
                              'light:\n  platform: mqtt_json'),
        }
        with patch_yaml_files(files):
            res = check_config.check(get_test_config_dir('platform.yaml'))
            change_yaml_files(res)
            self.assertDictEqual(
                {'mqtt': {
                    'keepalive': 60,
                    'port': 1883,
                    'protocol': '3.1.1',
                    'discovery': False,
                    'discovery_prefix': 'homeassistant',
                    'tls_version': 'auto',
                },
                 'light': [],
                 'group': None},
                res['components']
            )
            self.assertDictEqual(
                {'light.mqtt_json': {'platform': 'mqtt_json'}},
                res['except']
            )
            self.assertDictEqual({}, res['secret_cache'])
            self.assertDictEqual({}, res['secrets'])
            self.assertListEqual(['.../platform.yaml'], res['yaml_files'])
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:46,代码来源:test_check_config.py


示例14: test_include_dir_merge_list

    def test_include_dir_merge_list(self, mock_walk):
        """Test include dir merge list yaml."""
        mock_walk.return_value = [["/tmp", [], ["first.yaml", "second.yaml"]]]

        with patch_yaml_files({"/tmp/first.yaml": "- one", "/tmp/second.yaml": "- two\n- three"}):
            conf = "key: !include_dir_merge_list /tmp"
            with io.StringIO(conf) as file:
                doc = yaml.yaml.safe_load(file)
                assert sorted(doc["key"]) == sorted(["one", "two", "three"])
开发者ID:GadgetReactor,项目名称:home-assistant,代码行数:9,代码来源:test_yaml.py


示例15: test_bad_core_config

 def test_bad_core_config(self, isfile_patch):
     """Test a bad core config setup."""
     files = {
         YAML_CONFIG_FILE: BAD_CORE_CONFIG,
     }
     with patch_yaml_files(files):
         res = check_config.check(get_test_config_dir())
         assert res['except'].keys() == {'homeassistant'}
         assert res['except']['homeassistant'][1] == {'unit_system': 'bad'}
开发者ID:Martwall,项目名称:home-assistant,代码行数:9,代码来源:test_check_config.py


示例16: test_include_dir_list

    def test_include_dir_list(self, mock_walk):
        """Test include dir list yaml."""
        mock_walk.return_value = [["/tmp", [], ["one.yaml", "two.yaml"]]]

        with patch_yaml_files({"/tmp/one.yaml": "one", "/tmp/two.yaml": "two"}):
            conf = "key: !include_dir_list /tmp"
            with io.StringIO(conf) as file:
                doc = yaml.yaml.safe_load(file)
                assert sorted(doc["key"]) == sorted(["one", "two"])
开发者ID:GadgetReactor,项目名称:home-assistant,代码行数:9,代码来源:test_yaml.py


示例17: test_include_dir_named

    def test_include_dir_named(self, mock_walk):
        """Test include dir named yaml."""
        mock_walk.return_value = [["/tmp", [], ["first.yaml", "second.yaml"]]]

        with patch_yaml_files({"/tmp/first.yaml": "one", "/tmp/second.yaml": "two"}):
            conf = "key: !include_dir_named /tmp"
            correct = {"first": "one", "second": "two"}
            with io.StringIO(conf) as file:
                doc = yaml.yaml.safe_load(file)
                assert doc["key"] == correct
开发者ID:GadgetReactor,项目名称:home-assistant,代码行数:10,代码来源:test_yaml.py


示例18: test_include_dir_merge_named

    def test_include_dir_merge_named(self, mock_walk):
        """Test include dir merge named yaml."""
        mock_walk.return_value = [["/tmp", [], ["first.yaml", "second.yaml"]]]

        files = {"/tmp/first.yaml": "key1: one", "/tmp/second.yaml": "key2: two\nkey3: three"}

        with patch_yaml_files(files):
            conf = "key: !include_dir_merge_named /tmp"
            with io.StringIO(conf) as file:
                doc = yaml.yaml.safe_load(file)
                assert doc["key"] == {"key1": "one", "key2": "two", "key3": "three"}
开发者ID:GadgetReactor,项目名称:home-assistant,代码行数:11,代码来源:test_yaml.py


示例19: test_reload_core_with_wrong_conf

    def test_reload_core_with_wrong_conf(self, mock_process, mock_error):
        """Test reload core conf service."""
        files = {
            config.YAML_CONFIG_FILE: yaml.dump(['invalid', 'config'])
        }
        with patch_yaml_files(files, True):
            comps.reload_core_config(self.hass)
            self.hass.block_till_done()

        assert mock_error.called
        assert mock_process.called is False
开发者ID:simpss,项目名称:home-assistant,代码行数:11,代码来源:test_init.py


示例20: test_from_config_file

def test_from_config_file(hass):
    """Test with configuration file."""
    components = set(['browser', 'conversation', 'script'])
    files = {
        'config.yaml': ''.join('{}:\n'.format(comp) for comp in components)
    }

    with patch_yaml_files(files, True):
        yield from bootstrap.async_from_config_file('config.yaml')

    assert components == hass.config.components
开发者ID:W00D00,项目名称:home-assistant,代码行数:11,代码来源:test_bootstrap.py



注:本文中的tests.common.patch_yaml_files函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.MockConfigEntry类代码示例发布时间:2022-05-27
下一篇:
Python common.mock_state_change_event函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap