android_test_mapping_format: Allow test config to have a `host` attribute
The value of the `host` attribute can only be true or false.
Bug: 116039282
Test: unitest
Change-Id: I5d865ef67b8faf7b3748883381b26062f4af4b61
diff --git a/tools/android_test_mapping_format.py b/tools/android_test_mapping_format.py
index 49725b3..c42fd61 100755
--- a/tools/android_test_mapping_format.py
+++ b/tools/android_test_mapping_format.py
@@ -32,6 +32,7 @@
NAME = 'name'
OPTIONS = 'options'
PATH = 'path'
+HOST = 'host'
class Error(Exception):
@@ -79,6 +80,11 @@
'Invalid test config in test mapping file %s. test config must '
'a `name` setting. Failed test config: %s' %
(test_mapping_file, test))
+ if not isinstance(test.get(HOST, False), bool):
+ raise InvalidTestMappingError(
+ 'Invalid test config in test mapping file %s. `host` setting in '
+ 'test config can only have boolean value of `true` or `false`. '
+ 'Failed test config: %s' % (test_mapping_file, test))
for option in test.get(OPTIONS, []):
if len(option) != 1:
raise InvalidTestMappingError(
diff --git a/tools/android_test_mapping_format_unittest.py b/tools/android_test_mapping_format_unittest.py
index d8a3167..3b88514 100755
--- a/tools/android_test_mapping_format_unittest.py
+++ b/tools/android_test_mapping_format_unittest.py
@@ -36,7 +36,8 @@
],
"postsubmit": [
{
- "name": "CtsWindowManagerDeviceTestCases"
+ "name": "CtsWindowManagerDeviceTestCases",
+ "host": true
}
],
"imports": [
@@ -60,7 +61,18 @@
{
"bad_name": "CtsWindowManagerDeviceTestCases",
}
- ],
+ ]
+}
+"""
+
+BAD_TEST_WRONG_HOST_VALUE = """
+{
+ "presubmit": [
+ {
+ "name": "CtsWindowManagerDeviceTestCases",
+ "host": "bad_value"
+ }
+ ]
}
"""
@@ -128,6 +140,15 @@
android_test_mapping_format.process_file,
self.test_mapping_file)
+ def test_invalid_test_mapping_wrong_test_value(self):
+ """Verify that test config using wrong host value can be detected."""
+ with open(self.test_mapping_file, 'w') as f:
+ f.write(BAD_TEST_WRONG_HOST_VALUE)
+ self.assertRaises(
+ android_test_mapping_format.InvalidTestMappingError,
+ android_test_mapping_format.process_file,
+ self.test_mapping_file)
+
def test_invalid_test_mapping_wrong_test_option(self):
"""Verify that test config using wrong option can be detected."""
with open(self.test_mapping_file, 'w') as f: