Просмотр исходного кода

tests (device_config): experiment with output format

Newline insertion worked, but errors are not picked up as error lines.
Jason Rumney 2 месяцев назад
Родитель
Сommit
5e9efde4c1
1 измененных файлов с 19 добавлено и 19 удалено
  1. 19 19
      tests/test_device_config.py

+ 19 - 19
tests/test_device_config.py

@@ -404,12 +404,12 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
         line = entity._config.__line__
         line = entity._config.__line__
         self.assertIsNotNone(
         self.assertIsNotNone(
             entity._config.get("entity"),
             entity._config.get("entity"),
-            f"\n{fname}:{line}: entity type missing in {cfg}",
+            f"\nERROR {fname}:{line}: entity type missing in {cfg}",
         )
         )
         e = entity.config_id
         e = entity.config_id
         self.assertIsNotNone(
         self.assertIsNotNone(
             entity._config.get("dps"),
             entity._config.get("dps"),
-            f"\n{fname}:{line}: dps missing from {e} in {cfg}",
+            f"\nERROR {fname}:{line}: dps missing from {e} in {cfg}",
         )
         )
         functions = set()
         functions = set()
         extra = set()
         extra = set()
@@ -422,22 +422,22 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
             line = dp._config.__line__
             line = dp._config.__line__
             self.assertIsNotNone(
             self.assertIsNotNone(
                 dp._config.get("id"),
                 dp._config.get("id"),
-                f"\n{fname}:{line}: dp id missing from {e} in {cfg}",
+                f"\nERROR {fname}:{line}: dp id missing from {e} in {cfg}",
             )
             )
             self.assertIsNotNone(
             self.assertIsNotNone(
                 dp._config.get("type"),
                 dp._config.get("type"),
-                f"\n{fname}:{line}: dp type missing from {e} in {cfg}",
+                f"\nERROR {fname}:{line}: dp type missing from {e} in {cfg}",
             )
             )
             self.assertIsNotNone(
             self.assertIsNotNone(
                 dp._config.get("name"),
                 dp._config.get("name"),
-                f"\n{fname}:{line}: dp name missing from {e} in {cfg}",
+                f"\nERROR {fname}:{line}: dp name missing from {e} in {cfg}",
             )
             )
             extra.add(dp.name)
             extra.add(dp.name)
             mappings = dp._config.get("mapping", [])
             mappings = dp._config.get("mapping", [])
             self.assertIsInstance(
             self.assertIsInstance(
                 mappings,
                 mappings,
                 list,
                 list,
-                f"\n{fname}:{line}: mapping is not a list in {cfg}; entity {e}, dp {dp.name}",
+                f"\nERROR {fname}:{line}: mapping is not a list in {cfg}; entity {e}, dp {dp.name}",
             )
             )
             for m in mappings:
             for m in mappings:
                 line = m.__line__
                 line = m.__line__
@@ -445,7 +445,7 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
                 self.assertIsInstance(
                 self.assertIsInstance(
                     conditions,
                     conditions,
                     list,
                     list,
-                    f"\n{fname}:{line}: conditions is not a list in {cfg}; entity {e}, dp {dp.name}",
+                    f"\nERROR {fname}:{line}: conditions is not a list in {cfg}; entity {e}, dp {dp.name}",
                 )
                 )
                 for c in conditions:
                 for c in conditions:
                     if c.get("value_redirect"):
                     if c.get("value_redirect"):
@@ -463,7 +463,7 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
             self.assertIn(
             self.assertIn(
                 redirect,
                 redirect,
                 extra,
                 extra,
-                f"\n{fname}:{line}: dp {redirect} missing from {e} in {cfg}",
+                f"\nERROR {fname}:{line}: dp {redirect} missing from {e} in {cfg}",
             )
             )
 
 
         # Check dps that are required for this entity type all exist
         # Check dps that are required for this entity type all exist
@@ -471,13 +471,13 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
         for rule in expected["required"]:
         for rule in expected["required"]:
             self.assertTrue(
             self.assertTrue(
                 self.dp_match(rule, functions, extra, known, True),
                 self.dp_match(rule, functions, extra, known, True),
-                f"\n{fname}:{line}: {cfg} missing required {self.rule_broken_msg(rule)} in {e}",
+                f"\nERROR {fname}:{line}: {cfg} missing required {self.rule_broken_msg(rule)} in {e}",
             )
             )
 
 
         for rule in expected["optional"]:
         for rule in expected["optional"]:
             self.assertTrue(
             self.assertTrue(
                 self.dp_match(rule, functions, extra, known, False),
                 self.dp_match(rule, functions, extra, known, False),
-                f"\n{fname}:{line}: {cfg} expecting {self.rule_broken_msg(rule)} in {e}",
+                f"\nERROR {fname}:{line}: {cfg} expecting {self.rule_broken_msg(rule)} in {e}",
             )
             )
 
 
         # Check for potential typos in extra attributes
         # Check for potential typos in extra attributes
