android_test_mapping_format: Allow test config to have a `file_patterns` attribute
The value of the `file_patterns` attribute can only be a list of strings.
Bug: 121443061
Test: unitest
Change-Id: I5f64d6b2cf8ffd2a11b03c68a983dc7eecf91846
diff --git a/tools/android_test_mapping_format_unittest.py b/tools/android_test_mapping_format_unittest.py
index ffd1160..248786e 100755
--- a/tools/android_test_mapping_format_unittest.py
+++ b/tools/android_test_mapping_format_unittest.py
@@ -22,7 +22,7 @@
import android_test_mapping_format
-VALID_TEST_MAPPING = """
+VALID_TEST_MAPPING = r"""
{
"presubmit": [
{
@@ -38,7 +38,8 @@
{
"name": "CtsWindowManagerDeviceTestCases",
"host": true,
- "preferred_targets": ["a", "b"]
+ "preferred_targets": ["a", "b"],
+ "file_patterns": [".*\\.java"]
}
],
"imports": [
@@ -137,6 +138,17 @@
}
"""
+BAD_FILE_PATTERNS = """
+{
+ "presubmit": [
+ {
+ "name": "CtsWindowManagerDeviceTestCases",
+ "file_patterns": ["pattern", 123]
+ }
+ ]
+}
+"""
+
class AndroidTestMappingFormatTests(unittest.TestCase):
"""Unittest for android_test_mapping_format module."""
@@ -223,6 +235,15 @@
android_test_mapping_format.process_file,
self.test_mapping_file)
+ def test_invalid_test_mapping_file_patterns_value(self):
+ """Verify that file_patterns using wrong value can be detected."""
+ with open(self.test_mapping_file, 'w') as f:
+ f.write(BAD_FILE_PATTERNS)
+ self.assertRaises(
+ android_test_mapping_format.InvalidTestMappingError,
+ android_test_mapping_format.process_file,
+ self.test_mapping_file)
+
if __name__ == '__main__':
unittest.main()