Esempio n. 1
0
 def test_smoke_publish(self):
   task = prepare_task(JarPublish,
                       args=['--test-local=/tmp'],
                       build_graph=self.build_graph,
                       build_file_parser=self.build_file_parser)
   task.scm = Mock()
   task.execute([])
Esempio n. 2
0
    def test_cmdline_only(self):
        jvm_binary = self.make_target('src/java/com/pants:binary',
                                      JvmBinary,
                                      main="com.pants.Binary")
        jvm_run = prepare_task(JvmRun,
                               args=['--test-only-write-cmd-line=a'],
                               targets=[jvm_binary])

        round_manager = RoundManager(jvm_run.context)
        jvm_run.prepare(round_manager)

        self.populate_exclusive_groups(context=jvm_run.context,
                                       classpaths=['bob', 'fred'])

        with temporary_dir() as pwd:
            with pushd(pwd):
                cmdline_file = os.path.join(pwd, 'a')
                self.assertFalse(os.path.exists(cmdline_file))
                jvm_run.execute()
                self.assertTrue(os.path.exists(cmdline_file))
                with open(cmdline_file) as fp:
                    contents = fp.read()
                    expected_suffix = 'java -cp bob:fred com.pants.Binary'
                    self.assertEquals(expected_suffix,
                                      contents[-len(expected_suffix):])
Esempio n. 3
0
  def test_publish_remote(self):
    targets = self._prepare_for_publishing()

    task = prepare_task(JarPublish,
                        config=self._get_config(),
                        args=['--no-test-dryrun'],
                        build_graph=self.build_graph,
                        build_file_parser=self.build_file_parser,
                        targets=targets)
    self._prepare_mocks(task)
    task.execute()

    # One file per task is written to the pushdb during a local publish
    files = []
    for _, _, filenames in os.walk(self.push_db_basedir):
      files.extend(filenames)
    self.assertEquals(len(targets), len(files),
                      "During a remote publish, one pushdb should be written per target")

    self.assertEquals(len(targets), task.confirm_push.call_count,
                      "Expected one call to confirm_push per artifact")
    self.assertEquals(len(targets), task.publish.call_count,
                      "Expected one call to publish per artifact")
    self.assertEquals(len(targets), task.scm.tag.call_count,
                      "Expected one call to scm.tag per artifact")
Esempio n. 4
0
    def test_sigpipe(self):
        r, w = os.pipe()
        task = prepare_task(task_type=self.Infinite,
                            outstream=os.fdopen(w, 'w'),
                            build_graph=self.build_graph,
                            build_file_parser=self.build_file_parser)

        raised = Queue(maxsize=1)

        def execute():
            try:
                task.execute()
            except IOError as e:
                raised.put(e)

        execution = threading.Thread(target=execute,
                                     name='ConsoleTaskTest_sigpipe')
        execution.setDaemon(True)
        execution.start()
        try:
            data = os.read(r, 5)
            self.assertEqual('jake\n', data)
            os.close(r)
        finally:
            task.stop()
            execution.join()

        with pytest.raises(Empty):
            e = raised.get_nowait()

            # Instead of taking the generic pytest.raises message, provide a more detailed failure
            # message that shows exactly what untrapped error was on the queue.
            self.fail('task raised %s' % e)
Esempio n. 5
0
  def test_publish_local(self):
    targets = self._prepare_for_publishing()

    with temporary_dir() as publish_dir:
      task = prepare_task(JarPublish,
                          args=['--test-local=%s' % publish_dir,
                                '--no-test-dryrun'],
                          build_graph=self.build_graph,
                          build_file_parser=self.build_file_parser,
                          targets=targets)
      self._prepare_mocks(task)
      task.execute()

      #Nothing is written to the pushdb during a local publish
      #(maybe some directories are created, but git will ignore them)
      files = []
      for _, _, filenames in os.walk(self.push_db_basedir):
        files.extend(filenames)
      self.assertEquals(0, len(files),
                        "Nothing should be written to the pushdb during a local publish")

      self.assertEquals(len(targets), task.confirm_push.call_count,
                        "Expected one call to confirm_push per artifact")
      self.assertEquals(len(targets), task.publish.call_count,
                        "Expected one call to publish per artifact")
