示例#1
0
def create_context(options=None,
                   passthru_args=None,
                   target_roots=None,
                   build_graph=None,
                   build_file_parser=None,
                   address_mapper=None,
                   console_outstream=None,
                   workspace=None):
    """Creates a ``Context`` with no options or targets by default.

  :param options: A map of scope -> (map of key to value).

  Other params are as for ``Context``.
  """
    options = create_options(options or {}, passthru_args=passthru_args)
    run_tracker = TestContext.DummyRunTracker()
    target_roots = maybe_list(target_roots, Target) if target_roots else []
    return TestContext(options=options,
                       run_tracker=run_tracker,
                       target_roots=target_roots,
                       build_graph=build_graph,
                       build_file_parser=build_file_parser,
                       address_mapper=address_mapper,
                       console_outstream=console_outstream,
                       workspace=workspace)
示例#2
0
def create_context(options=None,
                   passthru_args=None,
                   target_roots=None,
                   build_graph=None,
                   build_file_parser=None,
                   address_mapper=None,
                   console_outstream=None,
                   workspace=None):
    """Creates a ``Context`` with no options or targets by default.

  :API: public

  :param options: A map of scope -> (map of key to value).

  Other params are as for ``Context``.
  """
    options = create_options(options or {}, passthru_args=passthru_args)
    return create_context_from_options(options,
                                       passthru_args=passthru_args,
                                       target_roots=target_roots,
                                       build_graph=build_graph,
                                       build_file_parser=build_file_parser,
                                       address_mapper=address_mapper,
                                       console_outstream=console_outstream,
                                       workspace=workspace)
示例#3
0
 def _plugin_for_testing(self):
     options_object = create_options({
         'foo': {
             'skip': False
         }
     }).for_scope('foo')
     return MinimalCheckstylePlugin(options_object,
                                    self._python_file_for_testing())
示例#4
0
def create_context(options=None, target_roots=None, build_graph=None,
                   build_file_parser=None, address_mapper=None,
                   console_outstream=None, workspace=None):
  """Creates a ``Context`` with no options or targets by default.

  :param options: A map of scope -> (map of key to value).

  Other params are as for ``Context``.
  """
  options = create_options(options or {})
  run_tracker = TestContext.DummyRunTracker()
  target_roots = maybe_list(target_roots, Target) if target_roots else []
  return TestContext(options=options, run_tracker=run_tracker, target_roots=target_roots,
                     build_graph=build_graph, build_file_parser=build_file_parser,
                     address_mapper=address_mapper, console_outstream=console_outstream,
                     workspace=workspace)
示例#5
0
 def test_log_exception(self):
   with temporary_dir() as workdir:
     exiter = Exiter()
     exiter.apply_options(create_options({ '': {
       'print_exception_stacktrace': True,
       'pants_workdir': workdir}
     }))
     exiter._log_exception('test-data')
     output_path = os.path.join(workdir, 'logs', 'exceptions.log')
     self.assertTrue(os.path.exists(output_path))
     with open(output_path, 'r') as exception_log:
       timestamp = exception_log.readline()
       args = exception_log.readline()
       pid = exception_log.readline()
       msg = exception_log.readline()
       self.assertIn('timestamp: ', timestamp)
       self.assertIn('args: [', args)
       self.assertIn('pid: {}'.format(os.getpid()), pid)
       self.assertIn('test-data', msg)
示例#6
0
def create_context(options=None, passthru_args=None, target_roots=None, build_graph=None,
                   build_file_parser=None, address_mapper=None,
                   console_outstream=None, workspace=None):
  """Creates a ``Context`` with no options or targets by default.

  :API: public

  :param options: A map of scope -> (map of key to value).

  Other params are as for ``Context``.
  """
  options = create_options(options or {}, passthru_args=passthru_args)
  return create_context_from_options(options,
                                     passthru_args=passthru_args,
                                     target_roots=target_roots,
                                     build_graph=build_graph,
                                     build_file_parser=build_file_parser,
                                     address_mapper=address_mapper,
                                     console_outstream=console_outstream,
                                     workspace=workspace)
示例#7
0
 def cache_factory(self, **options):
   cache_options = {
     'pinger_timeout': .5,
     'pinger_tries': 2,
     'ignore': False,
     'read': False,
     'read_from': [self.EMPTY_URI],
     'write_to': [self.EMPTY_URI],
     'write': False,
     'compression_level': 1,
     'max_entries_per_target': 1,
     'write_permissions': None,
     'dereference_symlinks': True,
     # Usually read from global scope.
     'pants_workdir': self.pants_workdir
   }
   cache_options.update(**options)
   return CacheFactory(create_options(options={'test': cache_options}).for_scope('test'),
                       MockLogger(),
                       self.create_task(),
                       resolver=self.resolver)
示例#8
0
 def cache_factory(self, **options):
   cache_options = {
     'pinger_timeout': .5,
     'pinger_tries': 2,
     'ignore': False,
     'read': False,
     'read_from': [self.EMPTY_URI],
     'write_to': [self.EMPTY_URI],
     'write': False,
     'compression_level': 1,
     'max_entries_per_target': 1,
     'write_permissions': None,
     'dereference_symlinks': True,
     # Usually read from global scope.
     'pants_workdir': self.pants_workdir
   }
   cache_options.update(**options)
   return CacheFactory(create_options(options={'test': cache_options}).for_scope('test'),
                       MockLogger(),
                       self.create_task(),
                       resolver=self.resolver)
示例#9
0
 def test_log_exception(self):
     with temporary_dir() as workdir:
         exiter = Exiter()
         exiter.apply_options(
             create_options({
                 '': {
                     'print_exception_stacktrace': True,
                     'pants_workdir': workdir
                 }
             }))
         exiter._log_exception('test-data')
         output_path = os.path.join(workdir, 'logs', 'exceptions.log')
         self.assertTrue(os.path.exists(output_path))
         with open(output_path, 'r') as exception_log:
             timestamp = exception_log.readline()
             args = exception_log.readline()
             pid = exception_log.readline()
             msg = exception_log.readline()
             self.assertIn('timestamp: ', timestamp)
             self.assertIn('args: [', args)
             self.assertIn('pid: {}'.format(os.getpid()), pid)
             self.assertIn('test-data', msg)
示例#10
0
 def _plugin_for_testing(self):
   options_object = create_options({'foo': {'skip': False}}).for_scope('foo')
   return MinimalCheckstylePlugin(options_object, self._python_file_for_testing())
示例#11
0
 def get_plugin(self, file_content, **options):
     python_file = self.create_python_file(file_content)
     full_options = copy.copy(options)
     full_options['skip'] = False
     options_object = create_options({'foo': full_options}).for_scope('foo')
     return self.plugin_type(options_object, python_file)
示例#12
0
 def get_plugin(self, file_content, **options):
   python_file = self.create_python_file(file_content)
   full_options = copy.copy(options)
   full_options['skip'] = False
   options_object = create_options({'foo': full_options}).for_scope('foo')
   return self.plugin_type(options_object, python_file)