Пример #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__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)
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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)
Пример #13
0
  def _get_resource_extensions(self, project):
    resource_extensions = set()
    resource_extensions.update(project.resource_extensions)

    # TODO(John Sirois): make test resources 1st class in ant build and punch this through to pants
    # model
    for _, _, files in safe_walk(os.path.join(get_buildroot(), 'tests', 'resources')):
      resource_extensions.update(Project.extract_resource_extensions(files))

    return resource_extensions
Пример #14
0
  def _get_resource_extensions(self, project):
    resource_extensions = set()
    resource_extensions.update(project.resource_extensions)

    # TODO(John Sirois): make test resources 1st class in ant build and punch this through to pants
    # model
    for _, _, files in safe_walk(os.path.join(get_buildroot(), 'tests', 'resources')):
      resource_extensions.update(Project.extract_resource_extensions(files))

    return resource_extensions
Пример #15
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)
Пример #16
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'),
   ]))
Пример #17
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)
Пример #18
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'),
                       ]))