Esempio n. 1
0
 def context(self, config='', options=None, target_roots=None, **kwargs):
   return create_context(config=self.config(overrides=config),
                         options=self.create_options(**(options or {})),
                         target_roots=target_roots,
                         build_graph=self.build_graph,
                         build_file_parser=self.build_file_parser,
                         **kwargs)
Esempio n. 2
0
 def context(self, config='', **options):
   return create_context(config=self.config(overrides=config),
                         old_options=self.create_options(**options),
                         build_graph=self.build_graph,
                         build_file_parser=self.build_file_parser,
                         address_mapper=self.address_mapper,
                         target_roots=[self.jl, self.sl, self.binary, self.jtl, self.scala_lib])
Esempio n. 3
0
 def context(self, config='', options=None, target_roots=None, **kwargs):
   return create_context(config=self.config(overrides=config),
                         options=self.create_options(**(options or {})),
                         target_roots=target_roots,
                         build_graph=self.build_graph,
                         build_file_parser=self.build_file_parser,
                         **kwargs)
Esempio n. 4
0
 def test_binary_create_init(self):
   options = {'jvm_binary_create_outdir': None,
              'binary_create_compressed': None,
              'binary_create_zip64': None,
              'jvm_binary_create_deployjar': None}
   binary_create = BinaryCreate(create_context(config=sample_ini_test_1, options=options))
   self.assertEquals(binary_create.outdir, '/tmp/dist')
Esempio n. 5
0
  def setUp(self):
    super(GroupEngineTest, self).setUp()

    self.java_library('src/java', 'a')
    self.scala_library('src/scala', 'b', deps=['src/java:a'])
    self.java_library('src/java', 'c', deps=['src/scala:b'])
    self.scala_library('src/scala', 'd', deps=['src/java:c'])
    self.java_library('src/java', 'e', deps=['src/scala:d'])
    self.python_library('src/python', 'f')

    self.context = create_context(options=dict(explain=False),
                                  target_roots=self.targets('src/java:e', 'src/python:f'),
                                  build_graph=self.build_graph,
                                  build_file_parser=self.build_file_parser)
    self.assertTrue(self.context.is_unlocked())

    # TODO(John Sirois): disentangle GroupEngine from relying upon the CheckExclusives task being
    # run.  It should either arrange this directly or else the requirement should be in a different
    # layer.
    exclusives_mapping = ExclusivesMapping(self.context)
    exclusives_mapping._populate_target_maps(self.context.targets())
    self.context.products.safe_create_data('exclusives_groups', lambda: exclusives_mapping)

    self.engine = GroupEngine()
    self.recorded_actions = []
Esempio n. 6
0
    def context(self,
                for_task_types=None,
                options=None,
                passthru_args=None,
                target_roots=None,
                console_outstream=None,
                workspace=None,
                for_subsystems=None):

        # Many tests use source root functionality via the SourceRootConfig.global_instance()
        # (typically accessed via Target.target_base), so we always set it up, for convenience.
        optionables = {SourceRootConfig}
        extra_scopes = set()

        for_subsystems = for_subsystems or ()
        for subsystem in for_subsystems:
            if subsystem.options_scope is None:
                raise TaskError(
                    'You must set a scope on your subsystem type before using it in tests.'
                )
            optionables.add(subsystem)

        for_task_types = for_task_types or ()
        for task_type in for_task_types:
            scope = task_type.options_scope
            if scope is None:
                raise TaskError(
                    'You must set a scope on your task type before using it in tests.'
                )
            optionables.add(task_type)
            extra_scopes.update(
                [si.scope for si in task_type.known_scope_infos()])
            optionables.update(
                Subsystem.closure(
                    set([
                        dep.subsystem_cls
                        for dep in task_type.subsystem_dependencies_iter()
                    ]) | self._build_configuration.subsystems()))

        # Now default the option values and override with any caller-specified values.
        # TODO(benjy): Get rid of the options arg, and require tests to call set_options.
        options = options.copy() if options else {}
        for s, opts in self.options.items():
            scoped_opts = options.setdefault(s, {})
            scoped_opts.update(opts)

        options = create_options_for_optionables(optionables,
                                                 extra_scopes=extra_scopes,
                                                 options=options)
        Subsystem._options = options
        context = create_context(options=options,
                                 passthru_args=passthru_args,
                                 target_roots=target_roots,
                                 build_graph=self.build_graph,
                                 build_file_parser=self.build_file_parser,
                                 address_mapper=self.address_mapper,
                                 console_outstream=console_outstream,
                                 workspace=workspace)
        return context
