Ejemplo n.º 1
0
 def test_single(self):
   exactly_b = Exactly(self.B)
   self.assertEqual((self.B,), exactly_b.types)
   self.assertFalse(exactly_b.satisfied_by(self.A()))
   self.assertTrue(exactly_b.satisfied_by(self.B()))
   self.assertFalse(exactly_b.satisfied_by(self.BPrime()))
   self.assertFalse(exactly_b.satisfied_by(self.C()))
Ejemplo n.º 2
0
 def test_multiple(self):
     exactly_a_or_b = Exactly(self.A, self.B)
     self.assertEqual((self.A, self.B), exactly_a_or_b.types)
     self.assertTrue(exactly_a_or_b.satisfied_by(self.A()))
     self.assertTrue(exactly_a_or_b.satisfied_by(self.B()))
     self.assertFalse(exactly_a_or_b.satisfied_by(self.BPrime()))
     self.assertFalse(exactly_a_or_b.satisfied_by(self.C()))
Ejemplo n.º 3
0
 def test_multiple(self):
   exactly_a_or_b = Exactly(self.A, self.B)
   self.assertEqual((self.A, self.B), exactly_a_or_b.types)
   self.assertTrue(exactly_a_or_b.satisfied_by(self.A()))
   self.assertTrue(exactly_a_or_b.satisfied_by(self.B()))
   self.assertFalse(exactly_a_or_b.satisfied_by(self.BPrime()))
   self.assertFalse(exactly_a_or_b.satisfied_by(self.C()))
Ejemplo n.º 4
0
 def __init__(self, default_repo, repos, name=None, **kwargs):
     super(PublishConfiguration,
           self).__init__(name=name,
                          default_repo=addressable(Exactly(Configuration),
                                                   default_repo),
                          repos=addressable_mapping(Exactly(Configuration),
                                                    repos),
                          **kwargs)
Ejemplo n.º 5
0
class PublishConfiguration(Struct):
    # An example of addressable and addressable_mapping field wrappers.

    def __init__(self, default_repo, repos, name=None, **kwargs):
        super(PublishConfiguration, self).__init__(name=name, **kwargs)
        self.default_repo = default_repo
        self.repos = repos

    @addressable(Exactly(Struct))
    def default_repo(self):
        """"""

    @addressable_dict(Exactly(Struct))
    def repos(self):
        """"""
Ejemplo n.º 6
0
    class Person(SimpleSerializable):
        def __init__(self, age):
            super(AddressableTest.Person, self).__init__()
            self.age = age

        @addressable(Exactly(int))
        def age(self):
            """Return the person's age in years.
Ejemplo n.º 7
0
    class Series(SimpleSerializable):
        def __init__(self, values):
            super(AddressableListTest.Series, self).__init__()
            self.values = values

        @addressable_list(Exactly(int, float))
        def values(self):
            """Return this series' values.
