Пример #1
0
  def _collect_test_targets(self, targets):
    """Return a test registry mapping the tests found in the given targets.

    If `self._tests_to_run` is set, return a registry of explicitly specified tests instead.

    :returns: A registry of tests to run.
    :rtype: :class:`pants.java.junit.junit_xml_parser.Test.TestRegistry`
    """

    test_registry = TestRegistry(tuple(self._calculate_tests_from_targets(targets)))

    if targets and self._tests_to_run:
      # If there are some junit_test targets in the graph, find ones that match the requested
      # test(s).
      possible_test_to_target = {}
      unknown_tests = []
      for possible_test in self._get_possible_tests_to_run():
        target = test_registry.get_owning_target(possible_test)
        if target is None:
          unknown_tests.append(possible_test)
        else:
          possible_test_to_target[possible_test] = target

      if len(unknown_tests) > 0:
        raise TaskError("No target found for test specifier(s):\n\n  '{}'\n\nPlease change "
                        "specifier or bring in the proper target(s)."
                        .format("'\n  '".join(t.render_test_spec() for t in unknown_tests)))

      return TestRegistry(possible_test_to_target)
    else:
      return test_registry
Пример #2
0
    def _collect_test_targets(self, targets):
        """Return a test registry mapping the tests found in the given targets.

    If `self._tests_to_run` is set, return a registry of explicitly specified tests instead.

    :returns: A registry of tests to run.
    :rtype: :class:`pants.java.junit.junit_xml_parser.Test.TestRegistry`
    """

        test_registry = TestRegistry(
            tuple(self._calculate_tests_from_targets(targets)))

        if targets and self._tests_to_run:
            # If there are some junit_test targets in the graph, find ones that match the requested
            # test(s).
            possible_test_to_target = {}
            unknown_tests = []
            for possible_test in self._get_possible_tests_to_run():
                target = test_registry.get_owning_target(possible_test)
                if target is None:
                    unknown_tests.append(possible_test)
                else:
                    possible_test_to_target[possible_test] = target

            if len(unknown_tests) > 0:
                raise TaskError(
                    "No target found for test specifier(s):\n\n  '{}'\n\nPlease change "
                    "specifier or bring in the proper target(s).".format(
                        "'\n  '".join(t.render_test_spec()
                                      for t in unknown_tests)))

            return TestRegistry(possible_test_to_target)
        else:
            return test_registry
Пример #3
0
  def test_get_owning_target(self):
    registry = TestRegistry(((JUnitTest('class1'), 'Bob'),
                             (JUnitTest('class2'), 'Jane'),
                             (JUnitTest('class3', 'method1'), 'Heidi')))

    self.assertEqual('Bob', registry.get_owning_target(JUnitTest('class1')))
    self.assertEqual('Bob', registry.get_owning_target(JUnitTest('class1', 'method1')))

    self.assertEqual('Jane', registry.get_owning_target(JUnitTest('class2')))
    self.assertEqual('Jane', registry.get_owning_target(JUnitTest('class2', 'method1')))

    self.assertIsNone(registry.get_owning_target(JUnitTest('class3')))
    self.assertEqual('Heidi', registry.get_owning_target(JUnitTest('class3', 'method1')))