예제 #1
0
    def test_collapse_source_root(self):
        source_roots = create_subsystem(SourceRootConfig,
                                        source_roots={
                                            '/src/java': [],
                                            '/tests/java': [],
                                            '/some/other': []
                                        },
                                        unmatched='fail').get_source_roots()
        source_set_list = []
        self.assertEquals([],
                          Project._collapse_by_source_root(
                              source_roots, source_set_list))

        source_sets = [
            SourceSet('/repo-root', 'src/java', 'org/pantsbuild/app', False),
            SourceSet('/repo-root', 'tests/java', 'org/pantsbuild/app', True),
            SourceSet('/repo-root', 'some/other', 'path', False),
        ]

        results = Project._collapse_by_source_root(source_roots, source_sets)

        self.assertEquals(SourceSet('/repo-root', 'src/java', '', False),
                          results[0])
        self.assertFalse(results[0].is_test)
        self.assertEquals(SourceSet('/repo-root', 'tests/java', '', True),
                          results[1])
        self.assertTrue(results[1].is_test)
        # If there is no registered source root, the SourceSet should be returned unmodified
        self.assertEquals(source_sets[2], results[2])
        self.assertFalse(results[2].is_test)
예제 #2
0
  def test_collapse_source_root(self):
    self.context(for_subsystems=[SourceRootConfig], options={
      SourceRootConfig.options_scope: {
        'source_roots': {
          '/src/java': [],
          '/tests/java': [],
          '/some/other': []
        },
        'unmatched': 'fail'
      }
    })
    source_roots = SourceRootConfig.global_instance().get_source_roots()
    source_set_list = []
    self.assertEquals([], Project._collapse_by_source_root(source_roots, source_set_list))

    source_sets = [
      SourceSet('/repo-root', 'src/java', 'org/pantsbuild/app', False),
      SourceSet('/repo-root', 'tests/java', 'org/pantsbuild/app', True),
      SourceSet('/repo-root', 'some/other', 'path', False),
    ]

    results = Project._collapse_by_source_root(source_roots, source_sets)

    self.assertEquals(SourceSet('/repo-root', 'src/java', '', False), results[0])
    self.assertFalse(results[0].is_test)
    self.assertEquals(SourceSet('/repo-root', 'tests/java', '', True), results[1])
    self.assertTrue(results[1].is_test)
    # If there is no registered source root, the SourceSet should be returned unmodified
    self.assertEquals(source_sets[2], results[2])
    self.assertFalse(results[2].is_test)
예제 #3
0
 def test__only_test_resources(self):
   deduped_sources = Project.dedup_sources([
     SourceSet('foo', 'bar', 'baz', is_test=True, resources_only=True),
     SourceSet('foo', 'bar', 'baz', is_test=True, resources_only=True),
   ])
   self.assert_dedup(SourceSet('foo', 'bar', 'baz', is_test=True, resources_only=True),
                     deduped_sources)
예제 #4
0
 def test_source_set(self):
   source_set1 = SourceSet("repo-root", "path/to/build", "org/pantsbuild/project", False)
   # only the first 3 parameters are considered keys
   self.assertEquals(("repo-root", "path/to/build", "org/pantsbuild/project"), source_set1._key_tuple)
   source_set2 = SourceSet("repo-root", "path/to/build", "org/pantsbuild/project", True)
   # Don't consider the test flag
   self.assertEquals(source_set1, source_set2)
예제 #5
0
 def test_dedup_sources_resource_and_code(self):
     """Show that a non-resources-only source set turns off the resources_only flag"""
     deduped_sources = Project.dedup_sources([
         SourceSet('foo', 'bar', 'baz', resources_only=True),
         SourceSet('foo', 'bar', 'baz'),
         SourceSet('foo', 'bar', 'baz', resources_only=True),
     ])
     self.assert_dedup(SourceSet('foo', 'bar', 'baz'), deduped_sources)
예제 #6
0
 def test_dedup_test_resources(self):
   """Show that competting is_test values on a resources-only source set turns off is_test"""
   deduped_sources = Project.dedup_sources([
     SourceSet('foo', 'bar', 'baz', is_test=True, resources_only=True),
     SourceSet('foo', 'bar', 'baz', is_test= False, resources_only=True),
     SourceSet('foo', 'bar', 'baz', is_test=True, resources_only=True),
   ])
   self.assert_dedup(SourceSet('foo', 'bar', 'baz', resources_only=True), deduped_sources)