Esempio n. 7
0
    def test_successful_request_calls_hit_callback(self):
        context = create_context()
        key = CacheKey('muppet_key', 'fake_hash', 42)

        with self.setup_local_cache() as cache:
            self._do_test_successful_request_runs_callback(cache, context, key)

        with self.setup_rest_cache() as cache:
            self._do_test_successful_request_runs_callback(cache, context, key)
Esempio n. 8
0
  def test_successful_request_calls_hit_callback(self):
    context = create_context()
    key = CacheKey('muppet_key', 'fake_hash', 42)

    with self.setup_local_cache() as cache:
      self._do_test_successful_request_runs_callback(cache, context, key)

    with self.setup_rest_cache() as cache:
      self._do_test_successful_request_runs_callback(cache, context, key)
Esempio n. 9
0
 def context(self, config='', **options):
     return create_context(config=config,
                           options=self.create_options(**options),
                           build_graph=self.build_graph,
                           build_file_parser=self.build_file_parser,
                           target_roots=[
                               self.jl, self.sl, self.binary, self.jtl,
                               self.scala_lib
                           ])
Esempio n. 10
0
 def test_bundle_create_init(self):
   options = {
              'bundle_create_deployjar': None,
              'bundle_create_prefix': None,
              'bundle_create_archive': None
              }
   bundle_create = BundleCreate(create_context(config=sample_ini_test_1, options=options),
                                '/tmp/workdir')
   self.assertEquals(bundle_create._outdir, '/tmp/dist')
Esempio n. 11
0
 def context(self, config='', **options):
     return create_context(config=self.config(overrides=config),
                           options=self.create_options(**options),
                           build_graph=self.build_graph,
                           build_file_parser=self.build_file_parser,
                           address_mapper=self.address_mapper,
                           target_roots=[
                               self.jl, self.sl, self.binary, self.jtl,
                               self.scala_lib
                           ])
Esempio n. 12
0
  def test_failed_multiproc(self):
    context = create_context()
    key = CacheKey('muppet_key', 'fake_hash', 55)

    # Failed requests should return failure status, but not raise exceptions
    with self.setup_rest_cache(return_failed=True) as cache:
      self.assertFalse(context.subproc_map(call_use_cached_files, [(cache, key, None)])[0])
      with self.setup_test_file(cache.artifact_root) as path:
        context.subproc_map(call_insert, [(cache, key, [path], False)])
      self.assertFalse(context.subproc_map(call_use_cached_files, [(cache, key, None)])[0])
Esempio n. 13
0
 def test_bundle_create_init(self):
     options = {
         'bundle_create_deployjar': None,
         'bundle_create_prefix': None,
         'bundle_create_archive': None
     }
     bundle_create = BundleCreate(
         create_context(config=sample_ini_test_1, options=options),
         '/tmp/workdir')
     self.assertEquals(bundle_create._outdir, '/tmp/dist')
Esempio n. 14
0
  def test_jar_create_init(self):
    ini = dedent("""
          [DEFAULT]
          pants_workdir: /tmp/pants.d
          pants_supportdir: /tmp/build-support
          """).strip()

    jar_create = JarCreate(create_context(config=ini, options=self.create_options()))
    self.assertEquals(jar_create._output_dir, '/tmp/pants.d/jars')
    self.assertEquals(jar_create.confs, ['default'])
