AIDEGen: add more test cases in project_info_unittest.py
Bug: 122495153
Test: 1. m aidegen
2. $ANDROID_HOST_OUT/bin/aidegen Settings
Open com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
Check all dependencies of org.robolectric are correct.
The source path packages/apps/SettingsIntelligence/src should
not exist.
3. $ANDROID_HOST_OUT/bin/aidegen frameworks/base
frameworks/base/services/tests/servicestests/src/com/android/server/pm/dex/PackageDexUsageTests.java
should exist.
4. ./run_tests.sh
All test cases passed!
Change-Id: I9926dfb153cc27fd439b9473c1d5f950985c35c7
diff --git a/aidegen/lib/project_info.py b/aidegen/lib/project_info.py
index 4277b34..5950506 100644
--- a/aidegen/lib/project_info.py
+++ b/aidegen/lib/project_info.py
@@ -37,14 +37,14 @@
'convert these files into blueprint format in the future, otherwise '
'AIDEGen may not be able to include all module dependencies.\nPlease visit '
'%s for reference on how to convert makefile.' % _CONVERT_MK_URL)
-_FILTER_CLASSES = {'APPS', 'JAVA_LIBRARIES', 'ROBOLECTRIC'}
+_FILTER_CLASSES = ['APPS', 'JAVA_LIBRARIES', 'ROBOLECTRIC']
_ROBOLECTRIC_MODULE = 'Robolectric_all'
_NOT_TARGET = ('Module %s\'s class setting is %s, none of which is included in '
'%s, skipping this module in the project.')
# The module fake-framework have the same package name with framework but empty
# content. It will impact the dependency for framework when referencing the
# package from fake-framework in IntelliJ.
-_EXCLUDE_MODULES = {'fake-framework'}
+_EXCLUDE_MODULES = ['fake-framework']
class ProjectInfo():
@@ -84,31 +84,38 @@
self.project_relative_path = rel_path
self.project_absolute_path = abs_path
self.iml_path = ''
- self._set_default_modue_and_init_source_path()
+ self._set_default_modues()
+ self._init_source_path()
self.dep_modules = self.get_dep_modules()
self._filter_out_modules()
self._display_convert_make_files_message(module_info, target)
- def _set_default_modue_and_init_source_path(self):
- """Append default hard-code modules, source paths and jar files."""
+ def _set_default_modues(self):
+ """Append default hard-code modules, source paths and jar files.
+
+ 1. framework: Framework module is always needed for dependencies but it
+ might not always be located by module dependency.
+ 2. org.apache.http.legacy.stubs.system: The module can't be located
+ through module dependency. Without it, a lot of java files will have
+ error of "cannot resolve symbol" in IntelliJ since they import
+ packages android.Manifest and com.android.internal.R.
+ """
# TODO(b/112058649): Do more research to clarify how to remove these
# hard-code sources.
self.project_module_names.update([
- # Framework module is always needed for dependencies but it might
- # not be located by module dependency.
'framework',
- # The module can't be located through module dependency. Without it,
- # a lot of java files will have errors "cannot resolve symbol" in
- # IntelliJ since they import packages android.Manifest and
- # com.android.internal.R.
'org.apache.http.legacy.stubs.system'
])
+
+ def _init_source_path(self):
+ """Initialize source_path dictionary."""
self.source_path = {
'source_folder_path': set(),
'test_folder_path': set(),
'jar_path': set()
}
+
def _display_convert_make_files_message(self, module_info, target):
"""Show message info users convert their Android.mk to Android.bp.
@@ -167,8 +174,7 @@
def _filter_out_modules(self):
"""Filter out unnecessary modules."""
- for module in _EXCLUDE_MODULES:
- self.dep_modules.pop(module, None)
+ map(self.dep_modules.pop, _EXCLUDE_MODULES)
def _is_relative_module(self, data):
"""Determine if the module is a relative module to this project.
@@ -202,7 +208,7 @@
"""
if not 'class' in data:
return False
- return set(data['class']).intersection(_FILTER_CLASSES)
+ return any(x in data['class'] for x in _FILTER_CLASSES)
@staticmethod
def _is_a_robolectric_module(data):
diff --git a/aidegen/lib/project_info_unittest.py b/aidegen/lib/project_info_unittest.py
index 7467efe..e3f5bb7 100644
--- a/aidegen/lib/project_info_unittest.py
+++ b/aidegen/lib/project_info_unittest.py
@@ -16,10 +16,15 @@
"""Unittests for source_locator."""
+import os
import unittest
from unittest import mock
+from aidegen import constant
from aidegen.lib import project_info
+from aidegen.lib.project_info import ProjectInfo
+
+import aidegen.unittest_constants as uc
_MODULE_INFO = {
'm1': {'class': ['JAVA_LIBRARIES'], 'dependencies': ['m2', 'm6'],
@@ -40,6 +45,7 @@
'm6': {'class': ['JAVA_LIBRARIES'], 'dependencies': ['m2'], 'depth': 1},
}
+
# pylint: disable=protected-access
# pylint: disable=invalid-name
class ProjectInfoUnittests(unittest.TestCase):
@@ -63,6 +69,54 @@
proj_info.dep_modules = proj_info.get_dep_modules()
self.assertEqual(proj_info.dep_modules, _EXPECT_DEPENDENT_MODULES)
+ def test_is_a_target_module(self):
+ """Test _is_a_target_module with different conditions."""
+ self.assertEqual(ProjectInfo._is_a_target_module({}), False)
+ self.assertEqual(ProjectInfo._is_a_target_module({'path': ''}), False)
+ self.assertEqual(ProjectInfo._is_a_target_module({'class': ''}), False)
+ self.assertEqual(
+ ProjectInfo._is_a_target_module({
+ 'class': ['APPS']
+ }), True)
+ self.assertEqual(
+ ProjectInfo._is_a_target_module({
+ 'class': ['JAVA_LIBRARIES']
+ }), True)
+ self.assertEqual(
+ ProjectInfo._is_a_target_module({
+ 'class': ['ROBOLECTRIC']
+ }), True)
+
+ def test_is_a_robolectric_module(self):
+ """Test _is_a_robolectric_module with different conditions."""
+ self.assertEqual(ProjectInfo._is_a_robolectric_module({}), False)
+ self.assertEqual(
+ ProjectInfo._is_a_robolectric_module({
+ 'path': [uc.TEST_PATH]
+ }), False)
+ self.assertEqual(
+ ProjectInfo._is_a_robolectric_module({
+ 'path': ['path/robotests']
+ }), True)
+ self.assertEqual(
+ ProjectInfo._is_a_robolectric_module({
+ 'path': ['path/robolectric']
+ }), True)
+ self.assertEqual(
+ ProjectInfo._is_a_robolectric_module({
+ 'path': ['robotests/robolectric']
+ }), True)
+
+ def test_get_target_name(self):
+ """Test _get_target_name with different conditions."""
+ constant.ANDROID_ROOT_PATH = uc.TEST_DATA_PATH
+ self.assertEqual(
+ ProjectInfo._get_target_name(uc.TEST_MODULE, uc.TEST_DATA_PATH),
+ os.path.basename(uc.TEST_DATA_PATH))
+ self.assertEqual(
+ ProjectInfo._get_target_name(uc.TEST_MODULE, uc.TEST_PATH),
+ uc.TEST_MODULE)
+
if __name__ == '__main__':
unittest.main()