Ejemplo n.º 8
0
    class Varz(SimpleSerializable):
        def __init__(self, varz):
            super(AddressableDictTest.Varz, self).__init__()
            self.varz = varz

        @addressable_dict(Exactly(int, float))
        def varz(self):
            """Return a snapshot of the current /varz.
Ejemplo n.º 9
0
        class NotSerializable(object):
            def __init__(self, count):
                super(NotSerializable, self).__init__()
                self.count = count

            @addressable(Exactly(int))
            def count(self):
                pass
Ejemplo n.º 10
0
 def test_single(self):
     exactly_b = Exactly(self.B)
     self.assertEqual((self.B, ), exactly_b.types)
     self.assertFalse(exactly_b.satisfied_by(self.A()))
     self.assertTrue(exactly_b.satisfied_by(self.B()))
     self.assertFalse(exactly_b.satisfied_by(self.BPrime()))
     self.assertFalse(exactly_b.satisfied_by(self.C()))
Ejemplo n.º 11
0
 def test(self):
     self.assertFalse(Exactly(self.B).satisfied_by(self.A()))
     self.assertTrue(Exactly(self.B).satisfied_by(self.B()))
     self.assertFalse(Exactly(self.B).satisfied_by(self.BPrime()))
     self.assertFalse(Exactly(self.B).satisfied_by(self.C()))
Ejemplo n.º 12
0
 def test_none(self):
     self.assertIsNone(addressable(Exactly(int), None))
Ejemplo n.º 13
0
class Target(Configuration):
    """TODO(John Sirois): XXX DOCME"""
    class ConfigurationNotFound(Exception):
        """Indicates a requested configuration of a target could not be found."""

    def __init__(self,
                 name=None,
                 sources=None,
                 configurations=None,
                 dependencies=None,
                 **kwargs):
        """
    :param string name: The name of this target which forms its address in its namespace.
    :param sources: The relative source file paths of sources this target owns.
    :type sources: :class:`Sources`
    :param list configurations: The configurations that apply to this target in various contexts.
    :param list dependencies: The direct dependencies of this target.
    """
        super(Target, self).__init__(name=name, **kwargs)
        self.configurations = configurations
        self.dependencies = dependencies
        self.sources = sources

    @addressable_list(SubclassesOf(Configuration))
    def configurations(self):
        """The configurations that apply to this target in various contexts.

    :rtype list of :class:`pants.engine.exp.configuration.Configuration`
    """

    @addressable_list(SubclassesOf(Configuration))
    def dependencies(self):
        """The direct dependencies of this target.

    :rtype: list
    """

    @addressable(Exactly(Sources))
    def sources(self):
        """Return the sources this target owns.

    :rtype: :class:`Sources`
    """

    def select_configuration(self, name):
        """Selects a named configuration of this target.

    :param string name: The name of the configuration to select.
    :returns: The configuration with the given name.
    :rtype: :class:`pants.engine.exp.configuration.Configuration`
    :raises: :class:`Target.ConfigurationNotFound` if the configuration was not found.
    """
        configs = tuple(config for config in self.configurations
                        if config.name == name)
        if len(configs) != 1:
            configurations = ('{} -> {!r}'.format(
                repr(c.name) if c.name else '<anonymous>', c) for c in configs)
            raise self.ConfigurationNotFound(
                'Failed to find a single configuration named {!r} these '
                'configurations in {!r}:\n\t{}'.format(
                    name, self, '\n\t'.join(configurations)))
        return configs[0]

    def walk_targets(self, postorder=True):
        """Performs a depth first walk of this target, visiting all reachable targets exactly once.

    :param bool postorder: When ``True``, the traversal order is postorder (children before
                           parents), else it is preorder (parents before children).
    """
        visited = set()

        def walk(target):
            if target not in visited:
                visited.add(target)
                if not postorder:
                    yield target
                for dep in self.dependencies:
                    if isinstance(dep, Target):
                        for t in walk(dep):
                            yield t
                if postorder:
                    yield target

        for target in walk(self):
            yield target
Ejemplo n.º 14
0
 def test_value(self):
     self.assertEqual(42, addressable(Exactly(int), 42))
Ejemplo n.º 15
0
 def test_none(self):
     with self.assertRaises(ValueError):
         Exactly()
Ejemplo n.º 16
0
 def test_type_mismatch(self):
     with self.assertRaises(AddressedError):
         addressable(Exactly(int), 42.0)
Ejemplo n.º 17
0
    @property
    def path_globs(self):
        """Creates a `PathGlobs` object for the files held by these Sources.

    This field may be projected to request the content of the files for this Sources object.
    """
        return PathGlobs.create(self.spec_path,
                                files=self.files,
                                globs=self.globs,
                                rglobs=self.rglobs,
                                zglobs=self.zglobs)

    @abstractproperty
    def extensions(self):
        """A collection of file extensions collected by this Sources instance.

    An empty collection indicates that any extension will be accepted.
    """

    @property
    def excludes(self):
        """The sources to exclude.

    :rtype: :class:`Sources`
    """


# Since Sources.excludes is recursive on the Sources type, we need to post-class-definition
# re-define excludes in this way.
Sources.excludes = addressable(Exactly(Sources))(Sources.excludes)
Ejemplo n.º 18
0
 def test_type_mismatch(self):
     with self.assertRaises(AddressedError):
         addressable_mapping(
             Exactly(int),
             dict(meaning_of_life=42, fine_structure_constant=1 / 137.0))
Ejemplo n.º 19
0
 def test_none(self):
     self.assertEqual({}, addressable_mapping(Exactly(int), None))
Ejemplo n.º 20
0
 def test_type_mismatch(self):
     with self.assertRaises(AddressedError):
         addressables(Exactly(int), [42, 1 / 137.0])
Ejemplo n.º 21
0
 def test_mixed(self):
     self.assertEqual(
         [42, Addressed(Exactly(int), '//:meaning-of-life')],
         addressables(Exactly(int), [42, '//:meaning-of-life']))
Ejemplo n.º 22
0
 def test_pointers(self):
     self.assertEqual([Addressed(Exactly(int), '//:meaning-of-life')],
                      addressables(Exactly(int), ['//:meaning-of-life']))
Ejemplo n.º 23
0
 def test_none(self):
     self.assertEqual([], addressables(Exactly(int), None))
Ejemplo n.º 24
0
 def test_pointers(self):
     self.assertEqual(
         dict(
             meaning_of_life=Addressed(Exactly(int), '//:meaning-of-life')),
         addressable_mapping(Exactly(int),
                             dict(meaning_of_life='//:meaning-of-life')))
Ejemplo n.º 25
0
 def test_pointer(self):
     self.assertEqual(Addressed(Exactly(int), '//:meaning-of-life'),
                      addressable(Exactly(int), '//:meaning-of-life'))