Esempio n. 15
0
    def context(self,
                for_task_types=None,
                options=None,
                target_roots=None,
                console_outstream=None,
                workspace=None,
                for_subsystems=None):

        optionables = set()
        extra_scopes = set()

        for_subsystems = for_subsystems or ()
        for subsystem in for_subsystems:
            if subsystem.options_scope is None:
                raise TaskError(
                    'You must set a scope on your subsystem type before using it in tests.'
                )
            optionables.add(subsystem)

        for_task_types = for_task_types or ()
        for task_type in for_task_types:
            scope = task_type.options_scope
            if scope is None:
                raise TaskError(
                    'You must set a scope on your task type before using it in tests.'
                )
            optionables.add(task_type)
            extra_scopes.update(
                [si.scope for si in task_type.known_scope_infos()])
            optionables.update(
                Subsystem.closure(
                    set([
                        dep.subsystem_cls
                        for dep in task_type.subsystem_dependencies_iter()
                    ]) | self._build_configuration.subsystems()))

        # Now default the option values and override with any caller-specified values.
        # TODO(benjy): Get rid of the options arg, and require tests to call set_options.
        options = options.copy() if options else {}
        for s, opts in self.options.items():
            scoped_opts = options.setdefault(s, {})
            scoped_opts.update(opts)

        option_values = create_options_for_optionables(
            optionables, extra_scopes=extra_scopes, options=options)

        context = create_context(options=option_values,
                                 target_roots=target_roots,
                                 build_graph=self.build_graph,
                                 build_file_parser=self.build_file_parser,
                                 address_mapper=self.address_mapper,
                                 console_outstream=console_outstream,
                                 workspace=workspace)
        Subsystem._options = context.options
        return context
Esempio n. 16
0
    def context(
        self,
        for_task_types=None,
        options=None,
        passthru_args=None,
        target_roots=None,
        console_outstream=None,
        workspace=None,
        for_subsystems=None,
    ):

        optionables = set()
        extra_scopes = set()

        for_subsystems = for_subsystems or ()
        for subsystem in for_subsystems:
            if subsystem.options_scope is None:
                raise TaskError("You must set a scope on your subsystem type before using it in tests.")
            optionables.add(subsystem)

        for_task_types = for_task_types or ()
        for task_type in for_task_types:
            scope = task_type.options_scope
            if scope is None:
                raise TaskError("You must set a scope on your task type before using it in tests.")
            optionables.add(task_type)
            extra_scopes.update([si.scope for si in task_type.known_scope_infos()])
            optionables.update(
                Subsystem.closure(
                    set([dep.subsystem_cls for dep in task_type.subsystem_dependencies_iter()])
                    | self._build_configuration.subsystems()
                )
            )

        # Now default the option values and override with any caller-specified values.
        # TODO(benjy): Get rid of the options arg, and require tests to call set_options.
        options = options.copy() if options else {}
        for s, opts in self.options.items():
            scoped_opts = options.setdefault(s, {})
            scoped_opts.update(opts)

        option_values = create_options_for_optionables(optionables, extra_scopes=extra_scopes, options=options)

        context = create_context(
            options=option_values,
            passthru_args=passthru_args,
            target_roots=target_roots,
            build_graph=self.build_graph,
            build_file_parser=self.build_file_parser,
            address_mapper=self.address_mapper,
            console_outstream=console_outstream,
            workspace=workspace,
        )
        Subsystem._options = context.options
        return context
Esempio n. 17
0
  def test_jar_create_init(self):
    ini = dedent("""
          [DEFAULT]
          pants_supportdir: /tmp/build-support
          """).strip()

    JarCreate(create_context(config=ini,
                             options=self.create_options(),
                             build_graph=self.build_graph,
                             build_file_parser=self.build_file_parser),
              '/tmp/workdir')
Esempio n. 18
0
    def test_failed_request_doesnt_call_hit_callback(self):
        context = create_context()
        key = CacheKey('muppet_key', 'fake_hash', 55)
        with self.setup_local_cache() as cache:
            self.assertEquals(
                context.subproc_map(call_use_cached_files,
                                    [(cache, key, raising_callback)]), [False])

        with self.setup_rest_cache() as cache:
            self.assertEquals(
                context.subproc_map(call_use_cached_files,
                                    [(cache, key, raising_callback)]), [False])
Esempio n. 19
0
    def test_jar_create_init(self):
        ini = dedent("""
          [DEFAULT]
          pants_supportdir: /tmp/build-support
          """).strip()

        JarCreate(
            create_context(config=ini,
                           options=self.create_options(),
                           build_graph=self.build_graph,
                           build_file_parser=self.build_file_parser),
            '/tmp/workdir')
Esempio n. 20
0
    def test_failed_multiproc(self):
        context = create_context()
        key = CacheKey('muppet_key', 'fake_hash', 55)

        # Failed requests should return failure status, but not raise exceptions
        with self.setup_rest_cache(return_failed=True) as cache:
            self.assertFalse(
                context.subproc_map(call_use_cached_files, [(cache, key)])[0])
            with self.setup_test_file(cache.artifact_root) as path:
                context.subproc_map(call_insert, [(cache, key, [path], False)])
            self.assertFalse(
                context.subproc_map(call_use_cached_files, [(cache, key)])[0])