Esempio n. 6
0
  def test_publish_unlisted_repo(self):
    # Note that we set a different config here, so repos:internal has no config
    config = """
[jar-publish]
repos: {
    'another-repo': {
      'resolver': 'example.org',
      'confs': ['default', 'sources', 'docs', 'changelog'],
    }
  }
"""

    targets = self._prepare_for_publishing()
    with temporary_dir() as publish_dir:
      task = prepare_task(JarPublish,
                          config=config,
                          args=['--no-test-dryrun'],
                          build_graph=self.build_graph,
                          build_file_parser=self.build_file_parser,
                          targets=targets)
      self._prepare_mocks(task)
      with self.assertRaises(TaskError):
        try:
          task.execute()
        except TaskError as e:
          assert "Repository internal has no" in str(e)
          raise e
Esempio n. 7
0
  def test_sigpipe(self):
    r, w = os.pipe()
    task = prepare_task(self.Infinite, outstream=os.fdopen(w, 'w'))

    raised = Queue(maxsize=1)

    def execute():
      try:
        task.execute([])
      except IOError as e:
        raised.put(e)

    execution = threading.Thread(target=execute, name='ConsoleTaskTest_sigpipe')
    execution.setDaemon(True)
    execution.start()
    try:
      data = os.read(r, 5)
      self.assertEqual('jake\n', data)
      os.close(r)
    finally:
      task.stop()
      execution.join()

    with pytest.raises(Empty):
      e = raised.get_nowait()

      # Instead of taking the generic pytest.raises message, provide a more detailed failure
      # message that shows exactly what untrapped error was on the queue.
      self.fail('task raised %s' % e)
Esempio n. 8
0
  def test_ragel_gen(self):
    self.create_file(relpath='test_ragel_gen/atoi.rl', contents=ragel_file_contents)
    self.add_to_build_file('test_ragel_gen', dedent("""
      java_ragel_library(name='atoi',
        sources=['atoi.rl'],
        dependencies=[]
      )
    """))

    task = prepare_task(RagelGen,
                        build_graph=self.build_graph,
                        targets=[self.target('test_ragel_gen:atoi')],
                        build_file_parser=self.build_file_parser)

    task._ragel_binary = 'ragel'
    task.invalidate_for_files = lambda: []
    task._java_out = self.task_outdir

    sources = [os.path.join(self.task_outdir, 'com/example/atoi/Parser.java')]

    try:
      saved_add_new_target = Context.add_new_target
      Context.add_new_target = MagicMock()
      task.execute()
      relative_task_outdir = os.path.relpath(self.task_outdir, get_buildroot())
      spec = '{spec_path}:{name}'.format(spec_path=relative_task_outdir, name='test_ragel_gen.atoi')
      address = SyntheticAddress.parse(spec=spec)
      Context.add_new_target.assert_called_once_with(address,
                                                     JavaRagelLibrary,
                                                     sources=sources,
                                                     excludes=OrderedSet(),
                                                     dependencies=OrderedSet(),
                                                     provides=None)
    finally:
      Context.add_new_target = saved_add_new_target
Esempio n. 9
0
 def test_smoke_publish(self):
   with temporary_dir() as publish_dir:
     task = prepare_task(JarPublish,
                       args=['--test-local=%s' % publish_dir],
                       build_graph=self.build_graph,
                       build_file_parser=self.build_file_parser)
     task.scm = Mock()
     task.execute()
Esempio n. 10
0
 def test_smoke_publish(self):
     with temporary_dir() as publish_dir:
         task = prepare_task(JarPublish,
                             args=['--test-local=%s' % publish_dir],
                             build_graph=self.build_graph,
                             build_file_parser=self.build_file_parser)
         task.scm = Mock()
         task.execute()
