Beispiel #1
0
    def test_validation(self):
        internal_repo = Repository(url=None, push_db_basedir=None)
        # Adding a JVM Artifact as a provides on a PythonTarget doesn't make a lot of sense.
        # This test sets up that very scenario, and verifies that pants throws a
        # TargetDefinitionException.
        with self.assertRaises(TargetDefinitionException):
            self.make_target(target_type=PythonTarget,
                             spec=":one",
                             provides=Artifact(org='com.twitter',
                                               name='one-jar',
                                               repo=internal_repo))

        spec = "//:test-with-PythonArtifact"
        pa = PythonArtifact(name='foo', version='1.0', description='foo')

        # This test verifies that adding a 'setup_py' provides to a PythonTarget is okay.
        pt_with_artifact = self.make_target(spec=spec,
                                            target_type=PythonTarget,
                                            provides=pa)
        self.assertEqual(pt_with_artifact.address.spec, spec)

        spec = "//:test-with-none"
        # This test verifies that having no provides is okay.
        pt_no_artifact = self.make_target(spec=spec,
                                          target_type=PythonTarget,
                                          provides=None)
        self.assertEqual(pt_no_artifact.address.spec, spec)
Beispiel #2
0
    def test_validation(self):
        repo = Repository(name="myRepo",
                          url="myUrl",
                          push_db_basedir="myPushDb")
        Artifact(org="testOrg", name="testName", repo=repo, description="Test")

        with self.assertRaises(ValueError):
            Artifact(org=1, name="testName", repo=repo, description="Test")

        with self.assertRaises(ValueError):
            Artifact(org="testOrg", name=1, repo=repo, description="Test")

        with self.assertRaises(ValueError):
            Artifact(org="testOrg",
                     name="testName",
                     repo=1,
                     description="Test")

        with self.assertRaises(ValueError):
            Artifact(org="testOrg", name="testName", repo=repo, description=1)
  def test_jar_provided_exclude_with_similar_org(self):
    provider = self.make_target('provider', ExportableJvmLibrary,
                         provides=Artifact('com.example.lib', '', Repository()))
    root = self.make_target('root', JvmTarget, dependencies=[provider])

    classpath_product = ClasspathProducts(self.pants_workdir)
    self.add_example_jar_classpath_element_for(classpath_product, root)
    self.add_excludes_for_targets(classpath_product, provider, root)

    classpath = classpath_product.get_for_target(root)

    self.assertEqual([('default', self._example_jar_path())], classpath)
  def test_jar_provided_exclude_with_similar_name(self):
    # note exclude 'jars/com.example/l' should not match jars/com.example/lib/jars/123.4.jar
    provider = self.make_target('provider', ExportableJvmLibrary,
                         provides=Artifact('com.example', 'li', Repository()))
    root = self.make_target('root', JvmTarget, dependencies=[provider])

    classpath_product = ClasspathProducts(self.pants_workdir)
    self.add_example_jar_classpath_element_for(classpath_product, root)
    self.add_excludes_for_targets(classpath_product, provider, root)

    classpath = classpath_product.get_for_target(root)

    self.assertEqual([('default', self._example_jar_path())], classpath)
  def test_jar_provided_by_transitive_target_excluded(self):
    provider = self.make_target('provider', ExportableJvmLibrary,
                         provides=Artifact('com.example', 'lib', Repository()))
    consumer = self.make_target('consumer', JvmTarget)
    root = self.make_target('root', JvmTarget, dependencies=[provider, consumer])

    classpath_product = ClasspathProducts(self.pants_workdir)
    self.add_example_jar_classpath_element_for(classpath_product, consumer)
    self.add_excludes_for_targets(classpath_product, consumer, provider, root)

    classpath = classpath_product.get_for_target(root)

    self.assertEqual([], classpath)
Beispiel #6
0
    def test_validation(self):
        repo = Repository(name="myRepo",
                          url="myUrl",
                          push_db_basedir="myPushDb")

        class TestPublicationMetadata(PublicationMetadata):
            def _compute_fingerprint(self):
                return None

        metadata = TestPublicationMetadata()

        Artifact(org="testOrg",
                 name="testName",
                 repo=repo,
                 publication_metadata=metadata)

        with self.assertRaises(ValueError):
            Artifact(org=1,
                     name="testName",
                     repo=repo,
                     publication_metadata=metadata)

        with self.assertRaises(ValueError):
            Artifact(org="testOrg",
                     name=1,
                     repo=repo,
                     publication_metadata=metadata)

        with self.assertRaises(ValueError):
            Artifact(org="testOrg",
                     name="testName",
                     repo=1,
                     publication_metadata=metadata)

        with self.assertRaises(ValueError):
            Artifact(org="testOrg",
                     name="testName",
                     repo=repo,
                     publication_metadata=1)
Beispiel #7
0
def test_list_provides() -> None:
    sample_repo = Repository(name="public", url="http://maven.example.com", push_db_basedir="/tmp")
    sample_artifact = Artifact(org="example_org", name="test", repo=sample_repo)
    targets = [
        MockTarget({ProvidesField.alias: sample_artifact}, address=Address.parse(":provided")),
        MockTarget({}, address=Address.parse(":not_provided")),
    ]
    stdout, _ = run_goal(targets, show_provides=True)
    assert stdout.strip() == "//:provided example_org#test"

    # Custom columns
    stdout, _ = run_goal(
        targets,
        show_provides=True,
        provides_columns="push_db_basedir,address,repo_url,repo_name,artifact_id",
    )
    assert stdout.strip() == "/tmp //:provided http://maven.example.com public example_org#test"
Beispiel #8
0
    def test_jar_provided_by_transitive_target_excluded(self):
        provider = self.make_target('provider',
                                    ExportableJvmLibrary,
                                    provides=Artifact('com.example', 'lib',
                                                      Repository()))
        consumer = self.make_target('consumer', JvmTarget)
        root = self.make_target('root',
                                JvmTarget,
                                dependencies=[provider, consumer])

        classpath_product = ClasspathProducts()
        classpath_product.add_for_target(
            consumer, [('default', self._example_jar_path())])
        classpath_product.add_excludes_for_targets([root, provider, consumer])

        classpath = classpath_product.get_for_target(root)

        self.assertEqual([], classpath)