Esempio n. 21
0
  def test_failed_request_doesnt_call_hit_callback(self):
    context = create_context()
    key = CacheKey('muppet_key', 'fake_hash', 55)
    with self.setup_local_cache() as cache:
      self.assertEquals(
        context.subproc_map(call_use_cached_files, [(cache, key, raising_callback)]),
        [False])

    with self.setup_rest_cache() as cache:
      self.assertEquals(
        context.subproc_map(call_use_cached_files, [(cache, key, raising_callback)]),
        [False])
Esempio n. 22
0
    def context(self,
                for_task_types=None,
                config='',
                options=None,
                new_options=None,
                target_roots=None,
                **kwargs):
        for_task_types = for_task_types or []
        new_options = new_options or {}

        new_option_values = defaultdict(dict)

        # Get values for all new-style options registered by the tasks in for_task_types.
        for task_type in for_task_types:
            scope = task_type.options_scope
            if scope is None:
                raise TaskError(
                    'You must set a scope on your task type before using it in tests.'
                )

            # We provide our own test-only registration implementation, bypassing argparse.
            # When testing we set option values directly, so we don't care about cmd-line flags, config,
            # env vars etc. In fact, for test isolation we explicitly don't want to look at those.
            def register(*rargs, **rkwargs):
                scoped_options = new_option_values[scope]
                default = rkwargs.get('default')
                if default is None and rkwargs.get('action') == 'append':
                    default = []
                for flag_name in rargs:
                    option_name = flag_name.lstrip('-').replace('-', '_')
                    scoped_options[option_name] = default

            task_type.register_options(register)

        # Now override with any caller-specified values.

        # TODO(benjy): Get rid of the new_options arg, and require tests to call set_new_options.
        for scope, opts in new_options.items():
            for key, val in opts.items():
                new_option_values[scope][key] = val

        for scope, opts in self.new_options.items():
            for key, val in opts.items():
                new_option_values[scope][key] = val

        return create_context(config=self.config(overrides=config),
                              new_options=new_option_values,
                              target_roots=target_roots,
                              build_graph=self.build_graph,
                              build_file_parser=self.build_file_parser,
                              address_mapper=self.address_mapper,
                              **kwargs)
Esempio n. 23
0
  def context(self, for_task_types=None, options=None, passthru_args=None, target_roots=None,
              console_outstream=None, workspace=None, for_subsystems=None):
    """
    :API: public
    """
    # Many tests use source root functionality via the SourceRootConfig.global_instance()
    # (typically accessed via Target.target_base), so we always set it up, for convenience.
    optionables = {SourceRootConfig}
    extra_scopes = set()

    for_subsystems = for_subsystems or ()
    for subsystem in for_subsystems:
      if subsystem.options_scope is None:
        raise TaskError('You must set a scope on your subsystem type before using it in tests.')
      optionables.add(subsystem)

    for_task_types = for_task_types or ()
    for task_type in for_task_types:
      scope = task_type.options_scope
      if scope is None:
        raise TaskError('You must set a scope on your task type before using it in tests.')
      optionables.add(task_type)
      extra_scopes.update([si.scope for si in task_type.known_scope_infos()])
      optionables.update(Subsystem.closure(
        set([dep.subsystem_cls for dep in task_type.subsystem_dependencies_iter()]) |
            self._build_configuration.subsystems()))

    # Now default the option values and override with any caller-specified values.
    # TODO(benjy): Get rid of the options arg, and require tests to call set_options.
    options = options.copy() if options else {}
    for s, opts in self.options.items():
      scoped_opts = options.setdefault(s, {})
      scoped_opts.update(opts)

    options = create_options_for_optionables(optionables,
                                             extra_scopes=extra_scopes,
                                             options=options)

    Subsystem.reset(reset_options=True)
    Subsystem.set_options(options)

    context = create_context(options=options,
                             passthru_args=passthru_args,
                             target_roots=target_roots,
                             build_graph=self.build_graph,
                             build_file_parser=self.build_file_parser,
                             address_mapper=self.address_mapper,
                             console_outstream=console_outstream,
                             workspace=workspace)
    return context