Esempio n. 11
0
    def test_smoke(self):
        contents = dedent(
            """namespace java com.pants.example
      struct Example {
      1: optional i64 number
      }
    """
        )

        self.create_file(relpath="test_smoke/a.thrift", contents=contents)
        self.add_to_build_file(
            "test_smoke",
            dedent(
                """
      java_thrift_library(name='a',
        sources=['a.thrift'],
        dependencies=[],
        compiler='scrooge',
        language='scala',
        rpc_style='finagle'
      )
    """
            ),
        )

        target = self.target("test_smoke:a")
        task = prepare_task(
            ScroogeGen, build_graph=self.build_graph, targets=[target], build_file_parser=self.build_file_parser
        )

        with patch("pants.backend.codegen.tasks.scrooge_gen.calculate_services"):
            task._outdir = MagicMock()
            task._outdir.return_value = self.task_outdir

            task.gen = MagicMock()
            sources = [os.path.join(self.task_outdir, "com/pants/example/Example.scala")]
            task.gen.return_value = {"test_smoke/a.thrift": sources}

            try:
                saved_add_new_target = Context.add_new_target
                Context.add_new_target = MagicMock()
                task.execute()
                relative_task_outdir = os.path.relpath(self.task_outdir, get_buildroot())
                spec = "{spec_path}:{name}".format(spec_path=relative_task_outdir, name="test_smoke.a")
                address = SyntheticAddress.parse(spec=spec)
                Context.add_new_target.assert_called_once_with(
                    address,
                    ScalaLibrary,
                    sources=sources,
                    excludes=OrderedSet(),
                    dependencies=OrderedSet(),
                    provides=None,
                    derived_from=target,
                )
            finally:
                Context.add_new_target = saved_add_new_target
Esempio n. 12
0
  def test_smoke(self):
    contents = dedent('''namespace java com.pants.example
      struct Example {
      1: optional i64 number
      }
    ''')

    self.create_file(relpath='test_smoke/a.thrift', contents=contents)
    self.add_to_build_file('test_smoke', dedent('''
      java_thrift_library(name='a',
        sources=['a.thrift'],
        dependencies=[],
        compiler='scrooge',
        language='scala',
        rpc_style='finagle'
      )
    '''))

    target = self.target('test_smoke:a')
    task = prepare_task(ScroogeGen,
                        build_graph=self.build_graph,
                        targets=[target],
                        build_file_parser=self.build_file_parser)

    with patch('pants.backend.codegen.tasks.scrooge_gen.calculate_services'):
      task._outdir = MagicMock()
      task._outdir.return_value = self.task_outdir

      task.gen = MagicMock()
      sources = [os.path.join(self.task_outdir, 'com/pants/example/Example.scala')]
      task.gen.return_value = {'test_smoke/a.thrift': sources}

      try:
        saved_add_new_target = Context.add_new_target
        Context.add_new_target = MagicMock()
        task.execute()
        relative_task_outdir = os.path.relpath(self.task_outdir, get_buildroot())
        spec = '{spec_path}:{name}'.format(spec_path=relative_task_outdir, name='test_smoke.a')
        address = SyntheticAddress.parse(spec=spec)
        Context.add_new_target.assert_called_once_with(address,
                                                       ScalaLibrary,
                                                       sources=sources,
                                                       excludes=OrderedSet(),
                                                       dependencies=OrderedSet(),
                                                       provides=None,
                                                       derived_from=target)
      finally:
        Context.add_new_target = saved_add_new_target
Esempio n. 13
0
  def test_publish_retry_eventually_fails(self):
    targets = self._prepare_for_publishing()

    #confirm that we fail if we have too many failed push attempts
    task = prepare_task(JarPublish,
                        config=self._get_config(),
                        args=['--no-test-dryrun',
                              '--test-scm-push-attempts=3'],
                        build_graph=self.build_graph,
                        build_file_parser=self.build_file_parser,
                        targets=[targets[0]])
    self._prepare_mocks(task)
    task.scm.push = Mock()
    task.scm.push.side_effect = FailNTimes(3, Scm.RemoteException)
    with self.assertRaises(Scm.RemoteException):
      task.execute()
Esempio n. 14
0
  def test_publish_retry_works(self):
    targets = self._prepare_for_publishing()

    task = prepare_task(JarPublish,
                        config=self._get_config(),
                        args=['--no-test-dryrun',
                              '--test-scm-push-attempts=3'],
                        build_graph=self.build_graph,
                        build_file_parser=self.build_file_parser,
                        targets=[targets[0]])
    self._prepare_mocks(task)

    task.scm.push = Mock()
    task.scm.push.side_effect = FailNTimes(2, Scm.RemoteException)
    task.execute()
    # Two failures, one success
    self.assertEquals(2 + 1, task.scm.push.call_count)