@@ -487,7 +487,7 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
                 self.assertLess(
                 self.assertLess(
                     fuzz.ratio(attr, dp),
                     fuzz.ratio(attr, dp),
                     85,
                     85,
-                    f"\n{fname}:{line}: Probable typo {attr} is too similar to {dp} in {cfg} {e}",
+                    f"\nERROR {fname}:{line}: Probable typo {attr} is too similar to {dp} in {cfg} {e}",
                 )
                 )
 
 
         # Check that sensors with mapped values are of class enum and vice versa
         # Check that sensors with mapped values are of class enum and vice versa
@@ -498,12 +498,12 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
                 self.assertEqual(
                 self.assertEqual(
                     entity.device_class,
                     entity.device_class,
                     SensorDeviceClass.ENUM,
                     SensorDeviceClass.ENUM,
-                    f"\n{fname}:{line}: {cfg} {e} has mapped values but does not have a device class of enum",
+                    f"\nERROR {fname}:{line}: {cfg} {e} has mapped values but does not have a device class of enum",
                 )
                 )
             if entity.device_class == SensorDeviceClass.ENUM:
             if entity.device_class == SensorDeviceClass.ENUM:
                 self.assertIsNotNone(
                 self.assertIsNotNone(
                     sensor.options,
                     sensor.options,
-                    f"\n{fname}:{line}: {cfg} {e} has a device class of enum, but has no mapped values",
+                    f"\nERROR {fname}:{line}: {cfg} {e} has a device class of enum, but has no mapped values",
                 )
                 )
 
 
     def test_config_files_parse(self):
     def test_config_files_parse(self):
@@ -521,24 +521,24 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
             try:
             try:
                 YAML_SCHEMA(parsed._config)
                 YAML_SCHEMA(parsed._config)
             except vol.MultipleInvalid as e:
             except vol.MultipleInvalid as e:
-                self.fail(f"\n{fname}:0: Validation error in {cfg}: {e}")
+                self.fail(f"\nERROR {fname}:0: Validation error in {cfg}: {e}")
 
 
             self.assertIsNotNone(
             self.assertIsNotNone(
                 parsed._config.get("name"),
                 parsed._config.get("name"),
-                f"\n{fname}:0: name missing from {cfg}",
+                f"\nERROR {fname}:0: name missing from {cfg}",
             )
             )
             count = 0
             count = 0
             for entity in parsed.all_entities():
             for entity in parsed.all_entities():
                 self.check_entity(entity, cfg)
                 self.check_entity(entity, cfg)
                 entities.append(entity.config_id)
                 entities.append(entity.config_id)
                 count += 1
                 count += 1
-            assert count > 0, f"\n{fname}:0: No entities found in {cfg}"
+            assert count > 0, f"\nERROR {fname}:0: No entities found in {cfg}"
 
 
             # check entities are unique
             # check entities are unique
             self.assertCountEqual(
             self.assertCountEqual(
                 entities,
                 entities,
                 set(entities),
                 set(entities),
-                f"\n{fname}:0: Duplicate entities in {cfg}",
+                f"\nERROR {fname}:0: Duplicate entities in {cfg}",
             )
             )
 
 
     def test_configs_can_be_matched(self):
     def test_configs_can_be_matched(self):
@@ -568,14 +568,14 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
             self.assertGreater(
             self.assertGreater(
                 len(required),
                 len(required),
                 0,
                 0,
-                msg=f"\n{fname}:0: No required dps found in {cfg}",
+                msg=f"\nERROR {fname}:0: No required dps found in {cfg}",
             )
             )
 
 
             for dp in required:
             for dp in required:
                 self.assertNotIn(
                 self.assertNotIn(
                     dp,
                     dp,
                     optional,
                     optional,
-                    msg=f"\n{fname}:0: Optional dp {dp} is required in {cfg}",
+                    msg=f"\nERROR {fname}:0: Optional dp {dp} is required in {cfg}",
                 )
                 )
 
 
     # Most of the device_config functionality is exercised during testing of
     # Most of the device_config functionality is exercised during testing of