Esempio n. 24
0
  def test_multiproc(self):
    context = create_context()
    key = CacheKey('muppet_key', 'fake_hash', 42)

    with self.setup_local_cache() as cache:
      self.assertEquals(context.subproc_map(call_use_cached_files, [(cache, key)]), [False])
      with self.setup_test_file(cache.artifact_root) as path:
        context.subproc_map(call_insert, [(cache, key, [path], False)])
      self.assertEquals(context.subproc_map(call_use_cached_files, [(cache, key)]), [True])

    with self.setup_rest_cache() as cache:
      self.assertEquals(context.subproc_map(call_use_cached_files, [(cache, key)]), [False])
      with self.setup_test_file(cache.artifact_root) as path:
        context.subproc_map(call_insert, [(cache, key, [path], False)])
      self.assertEquals(context.subproc_map(call_use_cached_files, [(cache, key)]), [True])
Esempio n. 25
0
  def test_multiproc(self):
    context = create_context()
    key = CacheKey('muppet_key', 'fake_hash', 42)

    with self.setup_local_cache() as cache:
      self.assertEquals(context.subproc_map(call_use_cached_files, [(cache, key)]), [False])
      with self.setup_test_file(cache.artifact_root) as path:
        context.subproc_map(call_insert, [(cache, key, [path], False)])
      self.assertEquals(context.subproc_map(call_use_cached_files, [(cache, key)]), [True])

    with self.setup_rest_cache() as cache:
      self.assertEquals(context.subproc_map(call_use_cached_files, [(cache, key)]), [False])
      with self.setup_test_file(cache.artifact_root) as path:
        context.subproc_map(call_insert, [(cache, key, [path], False)])
      self.assertEquals(context.subproc_map(call_use_cached_files, [(cache, key)]), [True])
Esempio n. 26
0
  def setUp(self):
    super(GroupEngineTest, self).setUp()

    self.context = create_context(options=dict(explain=False),
                                  target_roots=self.targets('src/java:e', 'src/python:f'))
    self.assertTrue(self.context.is_unlocked())

    # TODO(John Sirois): disentangle GroupEngine from relying upon the CheckExclusives task being
    # run.  It should either arrange this directly or else the requirement should be in a different
    # layer.
    exclusives_mapping = ExclusivesMapping(self.context)
    exclusives_mapping._populate_target_maps(self.context.targets())
    self.context.products.safe_create_data('exclusives_groups', lambda: exclusives_mapping)

    self.engine = GroupEngine(print_timing=False)
    self.recorded_actions = []
Esempio n. 27
0
  def context(self, for_task_types=None, config='', options=None, new_options=None,
              target_roots=None, **kwargs):
    for_task_types = for_task_types or []
    new_options = new_options or {}

    new_option_values = defaultdict(dict)

    # Get values for all new-style options registered by the tasks in for_task_types.
    for task_type in for_task_types:
      scope = task_type.options_scope
      if scope is None:
        raise TaskError('You must set a scope on your task type before using it in tests.')

      # We provide our own test-only registration implementation, bypassing argparse.
      # When testing we set option values directly, so we don't care about cmd-line flags, config,
      # env vars etc. In fact, for test isolation we explicitly don't want to look at those.
      def register(*rargs, **rkwargs):
        scoped_options = new_option_values[scope]
        default = rkwargs.get('default')
        if default is None and rkwargs.get('action') == 'append':
          default = []
        for flag_name in rargs:
          option_name = flag_name.lstrip('-').replace('-', '_')
          scoped_options[option_name] = default

      task_type.register_options(register)

    # Now override with any caller-specified values.

    # TODO(benjy): Get rid of the new_options arg, and require tests to call set_new_options.
    for scope, opts in new_options.items():
      for key, val in opts.items():
        new_option_values[scope][key] = val

    for scope, opts in self.new_options.items():
      for key, val in opts.items():
        new_option_values[scope][key] = val

    return create_context(config=self.config(overrides=config),
                          old_options=self.create_options(**(options or {})),
                          new_options = new_option_values,
                          target_roots=target_roots,
                          build_graph=self.build_graph,
                          build_file_parser=self.build_file_parser,
                          address_mapper=self.address_mapper,
                          **kwargs)
Esempio n. 28
0
 def test_duplicate_not_found(self):
   options = {'fail_fast': False}
   task = DuplicateDetector(create_context(options=options))
   self.assertFalse(task._is_conflicts(self.path_without_duplicates, None))
