Ejemplo n.º 1
0
 def test_extract_test_path(self, _):
     """Test extract_test_dir method."""
     path = os.path.join(uc.ROOT, CLASS_DIR, uc.CLASS_NAME + '.java')
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.extract_test_path(uc.FIND_ONE), path)
     path = os.path.join(uc.ROOT, CLASS_DIR, uc.CLASS_NAME + '.java')
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.extract_test_path(FIND_TWO), path)
Ejemplo n.º 2
0
 def test_find_parent_module_dir_with_autogen_config(self, _isfile, _isdir):
     """Test _find_parent_module_dir method."""
     abs_class_dir = '/%s' % CLASS_DIR
     mock_module_info = mock.Mock(spec=module_info.ModuleInfo)
     mock_module_info.path_to_module_info = PATH_TO_MODULE_INFO_WITH_AUTOGEN
     unittest_utils.assert_strict_equal(
         self,
         test_finder_utils.find_parent_module_dir(uc.ROOT, abs_class_dir,
                                                  mock_module_info),
         uc.MODULE_DIR)
Ejemplo n.º 3
0
 def test_find_parent_module_dir(self, _isfile, _isdir):
     """Test _find_parent_module_dir method."""
     abs_class_dir = '/%s' % CLASS_DIR
     mock_module_info = mock.Mock(spec=module_info.ModuleInfo)
     mock_module_info.path_to_module_info = {}
     unittest_utils.assert_strict_equal(
         self,
         test_finder_utils.find_parent_module_dir(uc.ROOT, abs_class_dir,
                                                  mock_module_info),
         uc.MODULE_DIR)
Ejemplo n.º 4
0
 def test_get_targets_from_vts_xml(self):
     """Test get_targets_from_xml method."""
     # Mocking Etree is near impossible, so use a real file, but mock out
     # ModuleInfo,
     mock_module_info = mock.Mock(spec=module_info.ModuleInfo)
     mock_module_info.is_module.return_value = True
     xml_file = os.path.join(uc.TEST_DATA_DIR, VTS_XML)
     unittest_utils.assert_strict_equal(
         self,
         test_finder_utils.get_targets_from_vts_xml(xml_file, '',
                                                    mock_module_info),
         VTS_XML_TARGETS)
Ejemplo n.º 5
0
 def test_get_targets_from_xml(self):
     """Test get_targets_from_xml method."""
     # Mocking Etree is near impossible, so use a real file, but mocking
     # ModuleInfo is still fine. Just have it return False when it finds a
     # module that states it's not a module.
     mock_module_info = mock.Mock(spec=module_info.ModuleInfo)
     mock_module_info.is_module.side_effect = lambda module: (
         not module == 'is_not_module')
     xml_file = os.path.join(uc.TEST_DATA_DIR, constants.MODULE_CONFIG)
     unittest_utils.assert_strict_equal(
         self,
         test_finder_utils.get_targets_from_xml(xml_file, mock_module_info),
         XML_TARGETS)
Ejemplo n.º 6
0
    def test_find_parent_module_dir_robo(self, _is_robo, _isfile, _isdir):
        """Test _find_parent_module_dir method.

        Make sure we behave as expected when we encounter a robo module path.
        """
        abs_class_dir = '/%s' % CLASS_DIR
        mock_module_info = mock.Mock(spec=module_info.ModuleInfo)
        rel_class_dir_path = os.path.relpath(abs_class_dir, uc.ROOT)
        mock_module_info.path_to_module_info = {rel_class_dir_path: [{}]}
        unittest_utils.assert_strict_equal(
            self,
            test_finder_utils.find_parent_module_dir(uc.ROOT, abs_class_dir,
                                                     mock_module_info),
            rel_class_dir_path)