Esempio n. 15
0
    def test_ragel_gen(self):
        self.create_file(relpath='test_ragel_gen/atoi.rl',
                         contents=ragel_file_contents)
        self.add_to_build_file(
            'test_ragel_gen',
            dedent("""
      java_ragel_library(name='atoi',
        sources=['atoi.rl'],
        dependencies=[]
      )
    """))

        task = prepare_task(RagelGen,
                            build_graph=self.build_graph,
                            targets=[self.target('test_ragel_gen:atoi')],
                            build_file_parser=self.build_file_parser)

        task._ragel_binary = 'ragel'
        task.invalidate_for_files = lambda: []
        task._java_out = self.task_outdir

        sources = [
            os.path.join(self.task_outdir, 'com/example/atoi/Parser.java')
        ]

        try:
            saved_add_new_target = Context.add_new_target
            Context.add_new_target = MagicMock()
            task.execute()
            relative_task_outdir = os.path.relpath(self.task_outdir,
                                                   get_buildroot())
            spec = '{spec_path}:{name}'.format(spec_path=relative_task_outdir,
                                               name='test_ragel_gen.atoi')
            address = SyntheticAddress.parse(spec=spec)
            Context.add_new_target.assert_called_once_with(
                address,
                JavaRagelLibrary,
                sources=sources,
                excludes=OrderedSet(),
                dependencies=OrderedSet(),
                provides=None)
        finally:
            Context.add_new_target = saved_add_new_target
Esempio n. 16
0
  def test_cmdline_only(self):
    jvm_binary = self.make_target('src/java/com/pants:binary', JvmBinary, main="com.pants.Binary")
    jvm_run = prepare_task(JvmRun, args=['--test-only-write-cmd-line=a'], targets=[jvm_binary])

    round_manager = RoundManager(jvm_run.context)
    jvm_run.prepare(round_manager)

    self.populate_exclusive_groups(context=jvm_run.context, classpaths=['bob', 'fred'])

    with temporary_dir() as pwd:
      with pushd(pwd):
        cmdline_file = os.path.join(pwd, 'a')
        self.assertFalse(os.path.exists(cmdline_file))
        jvm_run.execute()
        self.assertTrue(os.path.exists(cmdline_file))
        with open(cmdline_file) as fp:
          contents = fp.read()
          expected_suffix = 'java -cp bob:fred com.pants.Binary'
          self.assertEquals(expected_suffix, contents[-len(expected_suffix):])
Esempio n. 17
0
  def test_smoke(self):
    contents = dedent('''namespace java com.pants.example
      struct Example {
      1: optional i64 number
      }
    ''')

    self.create_file(relpath='test_smoke/a.thrift', contents=contents)
    self.add_to_build_file('test_smoke', dedent('''
      java_thrift_library(name='a',
        sources=['a.thrift'],
        dependencies=[],
        compiler='scrooge',
        language='scala',
        rpc_style='finagle'
      )
    '''))
    task_outdir = os.path.join(self.build_root, '.pants.d')
    task = prepare_task(ScroogeGen,
                        build_graph=self.build_graph,
                        targets=[self.target('test_smoke:a')],
                        build_file_parser=self.build_file_parser)

    with patch('pants.backend.codegen.tasks.scrooge_gen.calculate_services'):
      task._outdir = MagicMock()
      task._outdir.return_value = task_outdir

      task.gen = MagicMock()
      sources = [os.path.join(task_outdir, 'com/pants/example/Example.scala')]
      task.gen.return_value = {'test_smoke/a.thrift': sources}

      Context.add_new_target = MagicMock()
      task.execute()
      relative_task_outdir = os.path.relpath(task_outdir, get_buildroot())
      spec = '{spec_path}:{name}'.format(spec_path=relative_task_outdir, name='test_smoke.a')
      address = SyntheticAddress.parse(spec=spec)
      Context.add_new_target.assert_called_once_with(address,
                                                     ScalaLibrary,
                                                     sources=sources,
                                                     excludes=OrderedSet(),
                                                     dependencies=OrderedSet(),
                                                     provides=None)
Esempio n. 18
0
 def test_publish_local_only(self):
   with pytest.raises(TaskError) as exc:
     prepare_task(JarPublish)
Esempio n. 19
0
 def execute_task(self, config=sample_ini_test_1):
   with closing(StringIO()) as output:
     task = prepare_task(BuildBuildDictionary, config=config)
     task.execute()
     return output.getvalue()
Esempio n. 20
0
 def test_publish_local_only(self):
   with pytest.raises(TaskError) as exc:
     prepare_task(JarPublish)