Esempio n. 29
0
 def test_binary_create_init(self):
     binary_create = BinaryCreate(create_context(config=sample_ini_test_1),
                                  '/tmp/workdir')
     self.assertEquals(binary_create._outdir, '/tmp/dist')
Esempio n. 30
0
 def setUp(self):
   self.context = create_context()
Esempio n. 31
0
 def test_duplicate_not_found(self):
     options = {'fail_fast': False}
     task = DuplicateDetector(create_context(options=options))
     self.assertFalse(task._is_conflicts(self.path_without_duplicates,
                                         None))
Esempio n. 32
0
 def context(self, config='', **options):
   opts = dict(jar_create_outdir=self.jar_outdir)
   opts.update(**options)
   return create_context(config=config, options=self.create_options(**opts),
                         target_roots=[self.jl, self.sl, self.jtl])
Esempio n. 33
0
  def context(self, for_task_types=None, options=None, target_roots=None,
              console_outstream=None, workspace=None):
    for_task_types = for_task_types or []
    options = options or {}

    option_values = defaultdict(dict)

    registered_global_subsystems = set()

    # Get default values for all options registered by the tasks in for_task_types.
    # TODO: This is clunky and somewhat repetitive of the real registration code.
    for task_type in for_task_types:
      scope = task_type.options_scope
      if scope is None:
        raise TaskError('You must set a scope on your task type before using it in tests.')

      # We provide our own test-only registration implementation, bypassing argparse.
      # When testing we set option values directly, so we don't care about cmd-line flags, config,
      # env vars etc. In fact, for test isolation we explicitly don't want to look at those.
      def register_func(on_scope):
        def register(*rargs, **rkwargs):
          scoped_options = option_values[on_scope]
          default = rkwargs.get('default')
          if default is None and rkwargs.get('action') == 'append':
            default = []
          for flag_name in rargs:
            option_name = flag_name.lstrip('-').replace('-', '_')
            scoped_options[option_name] = default
        # TODO: Set register.bootstrap here, for good measure?
        register.scope = on_scope
        return register

      task_type.register_options(register_func(scope))
      for subsystem in task_type.global_subsystems():
        if subsystem not in registered_global_subsystems:
          subsystem.register_options(register_func(subsystem.qualify_scope(Options.GLOBAL_SCOPE)))
          registered_global_subsystems.add(subsystem)
      for subsystem in task_type.task_subsystems():
        subsystem.register_options(register_func(subsystem.qualify_scope(scope)))

    # Now override with any caller-specified values.

    # TODO(benjy): Get rid of the options arg, and require tests to call set_options.
    for scope, opts in options.items():
      for key, val in opts.items():
        option_values[scope][key] = val

    for scope, opts in self.options.items():
      for key, val in opts.items():
        option_values[scope][key] = val

    # Make inner scopes inherit option values from their enclosing scopes.
    # Iterating in sorted order guarantees that we see outer scopes before inner scopes,
    # and therefore only have to inherit from our immediately enclosing scope.
    for scope in sorted(option_values.keys()):
      if scope != Options.GLOBAL_SCOPE:
        enclosing_scope = scope.rpartition('.')[0]
        opts = option_values[scope]
        for key, val in option_values.get(enclosing_scope, {}).items():
          if key not in opts:  # Inner scope values override the inherited ones.
            opts[key] = val

    context = create_context(options=option_values,
                             target_roots=target_roots,
                             build_graph=self.build_graph,
                             build_file_parser=self.build_file_parser,
                             address_mapper=self.address_mapper,
                             console_outstream=console_outstream,
                             workspace=workspace)
    Subsystem._options = context.options
    return context
Esempio n. 34
0
 def test_fail_fast_error_raised(self):
     options = {'fail_fast': True, 'excludes': None, 'max_dups': 10}
     task = DuplicateDetector(create_context(options=options), workdir=None)
     with self.assertRaises(TaskError):
         task._is_conflicts(self.path_with_duplicates, binary_target=None)
Esempio n. 35
0
 def test_duplicate_not_found(self):
   options = {'fail_fast': False, 'excludes': None}
   task = DuplicateDetector(create_context(options=options), workdir=None)
   self.assertFalse(task._is_conflicts(self.path_without_duplicates, binary_target=None))
