Speed up tests
This commit is contained in:
parent
a34b00bc9c
commit
58afbecd05
21 changed files with 98 additions and 82 deletions
|
@ -49,13 +49,15 @@ class TestConfig(unittest.TestCase):
|
|||
|
||||
self.assertEqual(YAML_PATH, config_util.find_config_file(CONFIG_DIR))
|
||||
|
||||
def test_ensure_config_exists_creates_config(self):
|
||||
@mock.patch('builtins.print')
|
||||
def test_ensure_config_exists_creates_config(self, mock_print):
|
||||
""" Test that calling ensure_config_exists creates a new config file if
|
||||
none exists. """
|
||||
|
||||
config_util.ensure_config_exists(CONFIG_DIR, False)
|
||||
|
||||
self.assertTrue(os.path.isfile(YAML_PATH))
|
||||
self.assertTrue(mock_print.called)
|
||||
|
||||
def test_ensure_config_exists_uses_existing_config(self):
|
||||
""" Test that calling ensure_config_exists uses existing config. """
|
||||
|
@ -100,11 +102,12 @@ class TestConfig(unittest.TestCase):
|
|||
self.assertEqual({'hello': 'world'},
|
||||
config_util.load_config_file(YAML_PATH))
|
||||
|
||||
def test_create_default_config_detect_location(self):
|
||||
@mock.patch('homeassistant.util.location.detect_location_info',
|
||||
mock_detect_location_info)
|
||||
@mock.patch('builtins.print')
|
||||
def test_create_default_config_detect_location(self, mock_print):
|
||||
""" Test that detect location sets the correct config keys. """
|
||||
with mock.patch('homeassistant.util.location.detect_location_info',
|
||||
mock_detect_location_info):
|
||||
config_util.ensure_config_exists(CONFIG_DIR)
|
||||
config_util.ensure_config_exists(CONFIG_DIR)
|
||||
|
||||
config = config_util.load_config_file(YAML_PATH)
|
||||
|
||||
|
@ -121,11 +124,15 @@ class TestConfig(unittest.TestCase):
|
|||
}
|
||||
|
||||
self.assertEqual(expected_values, ha_conf)
|
||||
self.assertTrue(mock_print.called)
|
||||
|
||||
def test_create_default_config_returns_none_if_write_error(self):
|
||||
@mock.patch('builtins.print')
|
||||
def test_create_default_config_returns_none_if_write_error(self,
|
||||
mock_print):
|
||||
"""
|
||||
Test that writing default config to non existing folder returns None.
|
||||
"""
|
||||
self.assertIsNone(
|
||||
config_util.create_default_config(
|
||||
os.path.join(CONFIG_DIR, 'non_existing_dir/'), False))
|
||||
self.assertTrue(mock_print.called)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue