Ejemplo n.º 1
0
 def test_keyword_replaced(self):
     thrift_contents = dedent('''
   namespace py gen.twitter.tweetypie.tweet
   struct UrlEntity {
     1: i16 from
   }
 ''')
     expected_replaced_contents = dedent('''
   namespace py gen.twitter.tweetypie.tweet
   struct UrlEntity {
     1: i16 from_
   }
 ''')
     builder = PythonThriftBuilder(
         target=self.target('test_thrift_replacement:one'),
         root_dir=self.build_root,
         config=create_config(sample_ini=sample_ini_test))
     m = mock_open(read_data=thrift_contents)
     with patch('__builtin__.open', m, create=True):
         builder = PythonThriftBuilder(
             target=self.target('test_thrift_replacement:one'),
             root_dir=self.build_root,
             config=create_config(sample_ini=sample_ini_test))
         builder._modify_thrift('thrift_dummmy.thrift')
         expected_open_call_list = [
             call('thrift_dummmy.thrift'),
             call('thrift_dummmy.thrift', 'w')
         ]
         m.call_args_list == expected_open_call_list
         mock_file_handle = m()
         mock_file_handle.write.assert_called_once_with(
             expected_replaced_contents)
Ejemplo n.º 2
0
 def test_keyword_replaced(self):
   thrift_contents = dedent('''
     namespace py gen.twitter.tweetypie.tweet
     struct UrlEntity {
       1: i16 from
     }
   ''')
   expected_replaced_contents = dedent('''
     namespace py gen.twitter.tweetypie.tweet
     struct UrlEntity {
       1: i16 from_
     }
   ''')
   builder = PythonThriftBuilder(target=self.target('test_thrift_replacement:one'),
                                 root_dir=self.build_root,
                                 config=create_config(sample_ini=sample_ini_test))
   m = mock_open(read_data=thrift_contents)
   with patch('__builtin__.open', m, create=True):
     builder = PythonThriftBuilder(target=self.target('test_thrift_replacement:one'),
                                 root_dir=self.build_root,
                                 config=create_config(sample_ini=sample_ini_test))
     builder._modify_thrift('thrift_dummmy.thrift')
     expected_open_call_list = [call('thrift_dummmy.thrift'), call('thrift_dummmy.thrift', 'w')]
     m.call_args_list == expected_open_call_list
     mock_file_handle = m()
     mock_file_handle.write.assert_called_once_with(expected_replaced_contents)
Ejemplo n.º 3
0
def prepare_task(task_type, config=None, args=None, targets=None, **kwargs):
    """Prepares a Task for execution.

  task_type: The class of the Task to create.
  config: An optional string representing the contents of a pants.ini config.
  args: optional list of command line flags, these should be prefixed with '--test-'.
  targets: optional list of Target objects passed on the command line.
  **kwargs: Any additional args the Task subclass constructor takes beyond the required context.

  Returns a new Task ready to execute.
  """

    assert issubclass(
        task_type,
        Task), 'task_type must be a Task subclass, got %s' % task_type

    config = create_config(config or '')

    parser = OptionParser()
    option_group = OptionGroup(parser, 'test')
    mkflag = Mkflag('test')
    task_type.setup_parser(option_group, args, mkflag)
    options, _ = parser.parse_args(args or [])

    run_tracker = create_run_tracker()

    context = Context(config, options, run_tracker, targets or [])
    return task_type(context, **kwargs)
Ejemplo n.º 4
0
def prepare_task(task_type, config=None, args=None, targets=None, **kwargs):
  """Prepares a Task for execution.

  task_type: The class of the Task to create.
  config: An optional string representing the contents of a pants.ini config.
  args: optional list of command line flags, these should be prefixed with '--test-'.
  targets: optional list of Target objects passed on the command line.
  **kwargs: Any additional args the Task subclass constructor takes beyond the required context.

  Returns a new Task ready to execute.
  """

  assert issubclass(task_type, Task), 'task_type must be a Task subclass, got %s' % task_type

  config = create_config(config or '')

  parser = OptionParser()
  option_group = OptionGroup(parser, 'test')
  mkflag = Mkflag('test')
  task_type.setup_parser(option_group, args, mkflag)
  options, _ = parser.parse_args(args or [])

  run_tracker = create_run_tracker()

  context = Context(config, options, run_tracker, targets or [])
  return task_type(context, **kwargs)
Ejemplo n.º 5
0
  def test_keyword_replacement(self):
    m = mock_open(read_data='')
    with patch('__builtin__.open', m, create=True):
      with patch('shutil.copyfile'):
        builder = PythonThriftBuilder(target=self.target('test_thrift_replacement:one'),
                                    root_dir=self.build_root,
                                    config=create_config(sample_ini=sample_ini_test))

        builder._modify_thrift = MagicMock()
        builder._run_thrift = MagicMock()
        builder.run_thrifts()

        builder._modify_thrift.assert_called_once_with(os.path.realpath('%s/thrift/py-thrift/%s'
                                                                      % (self.build_root,
                                                                        'thrift/keyword.thrift')))
Ejemplo n.º 6
0
    def test_keyword_replacement(self):
        m = mock_open(read_data='')
        with patch('__builtin__.open', m, create=True):
            with patch('shutil.copyfile'):
                builder = PythonThriftBuilder(
                    target=self.target('test_thrift_replacement:one'),
                    root_dir=self.build_root,
                    config=create_config(sample_ini=sample_ini_test))

                builder._modify_thrift = MagicMock()
                builder._run_thrift = MagicMock()
                builder.run_thrifts()

                builder._modify_thrift.assert_called_once_with(
                    os.path.realpath(
                        '%s/thrift/py-thrift/%s' %
                        (self.build_root, 'thrift/keyword.thrift')))