Ejemplo n.º 7
0
    def test_find_parent_module_dir_with_autogen_subconfig(
            self, _isfile, _isdir):
        """Test _find_parent_module_dir method.

        This case is testing when the auto generated config is in a
        sub-directory of a larger test that contains a test config in a parent
        directory.
        """
        abs_class_dir = '/%s' % CLASS_DIR
        mock_module_info = mock.Mock(spec=module_info.ModuleInfo)
        mock_module_info.path_to_module_info = (
            PATH_TO_MODULE_INFO_WITH_SUB_AUTOGEN)
        unittest_utils.assert_strict_equal(
            self,
            test_finder_utils.find_parent_module_dir(uc.ROOT, abs_class_dir,
                                                     mock_module_info),
            uc.MODULE_DIR)
    def test_get_test_infos(self, mock_getfindmethods):
        """Test _get_test_infos method."""
        ctr = cli_t.CLITranslator()
        find_method_return_module_info = lambda x, y: uc.MODULE_INFO
        # pylint: disable=invalid-name
        find_method_return_module_class_info = (lambda x, test: uc.MODULE_INFO
                                                if test == uc.MODULE_NAME
                                                else uc.CLASS_INFO)
        find_method_return_nothing = lambda x, y: None
        one_test = [uc.MODULE_NAME]
        mult_test = [uc.MODULE_NAME, uc.CLASS_NAME]

        # Let's make sure we return what we expect.
        expected_test_infos = {uc.MODULE_INFO}
        mock_getfindmethods.return_value = [
            test_finder_base.Finder(None, find_method_return_module_info)]
        unittest_utils.assert_strict_equal(
            self, ctr._get_test_infos(one_test), expected_test_infos)

        # Check we receive multiple test infos.
        expected_test_infos = {uc.MODULE_INFO, uc.CLASS_INFO}
        mock_getfindmethods.return_value = [
            test_finder_base.Finder(None, find_method_return_module_class_info)]
        unittest_utils.assert_strict_equal(
            self, ctr._get_test_infos(mult_test), expected_test_infos)

        # Let's make sure we raise an error when we have no tests found.
        mock_getfindmethods.return_value = [
            test_finder_base.Finder(None, find_method_return_nothing)]
        self.assertRaises(atest_error.NoTestFoundError, ctr._get_test_infos,
                          one_test)

        # Check the method works for test mapping.
        test_detail1 = test_mapping.TestDetail(uc.TEST_MAPPING_TEST)
        test_detail2 = test_mapping.TestDetail(uc.TEST_MAPPING_TEST_WITH_OPTION)
        expected_test_infos = {uc.MODULE_INFO, uc.CLASS_INFO}
        mock_getfindmethods.return_value = [
            test_finder_base.Finder(None, find_method_return_module_class_info)]
        test_infos = ctr._get_test_infos(
            mult_test, [test_detail1, test_detail2])
        unittest_utils.assert_strict_equal(
            self, test_infos, expected_test_infos)
        for test_info in test_infos:
            if test_info == uc.MODULE_INFO:
                self.assertEqual(
                    test_detail1.options,
                    test_info.data[constants.TI_MODULE_ARG])
            else:
                self.assertEqual(
                    test_detail2.options,
                    test_info.data[constants.TI_MODULE_ARG])
 def test_generate_run_commands(self, mock_resultargs):
     """Test _generate_run_command method."""
     # Basic Run Cmd
     mock_resultargs.return_value = []
     unittest_utils.assert_strict_equal(
         self, self.tr._generate_run_commands([], {}, ''),
         RUN_CMD.format(metrics=''))
     unittest_utils.assert_strict_equal(
         self, self.tr._generate_run_commands([], {}, METRICS_DIR),
         RUN_CMD.format(metrics=METRICS_DIR_ARG))
     # Run cmd with result server args.
     result_arg = '--result_arg'
     mock_resultargs.return_value = [result_arg]
     unittest_utils.assert_strict_equal(
         self, self.tr._generate_run_commands([], {}, ''),
         RUN_CMD.format(metrics='') + ' ' + result_arg)
    def test_translate(self, _info, mock_testmapping):
        """Test translate method."""
        # Check that we can find a class.
        targets, test_infos = self.ctr.translate([uc.CLASS_NAME])
        unittest_utils.assert_strict_equal(
            self, targets, uc.CLASS_BUILD_TARGETS)
        unittest_utils.assert_strict_equal(self, test_infos, {uc.CLASS_INFO})

        # Check that we get all the build targets we expect.
        targets, test_infos = self.ctr.translate([uc.MODULE_NAME,
                                                  uc.CLASS_NAME])
        unittest_utils.assert_strict_equal(
            self, targets, uc.MODULE_CLASS_COMBINED_BUILD_TARGETS)
        unittest_utils.assert_strict_equal(self, test_infos, {uc.MODULE_INFO,
                                                              uc.CLASS_INFO})

        # Check that test mappings feeds into get_test_info properly.
        test_detail1 = test_mapping.TestDetail(uc.TEST_MAPPING_TEST)
        test_detail2 = test_mapping.TestDetail(uc.TEST_MAPPING_TEST_WITH_OPTION)
        mock_testmapping.return_value = ([test_detail1, test_detail2], None)
        targets, test_infos = self.ctr.translate([])
        unittest_utils.assert_strict_equal(
            self, targets, uc.MODULE_CLASS_COMBINED_BUILD_TARGETS)
        unittest_utils.assert_strict_equal(self, test_infos, {uc.MODULE_INFO,
                                                              uc.CLASS_INFO})
 def test_flatten_test_filters(self):
     """Test _flatten_test_filters method."""
     # No Flattening
     filters = self.tr._flatten_test_filters({uc.CLASS_FILTER})
     unittest_utils.assert_strict_equal(self, frozenset([uc.CLASS_FILTER]),
                                        filters)
     filters = self.tr._flatten_test_filters({CLASS2_FILTER})
     unittest_utils.assert_strict_equal(self, frozenset([CLASS2_FILTER]),
                                        filters)
     filters = self.tr._flatten_test_filters({uc.METHOD_FILTER})
     unittest_utils.assert_strict_equal(self, frozenset([uc.METHOD_FILTER]),
                                        filters)
     filters = self.tr._flatten_test_filters(
         {uc.METHOD_FILTER, CLASS2_METHOD_FILTER})
     unittest_utils.assert_strict_equal(
         self, frozenset([uc.METHOD_FILTER, CLASS2_METHOD_FILTER]), filters)
     # Flattening
     filters = self.tr._flatten_test_filters(
         {uc.METHOD_FILTER, METHOD2_FILTER})
     unittest_utils.assert_strict_equal(self, filters,
                                        frozenset([uc.FLAT_METHOD_FILTER]))
     filters = self.tr._flatten_test_filters({
         uc.METHOD_FILTER,
         METHOD2_FILTER,
         CLASS2_METHOD_FILTER,
     })
     unittest_utils.assert_strict_equal(
         self, filters,
         frozenset([uc.FLAT_METHOD_FILTER, CLASS2_METHOD_FILTER]))
Ejemplo n.º 12
0
 def test_split_methods(self):
     """Test _split_methods method."""
     # Class
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.split_methods('Class.Name'),
         ('Class.Name', set()))
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.split_methods('Class.Name#Method'),
         ('Class.Name', {'Method'}))
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.split_methods('Class.Name#Method,Method2'),
         ('Class.Name', {'Method', 'Method2'}))
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.split_methods('Class.Name#Method,Method2'),
         ('Class.Name', {'Method', 'Method2'}))
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.split_methods('Class.Name#Method,Method2'),
         ('Class.Name', {'Method', 'Method2'}))
     self.assertRaises(atest_error.TooManyMethodsError,
                       test_finder_utils.split_methods,
                       'class.name#Method,class.name.2#method')
     # Path
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.split_methods('foo/bar/class.java'),
         ('foo/bar/class.java', set()))
     unittest_utils.assert_strict_equal(
         self, test_finder_utils.split_methods('foo/bar/class.java#Method'),
         ('foo/bar/class.java', {'Method'}))