Esempio n. 36
0
  def context(self, for_task_types=None, options=None, target_roots=None,
              console_outstream=None, workspace=None):
    for_task_types = for_task_types or []
    options = options or {}

    option_values = defaultdict(dict)
    registered_global_subsystems = set()
    bootstrap_option_values = None  # We fill these in after registering bootstrap options.

    # We provide our own test-only registration implementation, bypassing argparse.
    # When testing we set option values directly, so we don't care about cmd-line flags, config,
    # env vars etc. In fact, for test isolation we explicitly don't want to look at those.
    # All this does is make the names available in code, with the default values.
    # Individual tests can then override the option values they care about.
    def register_func(on_scope):
      def register(*rargs, **rkwargs):
        scoped_options = option_values[on_scope]
        default = rkwargs.get('default')
        if default is None and rkwargs.get('action') == 'append':
          default = []
        for flag_name in rargs:
          option_name = flag_name.lstrip('-').replace('-', '_')
          scoped_options[option_name] = default
      register.bootstrap = bootstrap_option_values
      register.scope = on_scope
      return register

    # TODO: This sequence is a bit repetitive of the real registration sequence.

    # Register bootstrap options and grab their default values for use in subsequent registration.
    register_bootstrap_options(register_func(Options.GLOBAL_SCOPE), self.build_root)
    bootstrap_option_values = create_option_values(copy.copy(option_values[Options.GLOBAL_SCOPE]))

    # Now register the remaining global scope options.
    register_global_options(register_func(Options.GLOBAL_SCOPE))

    # Now register task and subsystem options for relevant tasks.
    for task_type in for_task_types:
      scope = task_type.options_scope
      if scope is None:
        raise TaskError('You must set a scope on your task type before using it in tests.')
      task_type.register_options(register_func(scope))
      for subsystem in (set(task_type.global_subsystems()) |
                        self._build_configuration.subsystem_types()):
        if subsystem not in registered_global_subsystems:
          subsystem.register_options(register_func(subsystem.qualify_scope(Options.GLOBAL_SCOPE)))
          registered_global_subsystems.add(subsystem)
      for subsystem in task_type.task_subsystems():
        subsystem.register_options(register_func(subsystem.qualify_scope(scope)))

    # Now default option values override with any caller-specified values.
    # TODO(benjy): Get rid of the options arg, and require tests to call set_options.

    for scope, opts in options.items():
      for key, val in opts.items():
        option_values[scope][key] = val

    for scope, opts in self.options.items():
      for key, val in opts.items():
        option_values[scope][key] = val

    # Make inner scopes inherit option values from their enclosing scopes.
    # Iterating in sorted order guarantees that we see outer scopes before inner scopes,
    # and therefore only have to inherit from our immediately enclosing scope.
    for scope in sorted(option_values.keys()):
      if scope != Options.GLOBAL_SCOPE:
        enclosing_scope = scope.rpartition('.')[0]
        opts = option_values[scope]
        for key, val in option_values.get(enclosing_scope, {}).items():
          if key not in opts:  # Inner scope values override the inherited ones.
            opts[key] = val

    context = create_context(options=option_values,
                             target_roots=target_roots,
                             build_graph=self.build_graph,
                             build_file_parser=self.build_file_parser,
                             address_mapper=self.address_mapper,
                             console_outstream=console_outstream,
                             workspace=workspace)
    Subsystem._options = context.options
    return context
Esempio n. 37
0
 def test_binary_create_init(self):
   binary_create = BinaryCreate(create_context(config=sample_ini_test_1),
                                '/tmp/workdir')
   self.assertEquals(binary_create._outdir, '/tmp/dist')
Esempio n. 38
0
 def test_fail_fast_error_raised(self):
     options = {'fail_fast': True}
     task = DuplicateDetector(create_context(options=options))
     with pytest.raises(TaskError):
         task._is_conflicts(self.path_with_duplicates, None)
Esempio n. 39
0
 def test_fail_fast_error_raised(self):
   options = {'fail_fast': True}
   task = DuplicateDetector(create_context(options=options))
   with pytest.raises(TaskError):
     task._is_conflicts(self.path_with_duplicates, None)