예제 #7
0
 def test_dedup_test_sources(self):
   """Show that a is_test on a non resources_only source set turns on is_test"""
   deduped_sources = Project.dedup_sources([
     SourceSet('foo', 'bar', 'baz', is_test=True),
     SourceSet('foo', 'bar', 'baz'),
     SourceSet('foo', 'bar', 'baz', is_test=True),
   ])
   self.assert_dedup(SourceSet('foo', 'bar', 'baz', is_test=True), deduped_sources)
예제 #8
0
 def test_all_together(self):
   deduped_sources = Project.dedup_sources([
     SourceSet('foo', 'bar', 'baz', is_test=True, resources_only=False),
     SourceSet('foo', 'bar', 'baz', is_test=True, resources_only=True),
     SourceSet('foo', 'bar', 'baz', is_test=False, resources_only=True),
     SourceSet('foo', 'bar', 'baz', is_test=False, resources_only=False),
   ])
   self.assert_dedup(SourceSet('foo', 'bar', 'baz', is_test=True), deduped_sources)
예제 #9
0
 def test_dedup_sources_simple(self):
     self.assertEquals([
         SourceSet('foo', 'bar', ''),
         SourceSet('foo', 'bar', 'baz'),
         SourceSet('foo', 'bar', 'foobar')
     ],
                       Project.dedup_sources([
                           SourceSet('foo', 'bar', ''),
                           SourceSet('foo', 'bar', 'foobar'),
                           SourceSet('foo', 'bar', 'baz'),
                           SourceSet('foo', 'bar', 'baz'),
                           SourceSet('foo', 'bar', 'foobar'),
                           SourceSet('foo', 'bar', 'foobar'),
                           SourceSet('foo', 'bar', 'baz'),
                       ]))
예제 #10
0
  def test_collapse_source_root(self):
    source_set_list = []
    self.assertEquals([], Project._collapse_by_source_root(source_set_list))

    SourceRoot.register("src/java", JavaLibrary)
    SourceRoot.register("tests/java", JavaTests)
    source_sets = [
      SourceSet("/repo-root", "src/java", "org/pantsbuild/app", False),
      SourceSet("/repo-root", "tests/java", "org/pantsbuild/app", True),
      SourceSet("/repo-root", "some/other", "path", False),
    ]

    results = Project._collapse_by_source_root(source_sets)

    self.assertEquals(SourceSet("/repo-root", "src/java", "", False), results[0])
    self.assertFalse(results[0].is_test)
    self.assertEquals(SourceSet("/repo-root", "tests/java", "", True), results[1])
    self.assertTrue(results[1].is_test)
    # If there is no registered source root, the SourceSet should be returned unmodified
    self.assertEquals(source_sets[2], results[2])
    self.assertFalse(results[2].is_test)
예제 #11
0
    def test_sibling_is_test(self):
        SourceRoot.register("src/java", JavaLibrary)
        SourceRoot.register("src/resources", Resources)
        SourceRoot.register("tests/java", JavaTests, JavaLibrary)
        SourceRoot.register("tests/resources", Resources)

        src_java = SourceSet("repo-root", "src/java/com/pants", "project/lib",
                             False)
        self.assertFalse(IdeaGen._sibling_is_test(src_java))

        src_resources = SourceSet("repo-root", "src/resources/org/pantsbuild",
                                  "project/lib", False, 'java-resource')
        self.assertFalse(IdeaGen._sibling_is_test(src_resources))

        # Surprise! It doesn't matter what you pass for is_test when constructing the source set,
        # its detecting that one of the siblings under /tests/ is configured with a JavaTests target.
        tests_java = SourceSet("repo-root", "tests/java/org/pantsbuild",
                               "project/lib", False)
        self.assertTrue(IdeaGen._sibling_is_test(tests_java))

        tests_resources = SourceSet("repo-root",
                                    "tests/resources/org/pantsbuild",
                                    "project/lib", False)
        self.assertTrue(IdeaGen._sibling_is_test(tests_resources))