Merge "AIDEGen: Use 'import module' instead of 'import method' in Python"
diff --git a/aidegen/aidegen_main.py b/aidegen/aidegen_main.py
index 89bf060..94601bc 100644
--- a/aidegen/aidegen_main.py
+++ b/aidegen/aidegen_main.py
@@ -46,24 +46,17 @@
import traceback
from aidegen import constant
-from aidegen.lib.android_dev_os import AndroidDevOS
+from aidegen.lib import aidegen_metrics
+from aidegen.lib import android_dev_os
from aidegen.lib import common_util
-from aidegen.lib.common_util import COLORED_INFO
-from aidegen.lib.common_util import COLORED_PASS
-from aidegen.lib.common_util import back_to_cwd
-from aidegen.lib.common_util import is_android_root
-from aidegen.lib.common_util import time_logged
-from aidegen.lib.errors import AIDEgenError
-from aidegen.lib.errors import IDENotExistError
-from aidegen.lib.ide_util import IdeUtil
-from aidegen.lib.aidegen_metrics import starts_asuite_metrics
-from aidegen.lib.aidegen_metrics import ends_asuite_metrics
-from aidegen.lib.module_info import AidegenModuleInfo
-from aidegen.lib.project_file_gen import ProjectFileGenerator
-from aidegen.lib.eclipse_project_file_gen import EclipseConf
-from aidegen.lib.project_info import ProjectInfo
+from aidegen.lib import eclipse_project_file_gen
+from aidegen.lib import errors
+from aidegen.lib import ide_util
+from aidegen.lib import module_info
from aidegen.lib import project_config
-from aidegen.lib.source_locator import multi_projects_locate_source
+from aidegen.lib import project_file_gen
+from aidegen.lib import project_info
+from aidegen.lib import source_locator
AIDEGEN_REPORT_LINK = ('To report the AIDEGen tool problem, please use this '
'link: https://goto.google.com/aidegen-bug')
@@ -74,7 +67,7 @@
or - specify "aidegen -n" to generate project file only
"""
-_CONGRATULATION = COLORED_PASS('CONGRATULATION:')
+_CONGRATULATION = common_util.COLORED_PASS('CONGRATULATION:')
_LAUNCH_SUCCESS_MSG = (
'IDE launched successfully. Please check your IDE window.')
_IDE_CACHE_REMINDER_MSG = (
@@ -87,9 +80,9 @@
'AIDEGen build time exceeds {} minute(s).\n'.format(_MAX_TIME),
project_config.SKIP_BUILD_INFO.rstrip('.'), ' in the future.'
])
-_INFO = COLORED_INFO('INFO:')
+_INFO = common_util.COLORED_INFO('INFO:')
_SKIP_MSG = _SKIP_BUILD_INFO_FUTURE.format(
- COLORED_INFO('aidegen [ module(s) ] -s'))
+ common_util.COLORED_INFO('aidegen [ module(s) ] -s'))
_TIME_EXCEED_MSG = '\n{} {}\n'.format(_INFO, _SKIP_MSG)
_LOG_FORMAT = '%(asctime)s %(filename)s:%(lineno)s:%(levelname)s: %(message)s'
_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
@@ -186,14 +179,15 @@
"""
if args.no_launch:
return None
- ide_util_obj = IdeUtil(args.ide_installed_path, args.ide[0],
- args.config_reset,
- AndroidDevOS.MAC == AndroidDevOS.get_os_type())
+ ide_util_obj = ide_util.IdeUtil(
+ args.ide_installed_path, args.ide[0], args.config_reset,
+ (android_dev_os.AndroidDevOS.MAC ==
+ android_dev_os.AndroidDevOS.get_os_type()))
if not ide_util_obj.is_ide_installed():
ipath = args.ide_installed_path or ide_util_obj.get_default_path()
err = _NO_LAUNCH_IDE_CMD.format(ipath)
logging.error(err)
- raise IDENotExistError(err)
+ raise errors.IDENotExistError(err)
return ide_util_obj
@@ -203,10 +197,12 @@
Args:
projects: A list of ProjectInfo instances.
"""
- if ProjectInfo.config.ide_name == constant.IDE_ECLIPSE:
- EclipseConf.generate_ide_project_files(projects)
+ if project_info.ProjectInfo.config.ide_name == constant.IDE_ECLIPSE:
+ eclipse_project_file_gen.EclipseConf.generate_ide_project_files(
+ projects)
else:
- ProjectFileGenerator.generate_ide_project_files(projects)
+ project_file_gen.ProjectFileGenerator.generate_ide_project_files(
+ projects)
def _compile_targets_for_whole_android_tree(atest_module_info, targets, cwd):
@@ -229,7 +225,7 @@
A list of targets after adjustment.
"""
new_targets = []
- if is_android_root(cwd):
+ if common_util.is_android_root(cwd):
new_targets = list(targets)
else:
for target in targets:
@@ -300,10 +296,11 @@
Returns:
A boolean, True when user is going to import whole Android tree.
"""
- return android_tree or (is_android_root(os.getcwd()) and targets == [''])
+ return (android_tree or
+ (common_util.is_android_root(os.getcwd()) and targets == ['']))
-@time_logged(message=_TIME_EXCEED_MSG, maximum=_MAX_TIME)
+@common_util.time_logged(message=_TIME_EXCEED_MSG, maximum=_MAX_TIME)
def main_with_message(args):
"""Main entry with skip build message.
@@ -313,7 +310,7 @@
aidegen_main(args)
-@time_logged
+@common_util.time_logged
def main_without_message(args):
"""Main entry without skip build message.
@@ -338,7 +335,7 @@
_configure_logging(args.verbose)
references = [constant.ANDROID_TREE] if _is_whole_android_tree(
args.targets, args.android_tree) else []
- starts_asuite_metrics(references)
+ aidegen_metrics.starts_asuite_metrics(references)
if args.skip_build:
main_without_message(args)
else:
@@ -346,7 +343,7 @@
except BaseException as err:
exit_code = constant.EXIT_CODE_EXCEPTION
_, exc_value, exc_traceback = sys.exc_info()
- if isinstance(err, AIDEgenError):
+ if isinstance(err, errors.AIDEgenError):
exit_code = constant.EXIT_CODE_AIDEGEN_EXCEPTION
# Filter out sys.Exit(0) case, which is not an exception case.
if isinstance(err, SystemExit) and exc_value.code == 0:
@@ -356,18 +353,19 @@
traceback_list = traceback.format_tb(exc_traceback)
traceback_list.append(error_message)
traceback_str = ''.join(traceback_list)
- ends_asuite_metrics(exit_code, traceback_str, error_message)
+ aidegen_metrics.ends_asuite_metrics(exit_code, traceback_str,
+ error_message)
# print out the trackback message for developers to debug
print(traceback_str)
raise err
finally:
if exit_code is constant.EXIT_CODE_NORMAL:
- ends_asuite_metrics(exit_code)
+ aidegen_metrics.ends_asuite_metrics(exit_code)
print('\n{0} {1}\n\n{0} {2}\n'.format(_INFO, AIDEGEN_REPORT_LINK,
_IDE_CACHE_REMINDER_MSG))
-@back_to_cwd
+@common_util.back_to_cwd
def aidegen_main(args):
"""AIDEGen main entry.
@@ -378,19 +376,19 @@
"""
# Pre-check for IDE relevant case, then handle dependency graph job.
ide_util_obj = _get_ide_util_instance(args)
- ProjectInfo.config = project_config.ProjectConfig(args)
+ project_info.ProjectInfo.config = project_config.ProjectConfig(args)
atest_module_info = common_util.get_atest_module_info(args.targets)
targets = _check_whole_android_tree(
atest_module_info, args.targets, args.android_tree)
- ProjectInfo.modules_info = AidegenModuleInfo(
+ project_info.ProjectInfo.modules_info = module_info.AidegenModuleInfo(
force_build=False,
module_file=None,
atest_module_info=atest_module_info,
projects=targets,
verbose=args.verbose,
skip_build=args.skip_build)
- projects = ProjectInfo.generate_projects(targets)
- multi_projects_locate_source(projects, args.verbose)
+ projects = project_info.ProjectInfo.generate_projects(targets)
+ source_locator.multi_projects_locate_source(projects, args.verbose)
_generate_project_files(projects)
if ide_util_obj:
_launch_ide(ide_util_obj, projects[0].project_absolute_path)
diff --git a/aidegen/aidegen_main_unittest.py b/aidegen/aidegen_main_unittest.py
index d2a78ef..c0a9b1e 100644
--- a/aidegen/aidegen_main_unittest.py
+++ b/aidegen/aidegen_main_unittest.py
@@ -24,15 +24,14 @@
import aidegen.unittest_constants as uc
from aidegen import aidegen_main
-from aidegen.lib import aidegen_metrics
from aidegen import constant
+from aidegen.lib import aidegen_metrics
from aidegen.lib import common_util
-from aidegen.lib.errors import IDENotExistError
-from aidegen.lib.errors import ProjectPathNotExistError
-from aidegen.lib.ide_util import IdeUtil
-from aidegen.lib.eclipse_project_file_gen import EclipseConf
-from aidegen.lib.project_info import ProjectInfo
-from aidegen.lib.project_file_gen import ProjectFileGenerator
+from aidegen.lib import eclipse_project_file_gen
+from aidegen.lib import errors
+from aidegen.lib import ide_util
+from aidegen.lib import project_file_gen
+from aidegen.lib import project_info
from atest import module_info
@@ -85,7 +84,7 @@
mock_log_config.called_with(
level=level, format=log_format, datefmt=datefmt))
- @mock.patch.object(IdeUtil, 'is_ide_installed')
+ @mock.patch.object(ide_util.IdeUtil, 'is_ide_installed')
def test_get_ide_util_instance(self, mock_installed):
"""Test _get_ide_util_instance with different conditions."""
target = 'tradefed'
@@ -93,18 +92,20 @@
self.assertEqual(aidegen_main._get_ide_util_instance(args), None)
args = aidegen_main._parse_args([target])
self.assertIsInstance(
- aidegen_main._get_ide_util_instance(args), IdeUtil)
+ aidegen_main._get_ide_util_instance(args), ide_util.IdeUtil)
mock_installed.return_value = False
- with self.assertRaises(IDENotExistError):
+ with self.assertRaises(errors.IDENotExistError):
aidegen_main._get_ide_util_instance(args)
@mock.patch('aidegen.lib.project_config.ProjectConfig')
- @mock.patch.object(ProjectFileGenerator, 'generate_ide_project_files')
- @mock.patch.object(EclipseConf, 'generate_ide_project_files')
+ @mock.patch.object(project_file_gen.ProjectFileGenerator,
+ 'generate_ide_project_files')
+ @mock.patch.object(eclipse_project_file_gen.EclipseConf,
+ 'generate_ide_project_files')
def test_generate_project_files(self, mock_eclipse, mock_ide, mock_config):
"""Test _generate_project_files with different conditions."""
projects = ['module_a', 'module_v']
- ProjectInfo.config = mock_config
+ project_info.ProjectInfo.config = mock_config
mock_config.ide_name = constant.IDE_ECLIPSE
aidegen_main._generate_project_files(projects)
self.assertTrue(mock_eclipse.called_with(projects))
@@ -121,9 +122,9 @@
"""Test main process always run through the target test function."""
target = 'nothing'
args = aidegen_main._parse_args([target, '-s', '-n'])
- with self.assertRaises(ProjectPathNotExistError):
+ with self.assertRaises(errors.ProjectPathNotExistError):
err = common_util.PATH_NOT_EXISTS_ERROR.format(target)
- mock_get.side_effect = ProjectPathNotExistError(err)
+ mock_get.side_effect = errors.ProjectPathNotExistError(err)
aidegen_main.main_without_message(args)
self.assertTrue(mock_metrics.called)
diff --git a/aidegen/lib/common_util.py b/aidegen/lib/common_util.py
index 305252c..9173685 100644
--- a/aidegen/lib/common_util.py
+++ b/aidegen/lib/common_util.py
@@ -29,10 +29,7 @@
from functools import wraps
from aidegen import constant
-from aidegen.lib.errors import FakeModuleError
-from aidegen.lib.errors import NoModuleDefinedInModuleInfoError
-from aidegen.lib.errors import ProjectOutsideAndroidRootError
-from aidegen.lib.errors import ProjectPathNotExistError
+from aidegen.lib import errors
from atest import constants
from atest import module_info
from atest.atest_utils import colorize
@@ -248,16 +245,16 @@
if not abs_path:
err = FAKE_MODULE_ERROR.format(target)
logging.error(err)
- raise FakeModuleError(err)
+ raise errors.FakeModuleError(err)
if not abs_path.startswith(get_android_root_dir()):
err = OUTSIDE_ROOT_ERROR.format(abs_path)
logging.error(err)
- raise ProjectOutsideAndroidRootError(err)
+ raise errors.ProjectOutsideAndroidRootError(err)
if not os.path.isdir(abs_path):
err = PATH_NOT_EXISTS_ERROR.format(rel_path)
if raise_on_lost_module:
logging.error(err)
- raise ProjectPathNotExistError(err)
+ raise errors.ProjectPathNotExistError(err)
logging.debug(_REBUILD_MODULE_INFO, err)
return False
if (not has_build_target(atest_module_info, rel_path)
@@ -265,7 +262,7 @@
err = NO_MODULE_DEFINED_ERROR.format(rel_path)
if raise_on_lost_module:
logging.error(err)
- raise NoModuleDefinedInModuleInfoError(err)
+ raise errors.NoModuleDefinedInModuleInfoError(err)
logging.debug(_REBUILD_MODULE_INFO, err)
return False
return True
diff --git a/aidegen/lib/common_util_unittest.py b/aidegen/lib/common_util_unittest.py
index 872c115..82e54fd 100644
--- a/aidegen/lib/common_util_unittest.py
+++ b/aidegen/lib/common_util_unittest.py
@@ -20,12 +20,9 @@
import unittest
from unittest import mock
-from aidegen.lib.errors import FakeModuleError
-from aidegen.lib.errors import NoModuleDefinedInModuleInfoError
-from aidegen.lib.errors import ProjectOutsideAndroidRootError
-from aidegen.lib.errors import ProjectPathNotExistError
-import aidegen.unittest_constants as uc
from aidegen.lib import common_util
+from aidegen.lib import errors
+from aidegen import unittest_constants
from atest import module_info
@@ -45,31 +42,34 @@
mock_get.return_value = []
mod_info = module_info.ModuleInfo()
self.assertEqual((None, None),
- common_util.get_related_paths(mod_info,
- uc.TEST_MODULE))
- mock_get_root.return_value = uc.TEST_PATH
- mock_get.return_value = [uc.TEST_MODULE]
- expected = (uc.TEST_MODULE, os.path.join(uc.TEST_PATH, uc.TEST_MODULE))
+ common_util.get_related_paths(
+ mod_info, unittest_constants.TEST_MODULE))
+ mock_get_root.return_value = unittest_constants.TEST_PATH
+ mock_get.return_value = [unittest_constants.TEST_MODULE]
+ expected = (unittest_constants.TEST_MODULE, os.path.join(
+ unittest_constants.TEST_PATH, unittest_constants.TEST_MODULE))
self.assertEqual(
- expected, common_util.get_related_paths(mod_info, uc.TEST_MODULE))
+ expected, common_util.get_related_paths(
+ mod_info, unittest_constants.TEST_MODULE))
mock_is_mod.return_value = False
mock_names.return_value = True
self.assertEqual(
- expected, common_util.get_related_paths(mod_info, uc.TEST_MODULE))
+ expected, common_util.get_related_paths(
+ mod_info, unittest_constants.TEST_MODULE))
@mock.patch.object(common_util, 'get_android_root_dir')
@mock.patch.object(common_util, 'get_related_paths')
def test_is_target_android_root(self, mock_get_rel, mock_get_root):
"""Test is_target_android_root with different conditions."""
- mock_get_rel.return_value = None, uc.TEST_PATH
- mock_get_root.return_value = uc.TEST_PATH
+ mock_get_rel.return_value = None, unittest_constants.TEST_PATH
+ mock_get_root.return_value = unittest_constants.TEST_PATH
self.assertTrue(
- common_util.is_target_android_root(module_info.ModuleInfo(),
- [uc.TEST_MODULE]))
+ common_util.is_target_android_root(
+ module_info.ModuleInfo(), [unittest_constants.TEST_MODULE]))
mock_get_rel.return_value = None, ''
self.assertFalse(
- common_util.is_target_android_root(module_info.ModuleInfo(),
- [uc.TEST_MODULE]))
+ common_util.is_target_android_root(
+ module_info.ModuleInfo(), [unittest_constants.TEST_MODULE]))
@mock.patch.object(common_util, 'get_android_root_dir')
@mock.patch.object(common_util, 'has_build_target')
@@ -80,29 +80,33 @@
"""Test if _check_module raises errors with different conditions."""
mod_info = module_info.ModuleInfo()
mock_get.return_value = None, None
- with self.assertRaises(FakeModuleError) as ctx:
- common_util._check_module(mod_info, uc.TEST_MODULE)
- expected = common_util.FAKE_MODULE_ERROR.format(uc.TEST_MODULE)
+ with self.assertRaises(errors.FakeModuleError) as ctx:
+ common_util._check_module(mod_info, unittest_constants.TEST_MODULE)
+ expected = common_util.FAKE_MODULE_ERROR.format(
+ unittest_constants.TEST_MODULE)
self.assertEqual(expected, str(ctx.exception))
- mock_get_root.return_value = uc.TEST_PATH
- mock_get.return_value = None, uc.TEST_MODULE
- with self.assertRaises(ProjectOutsideAndroidRootError) as ctx:
- common_util._check_module(mod_info, uc.TEST_MODULE)
- expected = common_util.OUTSIDE_ROOT_ERROR.format(uc.TEST_MODULE)
+ mock_get_root.return_value = unittest_constants.TEST_PATH
+ mock_get.return_value = None, unittest_constants.TEST_MODULE
+ with self.assertRaises(errors.ProjectOutsideAndroidRootError) as ctx:
+ common_util._check_module(mod_info, unittest_constants.TEST_MODULE)
+ expected = common_util.OUTSIDE_ROOT_ERROR.format(
+ unittest_constants.TEST_MODULE)
self.assertEqual(expected, str(ctx.exception))
- mock_get.return_value = None, uc.TEST_PATH
+ mock_get.return_value = None, unittest_constants.TEST_PATH
mock_isdir.return_value = False
- with self.assertRaises(ProjectPathNotExistError) as ctx:
- common_util._check_module(mod_info, uc.TEST_MODULE)
- expected = common_util.PATH_NOT_EXISTS_ERROR.format(uc.TEST_MODULE)
+ with self.assertRaises(errors.ProjectPathNotExistError) as ctx:
+ common_util._check_module(mod_info, unittest_constants.TEST_MODULE)
+ expected = common_util.PATH_NOT_EXISTS_ERROR.format(
+ unittest_constants.TEST_MODULE)
self.assertEqual(expected, str(ctx.exception))
mock_isdir.return_value = True
mock_has_target.return_value = False
- mock_get.return_value = None, os.path.join(uc.TEST_PATH, 'test.jar')
- with self.assertRaises(NoModuleDefinedInModuleInfoError) as ctx:
- common_util._check_module(mod_info, uc.TEST_MODULE)
+ mock_get.return_value = None, os.path.join(unittest_constants.TEST_PATH,
+ 'test.jar')
+ with self.assertRaises(errors.NoModuleDefinedInModuleInfoError) as ctx:
+ common_util._check_module(mod_info, unittest_constants.TEST_MODULE)
expected = common_util.NO_MODULE_DEFINED_ERROR.format(
- uc.TEST_MODULE)
+ unittest_constants.TEST_MODULE)
self.assertEqual(expected, str(ctx.exception))
self.assertEqual(common_util._check_module(mod_info, '', False), False)
self.assertEqual(common_util._check_module(mod_info, 'nothing', False),
@@ -124,9 +128,10 @@
@mock.patch.object(common_util, 'get_android_root_dir')
def test_get_abs_path(self, mock_get_root):
"""Test get_abs_path handling."""
- mock_get_root.return_value = uc.TEST_DATA_PATH
- self.assertEqual(uc.TEST_DATA_PATH, common_util.get_abs_path(''))
- test_path = os.path.join(uc.TEST_DATA_PATH, 'test.jar')
+ mock_get_root.return_value = unittest_constants.TEST_DATA_PATH
+ self.assertEqual(unittest_constants.TEST_DATA_PATH,
+ common_util.get_abs_path(''))
+ test_path = os.path.join(unittest_constants.TEST_DATA_PATH, 'test.jar')
self.assertEqual(test_path, common_util.get_abs_path(test_path))
self.assertEqual(test_path, common_util.get_abs_path('test.jar'))
diff --git a/aidegen/lib/eclipse_project_file_gen.py b/aidegen/lib/eclipse_project_file_gen.py
index 5c45d97..cc5052e 100644
--- a/aidegen/lib/eclipse_project_file_gen.py
+++ b/aidegen/lib/eclipse_project_file_gen.py
@@ -20,10 +20,10 @@
from aidegen import constant
from aidegen.lib import common_util
-from aidegen.lib.project_file_gen import ProjectFileGenerator
+from aidegen.lib import project_file_gen
-class EclipseConf(ProjectFileGenerator):
+class EclipseConf(project_file_gen.ProjectFileGenerator):
"""Class to generate project file under the module path for Eclipse.
Attributes:
diff --git a/aidegen/lib/eclipse_project_file_gen_unittest.py b/aidegen/lib/eclipse_project_file_gen_unittest.py
index 5c0456d..ff78226 100644
--- a/aidegen/lib/eclipse_project_file_gen_unittest.py
+++ b/aidegen/lib/eclipse_project_file_gen_unittest.py
@@ -20,10 +20,10 @@
import unittest
from unittest import mock
-import aidegen.unittest_constants as utc
from aidegen import constant
+from aidegen import unittest_constants
from aidegen.lib import common_util
-from aidegen.lib.eclipse_project_file_gen import EclipseConf
+from aidegen.lib import eclipse_project_file_gen
# pylint: disable=protected-access
@@ -35,7 +35,8 @@
_PROJECT_NAME = 'test'
_LINK_TEMPLATE = (' <link><name>%s</name><type>2</type>'
'<location>%s</location></link>\n')
- _PROJECT_SAMPLE = os.path.join(utc.TEST_DATA_PATH, 'eclipse.project')
+ _PROJECT_SAMPLE = os.path.join(unittest_constants.TEST_DATA_PATH,
+ 'eclipse.project')
@mock.patch.object(common_util, 'get_android_root_dir')
def test_gen_link(self, mock_get_root):
@@ -43,7 +44,8 @@
mock_get_root.return_value = self._ROOT_PATH
name = os.path.join(constant.KEY_DEPENDENCIES, self._PROJECT_RELPATH)
expected_link = self._LINK_TEMPLATE % (name, self._PROJECT_ABSPATH)
- generated_link = EclipseConf._gen_link(self._PROJECT_RELPATH)
+ generated_link = eclipse_project_file_gen.EclipseConf._gen_link(
+ self._PROJECT_RELPATH)
self.assertEqual(generated_link, expected_link)
@mock.patch.object(common_util, 'get_android_root_dir')
@@ -62,7 +64,7 @@
'r_java_path': set()
}
expected_content = common_util.read_file_content(self._PROJECT_SAMPLE)
- eclipse_config = EclipseConf(mock_project_info)
+ eclipse_config = eclipse_project_file_gen.EclipseConf(mock_project_info)
eclipse_config._create_project_content()
generated_content = eclipse_config.project_content
self.assertEqual(generated_content, expected_content)
@@ -88,7 +90,7 @@
' <classpathentry kind="src" path="src"/>\n',
' <classpathentry kind="src" path="test"/>\n',
]
- eclipse_config = EclipseConf(mock_project_info)
+ eclipse_config = eclipse_project_file_gen.EclipseConf(mock_project_info)
generated_result = sorted(eclipse_config._gen_src_path_entries())
self.assertEqual(generated_result, expected_result)
@@ -113,7 +115,7 @@
'path="/abspath/to/the/file.jar" '
'sourcepath="dependencies/relpath/to/the/module"/>\n')
]
- eclipse_config = EclipseConf(mock_project_info)
+ eclipse_config = eclipse_project_file_gen.EclipseConf(mock_project_info)
generated_result = eclipse_config._gen_jar_path_entries()
self.assertEqual(generated_result, expected_result)
diff --git a/aidegen/lib/ide_util_unittest.py b/aidegen/lib/ide_util_unittest.py
index 9e2d518..b9dce3a 100644
--- a/aidegen/lib/ide_util_unittest.py
+++ b/aidegen/lib/ide_util_unittest.py
@@ -19,28 +19,16 @@
import os
import shutil
+import subprocess
import tempfile
import unittest
from unittest import mock
-from unittest.mock import patch
-from subprocess import CalledProcessError as cmd_err
-from aidegen.lib.android_dev_os import AndroidDevOS
+from aidegen import unittest_constants
+from aidegen.lib import android_dev_os
from aidegen.lib import ide_util
from aidegen.lib import sdk_config
-from aidegen.lib.ide_util import IdeBase
-from aidegen.lib.ide_util import IdeIntelliJ
-from aidegen.lib.ide_util import IdeLinuxEclipse
-from aidegen.lib.ide_util import IdeLinuxIntelliJ
-from aidegen.lib.ide_util import IdeLinuxStudio
-from aidegen.lib.ide_util import IdeMacEclipse
-from aidegen.lib.ide_util import IdeMacIntelliJ
-from aidegen.lib.ide_util import IdeMacStudio
-from aidegen.lib.ide_util import IdeUtil
-
-
-import aidegen.unittest_constants as uc
#pylint: disable=protected-access
@@ -53,19 +41,17 @@
_TEST_PRJ_PATH4 = ''
_MODULE_XML_SAMPLE = ''
-
def setUp(self):
"""Prepare the testdata related path."""
- IdeUtilUnittests._TEST_PRJ_PATH1 = os.path.join(uc.TEST_DATA_PATH,
- 'android_facet.iml')
- IdeUtilUnittests._TEST_PRJ_PATH2 = os.path.join(uc.TEST_DATA_PATH,
- 'project/test.java')
- IdeUtilUnittests._TEST_PRJ_PATH3 = uc.TEST_DATA_PATH
- IdeUtilUnittests._TEST_PRJ_PATH4 = os.path.join(uc.TEST_DATA_PATH,
- '.idea')
- IdeUtilUnittests._MODULE_XML_SAMPLE = os.path.join(uc.TEST_DATA_PATH,
- 'modules.xml')
-
+ IdeUtilUnittests._TEST_PRJ_PATH1 = os.path.join(
+ unittest_constants.TEST_DATA_PATH, 'android_facet.iml')
+ IdeUtilUnittests._TEST_PRJ_PATH2 = os.path.join(
+ unittest_constants.TEST_DATA_PATH, 'project/test.java')
+ IdeUtilUnittests._TEST_PRJ_PATH3 = unittest_constants.TEST_DATA_PATH
+ IdeUtilUnittests._TEST_PRJ_PATH4 = os.path.join(
+ unittest_constants.TEST_DATA_PATH, '.idea')
+ IdeUtilUnittests._MODULE_XML_SAMPLE = os.path.join(
+ unittest_constants.TEST_DATA_PATH, 'modules.xml')
def tearDown(self):
"""Clear the testdata related path."""
@@ -85,39 +71,43 @@
self.assertFalse(
ide_util._is_intellij_project(IdeUtilUnittests._TEST_PRJ_PATH4))
- @mock.patch('glob.glob', return_value=uc.IDEA_SH_FIND_NONE)
+ @mock.patch('glob.glob', return_value=unittest_constants.IDEA_SH_FIND_NONE)
def test_get_intellij_sh_none(self, mock_glob):
"""Test with the cmd return none, test result should be None."""
- mock_glob.return_value = uc.IDEA_SH_FIND_NONE
+ mock_glob.return_value = unittest_constants.IDEA_SH_FIND_NONE
self.assertEqual(
None,
- ide_util._get_intellij_version_path(IdeLinuxIntelliJ()._ls_ce_path))
+ ide_util._get_intellij_version_path(
+ ide_util.IdeLinuxIntelliJ()._ls_ce_path))
self.assertEqual(
None,
- ide_util._get_intellij_version_path(IdeLinuxIntelliJ()._ls_ue_path))
+ ide_util._get_intellij_version_path(
+ ide_util.IdeLinuxIntelliJ()._ls_ue_path))
@mock.patch('builtins.input')
- @mock.patch('glob.glob', return_value=uc.IDEA_SH_FIND)
+ @mock.patch('glob.glob', return_value=unittest_constants.IDEA_SH_FIND)
def test_ask_preference(self, mock_glob, mock_input):
"""Ask users' preference, the result should be equal to test data."""
- mock_glob.return_value = uc.IDEA_SH_FIND
+ mock_glob.return_value = unittest_constants.IDEA_SH_FIND
mock_input.return_value = '1'
self.assertEqual(
- ide_util._ask_preference(uc.IDEA_SH_FIND), uc.IDEA_SH_FIND[0])
+ ide_util._ask_preference(unittest_constants.IDEA_SH_FIND),
+ unittest_constants.IDEA_SH_FIND[0])
mock_input.return_value = '2'
self.assertEqual(
- ide_util._ask_preference(uc.IDEA_SH_FIND), uc.IDEA_SH_FIND[1])
+ ide_util._ask_preference(unittest_constants.IDEA_SH_FIND),
+ unittest_constants.IDEA_SH_FIND[1])
@unittest.skip('Skip to use real command to launch IDEA.')
def test_run_intellij_sh_in_linux(self):
"""Follow the target behavior, with sh to show UI, else raise err."""
- sh_path = IdeLinuxIntelliJ()._get_script_from_system()
+ sh_path = ide_util.IdeLinuxIntelliJ()._get_script_from_system()
if sh_path:
- ide_util_obj = IdeUtil()
+ ide_util_obj = ide_util.IdeUtil()
ide_util_obj.config_ide(IdeUtilUnittests._TEST_PRJ_PATH1)
ide_util_obj.launch_ide()
else:
- self.assertRaises(cmd_err)
+ self.assertRaises(subprocess.CalledProcessError)
@mock.patch.object(ide_util, '_get_linux_ide')
@mock.patch.object(ide_util, '_get_mac_ide')
@@ -130,32 +120,35 @@
def test_get_mac_and_linux_ide(self):
"""Test if _get_mac_ide and _get_linux_ide return correct IDE class."""
- self.assertIsInstance(ide_util._get_mac_ide(), IdeMacIntelliJ)
- self.assertIsInstance(ide_util._get_mac_ide(None, 's'), IdeMacStudio)
- self.assertIsInstance(ide_util._get_mac_ide(None, 'e'), IdeMacEclipse)
- self.assertIsInstance(ide_util._get_linux_ide(), IdeLinuxIntelliJ)
+ self.assertIsInstance(ide_util._get_mac_ide(), ide_util.IdeMacIntelliJ)
+ self.assertIsInstance(ide_util._get_mac_ide(None, 's'),
+ ide_util.IdeMacStudio)
+ self.assertIsInstance(ide_util._get_mac_ide(None, 'e'),
+ ide_util.IdeMacEclipse)
+ self.assertIsInstance(ide_util._get_linux_ide(),
+ ide_util.IdeLinuxIntelliJ)
self.assertIsInstance(
- ide_util._get_linux_ide(None, 's'), IdeLinuxStudio)
+ ide_util._get_linux_ide(None, 's'), ide_util.IdeLinuxStudio)
self.assertIsInstance(
- ide_util._get_linux_ide(None, 'e'), IdeLinuxEclipse)
+ ide_util._get_linux_ide(None, 'e'), ide_util.IdeLinuxEclipse)
@mock.patch.object(ide_util, '_get_script_from_input_path')
- @mock.patch.object(IdeIntelliJ, '_get_script_from_system')
+ @mock.patch.object(ide_util.IdeIntelliJ, '_get_script_from_system')
def test_init_ideintellij(self, mock_sys, mock_input):
"""Test IdeIntelliJ's __init__ method."""
- IdeLinuxIntelliJ()
+ ide_util.IdeLinuxIntelliJ()
self.assertTrue(mock_sys.called)
- IdeMacIntelliJ()
+ ide_util.IdeMacIntelliJ()
self.assertTrue(mock_sys.called)
- IdeLinuxIntelliJ('some_path')
+ ide_util.IdeLinuxIntelliJ('some_path')
self.assertTrue(mock_input.called)
- IdeMacIntelliJ('some_path')
+ ide_util.IdeMacIntelliJ('some_path')
self.assertTrue(mock_input.called)
@mock.patch.object(sdk_config.SDKConfig, '_android_sdk_exists')
@mock.patch.object(sdk_config.SDKConfig, '_target_jdk_exists')
- @mock.patch.object(IdeIntelliJ, '_get_config_root_paths')
- @mock.patch.object(IdeBase, 'apply_optional_config')
+ @mock.patch.object(ide_util.IdeIntelliJ, '_get_config_root_paths')
+ @mock.patch.object(ide_util.IdeBase, 'apply_optional_config')
def test_config_ide(self, mock_config, mock_paths, mock_jdk, mock_sdk):
"""Test IDEA, IdeUtil.config_ide won't call base none implement api."""
# Mock SDkConfig flow to not to generate real jdk config file.
@@ -167,73 +160,79 @@
os.makedirs(idea_path)
shutil.copy(IdeUtilUnittests._MODULE_XML_SAMPLE, idea_path)
try:
- util_obj = IdeUtil()
+ util_obj = ide_util.IdeUtil()
util_obj.config_ide(module_path)
self.assertFalse(mock_config.called)
self.assertFalse(mock_paths.called)
finally:
shutil.rmtree(test_path)
- @patch.object(ide_util, '_get_script_from_input_path')
- @patch.object(ide_util, '_get_script_from_internal_path')
+ @mock.patch.object(ide_util, '_get_script_from_input_path')
+ @mock.patch.object(ide_util, '_get_script_from_internal_path')
def test_get_linux_config_1(self, mock_path, mock_path_2):
"""Test to get unique config path for linux IDEA case."""
- if not AndroidDevOS.MAC == AndroidDevOS.get_os_type():
+ if (not android_dev_os.AndroidDevOS.MAC ==
+ android_dev_os.AndroidDevOS.get_os_type()):
mock_path.return_value = '/opt/intelliJ-ce-2018.3/bin/idea.sh'
mock_path_2.return_value = '/opt/intelliJ-ce-2018.3/bin/idea.sh'
- ide_obj = IdeLinuxIntelliJ()
+ ide_obj = ide_util.IdeLinuxIntelliJ()
self.assertEqual(1, len(ide_obj._get_config_root_paths()))
else:
- self.assertTrue(AndroidDevOS.MAC == AndroidDevOS.get_os_type())
+ self.assertTrue((android_dev_os.AndroidDevOS.MAC ==
+ android_dev_os.AndroidDevOS.get_os_type()))
- @patch('glob.glob')
- @patch.object(ide_util, '_get_script_from_input_path')
- @patch.object(ide_util, '_get_script_from_internal_path')
+ @mock.patch('glob.glob')
+ @mock.patch.object(ide_util, '_get_script_from_input_path')
+ @mock.patch.object(ide_util, '_get_script_from_internal_path')
def test_get_linux_config_2(self, mock_path, mock_path_2, mock_filter):
"""Test to get unique config path for linux IDEA case."""
- if not AndroidDevOS.MAC == AndroidDevOS.get_os_type():
+ if (not android_dev_os.AndroidDevOS.MAC ==
+ android_dev_os.AndroidDevOS.get_os_type()):
mock_path.return_value = '/opt/intelliJ-ce-2018.3/bin/idea.sh'
mock_path_2.return_value = '/opt/intelliJ-ce-2018.3/bin/idea.sh'
- ide_obj = IdeLinuxIntelliJ()
+ ide_obj = ide_util.IdeLinuxIntelliJ()
mock_filter.called = False
ide_obj._get_config_root_paths()
self.assertFalse(mock_filter.called)
else:
- self.assertTrue(AndroidDevOS.MAC == AndroidDevOS.get_os_type())
+ self.assertTrue((android_dev_os.AndroidDevOS.MAC ==
+ android_dev_os.AndroidDevOS.get_os_type()))
def test_get_mac_config_root_paths(self):
"""Return None if there's no install path."""
- if AndroidDevOS.MAC == AndroidDevOS.get_os_type():
- mac_ide = IdeMacIntelliJ()
+ if (android_dev_os.AndroidDevOS.MAC ==
+ android_dev_os.AndroidDevOS.get_os_type()):
+ mac_ide = ide_util.IdeMacIntelliJ()
mac_ide._installed_path = None
self.assertIsNone(mac_ide._get_config_root_paths())
else:
- self.assertFalse(AndroidDevOS.MAC == AndroidDevOS.get_os_type())
+ self.assertFalse((android_dev_os.AndroidDevOS.MAC ==
+ android_dev_os.AndroidDevOS.get_os_type()))
- @patch('glob.glob')
- @patch.object(ide_util, '_get_script_from_input_path')
- @patch.object(ide_util, '_get_script_from_internal_path')
+ @mock.patch('glob.glob')
+ @mock.patch.object(ide_util, '_get_script_from_input_path')
+ @mock.patch.object(ide_util, '_get_script_from_internal_path')
def test_get_linux_config_root(self, mock_path_1, mock_path_2, mock_filter):
"""Test to go filter logic for self download case."""
mock_path_1.return_value = '/usr/tester/IDEA/IC2018.3.3/bin'
mock_path_2.return_value = '/usr/tester/IDEA/IC2018.3.3/bin'
- ide_obj = IdeLinuxIntelliJ()
+ ide_obj = ide_util.IdeLinuxIntelliJ()
mock_filter.reset()
ide_obj._get_config_root_paths()
self.assertTrue(mock_filter.called)
- @patch('os.path.join')
+ @mock.patch('os.path.join')
def test_get_code_style_config(self, mock_join_path):
"""Test return None, when no config source case existed."""
mock_join_path.return_value = '/usr/tester/no_file.test'
self.assertIsNone(ide_util.IdeIntelliJ._get_code_style_config())
- @patch('shutil.copy2')
- @patch.object(IdeIntelliJ, '_get_code_style_config')
+ @mock.patch('shutil.copy2')
+ @mock.patch.object(ide_util.IdeIntelliJ, '_get_code_style_config')
def test_apply_optional_config(self, mock_config_path, mock_copy):
"""Test copy logic should not work if there's no config source."""
mock_config_path.return_value = None
- ide_obj = IdeIntelliJ()
+ ide_obj = ide_util.IdeIntelliJ()
ide_obj.apply_optional_config()
self.assertFalse(mock_copy.called)
diff --git a/aidegen/lib/module_info.py b/aidegen/lib/module_info.py
index 2676231..244ddf4 100644
--- a/aidegen/lib/module_info.py
+++ b/aidegen/lib/module_info.py
@@ -23,10 +23,10 @@
from aidegen import constant
from aidegen.lib import common_util
from aidegen.lib import module_info_util
-from atest.module_info import ModuleInfo
+from atest import module_info
-class AidegenModuleInfo(ModuleInfo):
+class AidegenModuleInfo(module_info.ModuleInfo):
"""Class that offers fast/easy lookup for Module related details.
Class attributes:
diff --git a/aidegen/lib/module_info_util_unittest.py b/aidegen/lib/module_info_util_unittest.py
index 290e8bc..d32bfcf 100644
--- a/aidegen/lib/module_info_util_unittest.py
+++ b/aidegen/lib/module_info_util_unittest.py
@@ -22,7 +22,7 @@
import unittest
from unittest import mock
-import aidegen.unittest_constants as uc
+from aidegen import unittest_constants
from aidegen.lib import errors
from aidegen.lib import module_info_util
from atest import module_info
@@ -135,7 +135,8 @@
mock_copy.return_value = ''
amodule_info = module_info.ModuleInfo()
cmd = [module_info_util._GENERATE_JSON_COMMAND]
- module_info_util._build_target(amodule_info, cmd, uc.TEST_MODULE, True)
+ module_info_util._build_target(amodule_info, cmd,
+ unittest_constants.TEST_MODULE, True)
self.assertTrue(mock_copy.called)
self.assertTrue(mock_check_call.called)
mock_check_call.assert_called_with(
@@ -143,7 +144,8 @@
stderr=subprocess.STDOUT,
env=mock_copy.return_value,
shell=True)
- module_info_util._build_target(amodule_info, cmd, uc.TEST_MODULE, False)
+ module_info_util._build_target(amodule_info, cmd,
+ unittest_constants.TEST_MODULE, False)
self.assertTrue(mock_check_call.called)
mock_check_call.assert_called_with(cmd, shell=True)
@@ -179,11 +181,13 @@
mock_glob.return_value = ['project/file.iml']
mock_input.return_value = 'N'
with self.assertRaises(SystemExit) as cm:
- module_info_util._build_failed_handle(uc.TEST_MODULE)
+ module_info_util._build_failed_handle(
+ unittest_constants.TEST_MODULE)
self.assertEqual(cm.exception.code, 1)
mock_glob.return_value = []
with self.assertRaises(errors.BuildFailureError):
- module_info_util._build_failed_handle(uc.TEST_MODULE)
+ module_info_util._build_failed_handle(
+ unittest_constants.TEST_MODULE)
@mock.patch('builtins.open')
def test_get_soong_build_json_dict_failed(self, mock_open):
diff --git a/aidegen/lib/project_config.py b/aidegen/lib/project_config.py
index e81bb36..7bf4ecf 100644
--- a/aidegen/lib/project_config.py
+++ b/aidegen/lib/project_config.py
@@ -17,7 +17,7 @@
"""Project config class."""
from aidegen import constant
-from aidegen.lib.common_util import COLORED_INFO
+from aidegen.lib import common_util
SKIP_BUILD_INFO = ('If you are sure the related modules and dependencies have '
'been already built, please try to use command {} to skip '
@@ -54,9 +54,9 @@
"""Display different messages if users skip building targets or not."""
if self.is_skip_build:
print('\n{} {}\n'.format(
- COLORED_INFO('Warning:'), _SKIP_BUILD_WARN))
+ common_util.COLORED_INFO('Warning:'), _SKIP_BUILD_WARN))
else:
msg = SKIP_BUILD_INFO.format(
- COLORED_INFO(
+ common_util.COLORED_INFO(
_SKIP_BUILD_CMD.format(' '.join(self.targets))))
- print('\n{} {}\n'.format(COLORED_INFO('INFO:'), msg))
+ print('\n{} {}\n'.format(common_util.COLORED_INFO('INFO:'), msg))
diff --git a/aidegen/lib/project_file_gen.py b/aidegen/lib/project_file_gen.py
index f72c32b..06edfa7 100644
--- a/aidegen/lib/project_file_gen.py
+++ b/aidegen/lib/project_file_gen.py
@@ -41,7 +41,7 @@
_END_CONTENT = ' </content>\n'
_SRCJAR_URL = ('%s<content url="jar://{SRCJAR}">\n'
'%s<sourceFolder url="jar://{SRCJAR}" isTestSource="False" />\n'
- '%s</content>\n') % (' ' * 8, ' ' * 12, ' ' * 8)
+ '%s</content>') % (' ' * 8, ' ' * 12, ' ' * 8)
_ORDER_ENTRY = (' <orderEntry type="module-library" exported="">'
'<library><CLASSES><root url="jar://%s!/" /></CLASSES>'
'<JAVADOC /><SOURCES /></library></orderEntry>\n')
@@ -91,7 +91,7 @@
_CODE_STYLE_REL_PATH)
-class ProjectFileGenerator():
+class ProjectFileGenerator:
"""Project file generator.
Class attributes:
@@ -418,7 +418,9 @@
for srcjar_dir in srcjar_paths:
srcjar_urls.append(_SRCJAR_URL.format(SRCJAR=os.path.join(
common_util.get_android_root_dir(), srcjar_dir)))
- return content.replace(_SRCJAR_TOKEN, ''.join(srcjar_urls))
+ if srcjar_urls:
+ return content.replace(_SRCJAR_TOKEN, '\n'.join(srcjar_urls))
+ return content.replace(_SRCJAR_TOKEN + '\n', '')
# pylint: disable=too-many-locals
def _generate_iml(self, source_dict, is_main_module=False):
diff --git a/aidegen/lib/project_file_gen_unittest.py b/aidegen/lib/project_file_gen_unittest.py
index 212f14e..4533c8a 100644
--- a/aidegen/lib/project_file_gen_unittest.py
+++ b/aidegen/lib/project_file_gen_unittest.py
@@ -22,11 +22,10 @@
import unittest
from unittest import mock
-import aidegen.unittest_constants as uc
from aidegen import constant
+from aidegen import unittest_constants
from aidegen.lib import common_util
from aidegen.lib import project_file_gen
-from aidegen.lib.project_file_gen import ProjectFileGenerator
from atest import module_info
@@ -35,7 +34,8 @@
"""Unit tests for project_file_gen.py."""
maxDiff = None
- _TEST_DATA_PATH = uc.TEST_DATA_PATH
+ _TEST_DATA_PATH = unittest_constants.TEST_DATA_PATH
+ _ANDROID_PROJECT_PATH = unittest_constants.ANDROID_PROJECT_PATH
_PROJECT_PATH = os.path.join(_TEST_DATA_PATH, 'project')
_ANDROID_FACET_SAMPLE = os.path.join(_TEST_DATA_PATH, 'android_facet.iml')
_PROJECT_FACET_SAMPLE = os.path.join(_TEST_DATA_PATH, 'project_facet.iml')
@@ -48,10 +48,10 @@
_ENABLE_DEBUGGER_MODULE_SAMPLE = os.path.join(
_TEST_DATA_PATH, 'modules_with_enable_debugger.xml')
_VCS_XML_SAMPLE = os.path.join(_TEST_DATA_PATH, 'vcs.xml')
- _IML_PATH = os.path.join(uc.ANDROID_PROJECT_PATH, 'android_project.iml')
- _DEPENDENCIES_IML_PATH = os.path.join(uc.ANDROID_PROJECT_PATH,
+ _IML_PATH = os.path.join(_ANDROID_PROJECT_PATH, 'android_project.iml')
+ _DEPENDENCIES_IML_PATH = os.path.join(_ANDROID_PROJECT_PATH,
'dependencies.iml')
- _IDEA_PATH = os.path.join(uc.ANDROID_PROJECT_PATH, '.idea')
+ _IDEA_PATH = os.path.join(_ANDROID_PROJECT_PATH, '.idea')
_MODULE_PATH = os.path.join(_IDEA_PATH, 'modules.xml')
_VCS_PATH = os.path.join(_IDEA_PATH, 'vcs.xml')
_SOURCE_SAMPLE = os.path.join(_TEST_DATA_PATH, 'source.iml')
@@ -74,9 +74,9 @@
@mock.patch('aidegen.lib.project_info.ProjectInfo')
def test_handle_facet_for_android(self, mock_project):
"""Test _handle_facet with android project."""
- mock_project.project_absolute_path = uc.ANDROID_PROJECT_PATH
- android_facet = ProjectFileGenerator(mock_project)._handle_facet(
- constant.FILE_IML)
+ mock_project.project_absolute_path = self._ANDROID_PROJECT_PATH
+ android_facet = project_file_gen.ProjectFileGenerator(
+ mock_project)._handle_facet(constant.FILE_IML)
sample_android_facet = common_util.read_file_content(
self._ANDROID_FACET_SAMPLE)
self.assertEqual(android_facet, sample_android_facet)
@@ -85,8 +85,8 @@
def test_handle_facet_for_normal(self, mock_project):
"""Test _handle_facet with normal module."""
mock_project.project_absolute_path = self._PROJECT_PATH
- project_facet = ProjectFileGenerator(mock_project)._handle_facet(
- constant.FILE_IML)
+ project_facet = project_file_gen.ProjectFileGenerator(
+ mock_project)._handle_facet(constant.FILE_IML)
sample_project_facet = common_util.read_file_content(
self._PROJECT_FACET_SAMPLE)
self.assertEqual(project_facet, sample_project_facet)
@@ -111,8 +111,10 @@
"""Test _handle_source_folder."""
mock_get_root.return_value = self._AOSP_FOLDER
mock_project.project_relative_path = self._ANDROID_SOURCE_RELATIVE_PATH
- source = ProjectFileGenerator(mock_project)._handle_source_folder(
- constant.FILE_IML, copy.deepcopy(uc.ANDROID_SOURCE_DICT), True)
+ source = project_file_gen.ProjectFileGenerator(
+ mock_project)._handle_source_folder(
+ constant.FILE_IML, copy.deepcopy(
+ unittest_constants.ANDROID_SOURCE_DICT), True)
sample_source = common_util.read_file_content(self._SOURCE_SAMPLE)
self.assertEqual(source, sample_source)
@@ -121,14 +123,16 @@
def test_generate_iml(self, mock_project, mock_get_root):
"""Test _generate_iml."""
mock_get_root.return_value = self._AOSP_FOLDER
- mock_project.project_absolute_path = uc.ANDROID_PROJECT_PATH
+ mock_project.project_absolute_path = self._ANDROID_PROJECT_PATH
mock_project.project_relative_path = self._ANDROID_SOURCE_RELATIVE_PATH
- mock_project.source_path['jar_path'] = set(uc.JAR_DEP_LIST)
- pfile_gen = ProjectFileGenerator(mock_project)
+ mock_project.source_path['jar_path'] = set(
+ unittest_constants.JAR_DEP_LIST)
+ pfile_gen = project_file_gen.ProjectFileGenerator(mock_project)
# Test for main project.
try:
iml_path, dependencies_iml_path = pfile_gen._generate_iml(
- copy.deepcopy(uc.ANDROID_SOURCE_DICT), is_main_module=True)
+ copy.deepcopy(unittest_constants.ANDROID_SOURCE_DICT),
+ is_main_module=True)
test_iml = common_util.read_file_content(iml_path)
sample_iml = common_util.read_file_content(self._IML_SAMPLE)
finally:
@@ -140,7 +144,7 @@
# Test for sub projects.
try:
iml_path, _ = pfile_gen._generate_iml(
- copy.deepcopy(uc.ANDROID_SOURCE_DICT))
+ copy.deepcopy(unittest_constants.ANDROID_SOURCE_DICT))
test_iml = common_util.read_file_content(iml_path)
sample_iml = common_util.read_file_content(self._IML_SAMPLE)
finally:
@@ -150,12 +154,12 @@
@mock.patch('aidegen.lib.project_info.ProjectInfo')
def test_generate_modules_xml(self, mock_project):
"""Test _generate_modules_xml."""
- mock_project.project_absolute_path = uc.ANDROID_PROJECT_PATH
- pfile_gen = ProjectFileGenerator(mock_project)
+ mock_project.project_absolute_path = self._ANDROID_PROJECT_PATH
+ pfile_gen = project_file_gen.ProjectFileGenerator(mock_project)
# Test for main project.
try:
pfile_gen._generate_modules_xml([])
- project_file_gen.update_enable_debugger(uc.ANDROID_PROJECT_PATH)
+ project_file_gen.update_enable_debugger(self._ANDROID_PROJECT_PATH)
test_module = common_util.read_file_content(self._MODULE_PATH)
finally:
shutil.rmtree(self._IDEA_PATH)
@@ -165,7 +169,7 @@
# Test for sub projects which only has self module.
try:
pfile_gen._generate_modules_xml()
- project_file_gen.update_enable_debugger(uc.ANDROID_PROJECT_PATH)
+ project_file_gen.update_enable_debugger(self._ANDROID_PROJECT_PATH)
test_module = common_util.read_file_content(self._MODULE_PATH)
finally:
shutil.rmtree(self._IDEA_PATH)
@@ -176,13 +180,13 @@
@mock.patch('aidegen.lib.project_info.ProjectInfo')
def test_generate_vcs_xml(self, mock_project):
"""Test _generate_vcs_xml."""
- mock_project.project_absolute_path = uc.ANDROID_PROJECT_PATH
+ mock_project.project_absolute_path = self._ANDROID_PROJECT_PATH
try:
- git_path = os.path.join(uc.ANDROID_PROJECT_PATH,
+ git_path = os.path.join(self._ANDROID_PROJECT_PATH,
project_file_gen._GIT_FOLDER_NAME)
if not os.path.exists(git_path):
os.mkdir(git_path)
- pfile_gen = ProjectFileGenerator(mock_project)
+ pfile_gen = project_file_gen.ProjectFileGenerator(mock_project)
pfile_gen._generate_vcs_xml()
test_vcs = common_util.read_file_content(self._VCS_PATH)
finally:
@@ -190,10 +194,10 @@
sample_vcs = common_util.read_file_content(self._VCS_XML_SAMPLE)
# The sample must base on the real path.
sample_vcs = sample_vcs.replace(self._LOCAL_PATH_TOKEN,
- uc.ANDROID_PROJECT_PATH)
+ self._ANDROID_PROJECT_PATH)
self.assertEqual(test_vcs, sample_vcs)
mock_project.project_absolute_path = common_util.get_android_root_dir()
- pfile_gen = ProjectFileGenerator(mock_project)
+ pfile_gen = project_file_gen.ProjectFileGenerator(mock_project)
self.assertIsNone(pfile_gen._generate_vcs_xml())
def test_get_uniq_iml_name(self):
@@ -225,7 +229,8 @@
path_list.append(k)
print('{} {}.'.format('path list with length:', len(path_list)))
- names = [ProjectFileGenerator.get_unique_iml_name(f) for f in path_list]
+ names = [project_file_gen.ProjectFileGenerator.get_unique_iml_name(f)
+ for f in path_list]
print('{} {}.'.format('Names list with length:', len(names)))
self.assertEqual(len(names), len(path_list))
@@ -238,8 +243,9 @@
@mock.patch('aidegen.lib.project_info.ProjectInfo')
def test_copy_project_files(self, mock_project):
"""Test _copy_constant_project_files."""
- mock_project.project_absolute_path = uc.ANDROID_PROJECT_PATH
- ProjectFileGenerator(mock_project)._copy_constant_project_files()
+ mock_project.project_absolute_path = self._ANDROID_PROJECT_PATH
+ project_file_gen.ProjectFileGenerator(
+ mock_project)._copy_constant_project_files()
self.assertTrue(
os.path.isfile(
os.path.join(self._IDEA_PATH,
@@ -332,12 +338,12 @@
enable_debugger_iml = '/path/to/enable_debugger/enable_debugger.iml'
sample_module = common_util.read_file_content(
self._ENABLE_DEBUGGER_MODULE_SAMPLE)
- mock_project.project_absolute_path = uc.ANDROID_PROJECT_PATH
- pfile_gen = ProjectFileGenerator(mock_project)
+ mock_project.project_absolute_path = self._ANDROID_PROJECT_PATH
+ pfile_gen = project_file_gen.ProjectFileGenerator(mock_project)
try:
pfile_gen._generate_modules_xml([])
- project_file_gen.update_enable_debugger(
- uc.ANDROID_PROJECT_PATH, enable_debugger_iml)
+ project_file_gen.update_enable_debugger(self._ANDROID_PROJECT_PATH,
+ enable_debugger_iml)
test_module = common_util.read_file_content(self._MODULE_PATH)
self.assertEqual(test_module, sample_module)
finally:
@@ -348,8 +354,9 @@
def test_handle_srcjar_folder(self, mock_project, mock_get_root):
"""Test _handle_srcjar_folder."""
mock_get_root.return_value = self._AOSP_FOLDER
- source = ProjectFileGenerator(mock_project)._handle_srcjar_folder(
- constant.FILE_IML, {'out/aapt2.srcjar!/'})
+ source = project_file_gen.ProjectFileGenerator(
+ mock_project)._handle_srcjar_folder(constant.FILE_IML,
+ {'out/aapt2.srcjar!/'})
sample_source = common_util.read_file_content(self._SRCJAR_SAMPLE)
self.assertEqual(source, sample_source)
diff --git a/aidegen/lib/project_info.py b/aidegen/lib/project_info.py
index cefb284..4dd6591 100644
--- a/aidegen/lib/project_info.py
+++ b/aidegen/lib/project_info.py
@@ -23,8 +23,6 @@
from aidegen import constant
from aidegen.lib import common_util
-from aidegen.lib.common_util import COLORED_INFO
-from aidegen.lib.common_util import get_related_paths
_ANDROID_MK = 'Android.mk'
_ANDROID_BP = 'Android.bp'
@@ -92,7 +90,8 @@
locating the target, project with matching module name of
the given target has a higher priority than project path.
"""
- rel_path, abs_path = get_related_paths(self.modules_info, target)
+ rel_path, abs_path = common_util.get_related_paths(self.modules_info,
+ target)
self.module_name = self._get_target_name(target, abs_path)
self.project_module_names = set(
self.modules_info.get_module_names(rel_path))
@@ -136,7 +135,7 @@
mk_set = set(self._search_android_make_files())
if mk_set:
print('\n{} {}\n'.format(
- COLORED_INFO('Warning:'),
+ common_util.COLORED_INFO('Warning:'),
_ANDROID_MK_WARN.format(self.module_name, '\n'.join(mk_set))))
def _search_android_make_files(self):
@@ -153,7 +152,8 @@
if os.path.isfile(android_mk) and not os.path.isfile(android_bp):
yield '\t' + os.path.join(self.project_relative_path, _ANDROID_MK)
for mod_name in self.dep_modules:
- rel_path, abs_path = get_related_paths(self.modules_info, mod_name)
+ rel_path, abs_path = common_util.get_related_paths(
+ self.modules_info, mod_name)
if rel_path and abs_path:
mod_mk = os.path.join(abs_path, _ANDROID_MK)
mod_bp = os.path.join(abs_path, _ANDROID_BP)
diff --git a/aidegen/lib/project_info_unittest.py b/aidegen/lib/project_info_unittest.py
index 6964c33..96ea627 100644
--- a/aidegen/lib/project_info_unittest.py
+++ b/aidegen/lib/project_info_unittest.py
@@ -20,11 +20,9 @@
import unittest
from unittest import mock
+from aidegen import unittest_constants
from aidegen.lib import common_util
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'],
@@ -70,32 +68,39 @@
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(project_info.ProjectInfo._is_a_target_module({}),
+ False)
+ self.assertEqual(project_info.ProjectInfo._is_a_target_module(
+ {'path': ''}), False)
+ self.assertEqual(project_info.ProjectInfo._is_a_target_module(
+ {'class': ''}), False)
self.assertEqual(
- ProjectInfo._is_a_target_module({
+ project_info.ProjectInfo._is_a_target_module({
'class': ['APPS']
}), True)
self.assertEqual(
- ProjectInfo._is_a_target_module({
+ project_info.ProjectInfo._is_a_target_module({
'class': ['JAVA_LIBRARIES']
}), True)
self.assertEqual(
- ProjectInfo._is_a_target_module({
+ project_info.ProjectInfo._is_a_target_module({
'class': ['ROBOLECTRIC']
}), True)
@mock.patch.object(common_util, 'get_android_root_dir')
def test_get_target_name(self, mock_get_root):
"""Test _get_target_name with different conditions."""
- mock_get_root.return_value = uc.TEST_DATA_PATH
+ mock_get_root.return_value = unittest_constants.TEST_DATA_PATH
self.assertEqual(
- ProjectInfo._get_target_name(uc.TEST_MODULE, uc.TEST_DATA_PATH),
- os.path.basename(uc.TEST_DATA_PATH))
+ project_info.ProjectInfo._get_target_name(
+ unittest_constants.TEST_MODULE,
+ unittest_constants.TEST_DATA_PATH),
+ os.path.basename(unittest_constants.TEST_DATA_PATH))
self.assertEqual(
- ProjectInfo._get_target_name(uc.TEST_MODULE, uc.TEST_PATH),
- uc.TEST_MODULE)
+ project_info.ProjectInfo._get_target_name(
+ unittest_constants.TEST_MODULE,
+ unittest_constants.TEST_PATH),
+ unittest_constants.TEST_MODULE)
if __name__ == '__main__':
diff --git a/aidegen/lib/source_locator.py b/aidegen/lib/source_locator.py
index b74b49d..fb4d39d 100644
--- a/aidegen/lib/source_locator.py
+++ b/aidegen/lib/source_locator.py
@@ -24,9 +24,8 @@
import re
from aidegen import constant
-from aidegen.lib import errors
from aidegen.lib import common_util
-from aidegen.lib.common_util import COLORED_INFO
+from aidegen.lib import errors
from atest import atest_utils
# Parse package name from the package declaration line of a java.
@@ -186,7 +185,8 @@
message = ('Build failed!\n{}\nAIDEGen will proceed but dependency '
'correctness is not guaranteed if not all targets being '
'built successfully.'.format('\n'.join(targets)))
- print('\n{} {}\n'.format(COLORED_INFO('Warning:'), message))
+ print('\n{} {}\n'.format(common_util.COLORED_INFO('Warning:'),
+ message))
def _separate_build_targets(build_targets, max_length):
@@ -252,7 +252,7 @@
])
-class ModuleData():
+class ModuleData:
"""ModuleData class.
Attributes:
diff --git a/aidegen/lib/source_locator_unittest.py b/aidegen/lib/source_locator_unittest.py
index 6cd0fce..1803677 100644
--- a/aidegen/lib/source_locator_unittest.py
+++ b/aidegen/lib/source_locator_unittest.py
@@ -23,7 +23,7 @@
from unittest import mock
from aidegen import constant
-from aidegen import unittest_constants as uc
+from aidegen import unittest_constants
from aidegen.lib import source_locator
_MODULE_NAME = 'test'
@@ -51,7 +51,7 @@
"""Test _collect_srcs_paths create the source path list."""
result_source = set(['packages/apps/test/src/main/java'])
result_test = set(['packages/apps/test/tests'])
- mock_android_root_dir.return_value = uc.TEST_DATA_PATH
+ mock_android_root_dir.return_value = unittest_constants.TEST_DATA_PATH
module_data = source_locator.ModuleData(_MODULE_NAME, _MODULE_INFO,
_MODULE_DEPTH)
module_data._collect_srcs_paths()
@@ -61,14 +61,16 @@
def test_get_package_name(self):
"""test get the package name from a java file."""
result_package_name = 'com.android'
- test_java = os.path.join(uc.TEST_DATA_PATH, _MODULE_PATH,
+ test_java = os.path.join(unittest_constants.TEST_DATA_PATH,
+ _MODULE_PATH,
'src/main/java/com/android/java.java')
package_name = source_locator.ModuleData._get_package_name(test_java)
self.assertEqual(package_name, result_package_name)
# Test on java file with no package name.
result_package_name = None
- test_java = os.path.join(uc.TEST_DATA_PATH, _MODULE_PATH,
+ test_java = os.path.join(unittest_constants.TEST_DATA_PATH,
+ _MODULE_PATH,
'src/main/java/com/android/no_package.java')
package_name = source_locator.ModuleData._get_package_name(test_java)
self.assertEqual(package_name, result_package_name)
@@ -79,7 +81,7 @@
# Test for getting the source path by parse package name from a java.
test_java = 'packages/apps/test/src/main/java/com/android/java.java'
result_source = 'packages/apps/test/src/main/java'
- mock_android_root_dir.return_value = uc.TEST_DATA_PATH
+ mock_android_root_dir.return_value = unittest_constants.TEST_DATA_PATH
module_data = source_locator.ModuleData(_MODULE_NAME, _MODULE_INFO,
_MODULE_DEPTH)
src_path = module_data._get_source_folder(test_java)
@@ -124,7 +126,7 @@
# Test on target srcjar exists in srcjars.
test_module = dict(_MODULE_INFO)
test_module['srcs'] = []
- mock_android_root_dir.return_value = uc.TEST_DATA_PATH
+ mock_android_root_dir.return_value = unittest_constants.TEST_DATA_PATH
module_data = source_locator.ModuleData(_MODULE_NAME, test_module,
_MODULE_DEPTH)
# Test the module is not APPS.
@@ -207,7 +209,7 @@
# Append an existing jar file path to module_data.jar_files.
test_jar_file = os.path.join(_MODULE_PATH, 'test.jar')
result_jar_list = set([test_jar_file])
- mock_android_root_dir.return_value = uc.TEST_DATA_PATH
+ mock_android_root_dir.return_value = unittest_constants.TEST_DATA_PATH
module_data = source_locator.ModuleData(_MODULE_NAME, _MODULE_INFO,
_MODULE_DEPTH)
module_data._append_jar_file(test_jar_file)
@@ -236,7 +238,7 @@
os.path.join(_MODULE_PATH, 'tests/test_second.jar')
]
result_jar_list = set([os.path.join(_MODULE_PATH, 'test.jar')])
- mock_android_root_dir.return_value = uc.TEST_DATA_PATH
+ mock_android_root_dir.return_value = unittest_constants.TEST_DATA_PATH
module_data = source_locator.ModuleData(_MODULE_NAME, module_info,
_MODULE_DEPTH)
module_data._append_jar_from_installed()
@@ -265,7 +267,7 @@
os.path.join(_MODULE_PATH, 'test.jar'),
os.path.join(_MODULE_PATH, 'tests/test_second.jar')
])
- mock_android_root_dir.return_value = uc.TEST_DATA_PATH
+ mock_android_root_dir.return_value = unittest_constants.TEST_DATA_PATH
module_data = source_locator.ModuleData(_MODULE_NAME, module_info,
_MODULE_DEPTH)
module_data._set_jars_jarfile()
@@ -280,7 +282,7 @@
result_test_list = set(['packages/apps/test/tests'])
result_jar_list = set()
result_r_path = set()
- mock_android_root_dir.return_value = uc.TEST_DATA_PATH
+ mock_android_root_dir.return_value = unittest_constants.TEST_DATA_PATH
module_data = source_locator.ModuleData(_MODULE_NAME, module_info,
_MODULE_DEPTH)
module_data.locate_sources_path()
@@ -335,7 +337,7 @@
result_jar_list = set(
[('out/soong/.intermediates/packages/apps/test/test/'
'android_common/test.jar')])
- mock_android_root_dir.return_value = uc.TEST_DATA_PATH
+ mock_android_root_dir.return_value = unittest_constants.TEST_DATA_PATH
module_data = source_locator.ModuleData(_MODULE_NAME, module_info,
depth_by_source)
module_data.locate_sources_path()
@@ -384,7 +386,7 @@
"""Test locate_source handling."""
mock_atest_utils_build.build.return_value = True
test_root_path = os.path.join(tempfile.mkdtemp(), 'test')
- shutil.copytree(uc.TEST_DATA_PATH, test_root_path)
+ shutil.copytree(unittest_constants.TEST_DATA_PATH, test_root_path)
mock_android_root_dir.return_value = test_root_path
generated_jar = ('out/soong/.intermediates/packages/apps/test/test/'
'android_common/generated.jar')
diff --git a/aidegen/test_data/srcjar.iml b/aidegen/test_data/srcjar.iml
index a813829..0e54ef2 100644
--- a/aidegen/test_data/srcjar.iml
+++ b/aidegen/test_data/srcjar.iml
@@ -7,7 +7,6 @@
<content url="jar:///aosp/out/aapt2.srcjar!/">
<sourceFolder url="jar:///aosp/out/aapt2.srcjar!/" isTestSource="False" />
</content>
-
<orderEntry type="sourceFolder" forTests="false" />
@MODULE_DEPENDENCIES@
<orderEntry type="inheritedJdk" />
diff --git a/aidegen/test_data/test.iml b/aidegen/test_data/test.iml
index 5ab6d03..ced6e0c 100644
--- a/aidegen/test_data/test.iml
+++ b/aidegen/test_data/test.iml
@@ -11,7 +11,6 @@
<sourceFolder url="file:///aosp/test_data/project/level12/level22" isTestSource="False" />
</content>
-
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="dependencies" />
<orderEntry type="inheritedJdk" />
diff --git a/aidegen/unittest_constants.py b/aidegen/unittest_constants.py
index 78be494..71dfdb1 100644
--- a/aidegen/unittest_constants.py
+++ b/aidegen/unittest_constants.py
@@ -24,10 +24,10 @@
import os
-from aidegen.lib.common_util import get_aidegen_root_dir
+from aidegen.lib import common_util
# The data below is only for test usage.
-TEST_DATA_PATH = os.path.join(get_aidegen_root_dir(), "test_data")
+TEST_DATA_PATH = os.path.join(common_util.get_aidegen_root_dir(), "test_data")
IDEA_SH_FIND = [
'/opt/intellij-ce-2018.1/bin/idea.sh', '/opt/intellij-ce-2017.2/bin/idea.sh'
] # script path data