Esempio n. 40
0
    def context(self,
                for_task_types=None,
                options=None,
                target_roots=None,
                console_outstream=None,
                workspace=None):
        for_task_types = for_task_types or []
        options = options or {}

        option_values = defaultdict(dict)
        registered_subsystems = set()
        bootstrap_option_values = None  # We fill these in after registering bootstrap options.

        # We provide our own test-only registration implementation, bypassing argparse.
        # When testing we set option values directly, so we don't care about cmd-line flags, config,
        # env vars etc. In fact, for test isolation we explicitly don't want to look at those.
        # All this does is make the names available in code, with the default values.
        # Individual tests can then override the option values they care about.
        def register_func(on_scope):
            def register(*rargs, **rkwargs):
                scoped_options = option_values[on_scope]
                default = rkwargs.get('default')
                if default is None and rkwargs.get('action') == 'append':
                    default = []
                for flag_name in rargs:
                    option_name = flag_name.lstrip('-').replace('-', '_')
                    scoped_options[option_name] = default

            register.bootstrap = bootstrap_option_values
            register.scope = on_scope
            return register

        # TODO: This sequence is a bit repetitive of the real registration sequence.

        # Register bootstrap options and grab their default values for use in subsequent registration.
        GlobalOptionsRegistrar.register_bootstrap_options(
            register_func(Options.GLOBAL_SCOPE))
        bootstrap_option_values = create_option_values(
            copy.copy(option_values[Options.GLOBAL_SCOPE]))

        # Now register the full global scope options.
        GlobalOptionsRegistrar.register_options(
            register_func(Options.GLOBAL_SCOPE))

        # Now register task and subsystem options for relevant tasks.
        for task_type in for_task_types:
            scope = task_type.options_scope
            if scope is None:
                raise TaskError(
                    'You must set a scope on your task type before using it in tests.'
                )
            task_type.register_options(register_func(scope))
            for subsystem in (set(task_type.global_subsystems())
                              | set(task_type.task_subsystems())
                              | self._build_configuration.subsystems()):
                if subsystem not in registered_subsystems:
                    subsystem.register_options(
                        register_func(subsystem.options_scope))
                    registered_subsystems.add(subsystem)

        # Now default option values override with any caller-specified values.
        # TODO(benjy): Get rid of the options arg, and require tests to call set_options.

        for scope, opts in options.items():
            for key, val in opts.items():
                option_values[scope][key] = val

        for scope, opts in self.options.items():
            for key, val in opts.items():
                option_values[scope][key] = val

        # Make inner scopes inherit option values from their enclosing scopes.
        all_scopes = set(option_values.keys())
        for task_type in for_task_types:  # Make sure we know about pre-task subsystem scopes.
            all_scopes.update(
                [si.scope for si in task_type.known_scope_infos()])
        # Iterating in sorted order guarantees that we see outer scopes before inner scopes,
        # and therefore only have to inherit from our immediately enclosing scope.
        for scope in sorted(all_scopes):
            if scope != Options.GLOBAL_SCOPE:
                enclosing_scope = scope.rpartition('.')[0]
                opts = option_values[scope]
                for key, val in option_values.get(enclosing_scope, {}).items():
                    if key not in opts:  # Inner scope values override the inherited ones.
                        opts[key] = val

        context = create_context(options=option_values,
                                 target_roots=target_roots,
                                 build_graph=self.build_graph,
                                 build_file_parser=self.build_file_parser,
                                 address_mapper=self.address_mapper,
                                 console_outstream=console_outstream,
                                 workspace=workspace)
        Subsystem._options = context.options
        return context
Esempio n. 41
0
 def test_duplicate_not_found(self):
     options = {'fail_fast': False, 'excludes': None, 'max_dups': 10}
     task = DuplicateDetector(create_context(options=options), workdir=None)
     self.assertFalse(
         task._is_conflicts(self.path_without_duplicates,
                            binary_target=None))
Esempio n. 42
0
 def setUp(self):
   self.context = create_context()
Esempio n. 43
0
 def test_duplicate_found(self):
   old_options = {'fail_fast': False, 'excludes': None, 'max_dups' : 10}
   task = DuplicateDetector(create_context(old_options=old_options), workdir=None)
   self.assertTrue(task._is_conflicts(self.path_with_duplicates, binary_target=None))
Esempio n. 44
0
 def test_fail_fast_error_raised(self):
   options = {'fail_fast': True, 'excludes': None}
   task = DuplicateDetector(create_context(options=options), workdir=None)
   with pytest.raises(TaskError):
     task._is_conflicts(self.path_with_duplicates, binary_target=None)