Exemplo n.º 1
0
def test_interface_with_meta_info():
    """A Reahl component can publish a ReahlEgg instance to supply extra meta information about itself.
       Such interfaces with extra information are also often used from a flattened list in dependency order."""

    easter_egg.clear()
    easter_egg.add_dependency('reahl-component')

    # The interface for a component is published via the reahl.eggs entry point
    line = 'Egg = reahl.component.eggs:ReahlEgg'
    easter_egg.add_entry_point_from_line('reahl.eggs', line)

    # Interfaces can be queried in dependency order too
    interfaces_in_order = ReahlEgg.compute_all_relevant_interfaces(easter_egg.as_requirement_string())
    assert len(interfaces_in_order) == 2   # That of reahl-component itself, and of the easteregg
    [interface] = [i for i in interfaces_in_order if i.distribution is easter_egg]

    # The meta-info that can be obtained via such an interface
    assert interface.configuration_spec is None

    assert interface.get_persisted_classes_in_order() == []
    assert interface.migrations_in_order == []

    # Hooks for allowing a component to do its own housekeeping
    with expected(NoException):
        interface.do_daily_maintenance()
Exemplo n.º 2
0
def test_flattened_tree_of_eggs():
    """A Reahl application consists of a root egg and all its egg dependencies - with all such components
       often regarded in flattened order of dependence."""
    easter_egg.clear()
    easter_egg.add_dependency('reahl-component')

    # All eggs for a root egg can be found in dependency order
    components_in_order = ReahlEgg.compute_ordered_dependent_distributions(
        easter_egg.as_requirement_string())
    component_names_in_order = [i.project_name for i in components_in_order]

    # (many valid topological sorts are possible and the algorithm is nondeterministic in some aspects that
    #  do not matter, hence many possible valid orderings are possible for this dependency tree)
    #  We assert here only what matters, else this test becomes a flipper:
    def is_ordered_before(higher, lower):
        return component_names_in_order.index(
            higher) < component_names_in_order.index(lower)

    assert component_names_in_order[:2] == [
        easter_egg.project_name, 'reahl-component'
    ]

    for package_name in component_names_in_order:
        dependencies = [
            i.project_name for i in pkg_resources.require(package_name)
            if i.project_name != package_name
        ]
        assert all([is_ordered_before(package_name, i) for i in dependencies])
Exemplo n.º 3
0
    def config_defaults(self, fixture):
        """To facilitate dependency injection, the Configuration of one Egg can set the 'automatic' ConfigSettings of
           another egg on which it depends."""

        egg_needing_injection = EasterEgg('test-inject')
        fixture.set_config_spec(
            egg_needing_injection,
            'reahl.component_dev.test_config:ConfigWithInjectedSetting')
        pkg_resources.working_set.add(egg_needing_injection)

        fixture.set_config_spec(
            easter_egg,
            'reahl.component_dev.test_config:ConfigWhichInjectsSetting')

        easter_egg.add_dependency(
            egg_needing_injection.as_requirement_string())

        # Usually this happens inside other infrastructure, such as the implementation of reahl serve (see reahl-dev)
        config = StoredConfiguration(fixture.config_dir.name)
        config.configure()

        # The default value is still used
        vassert(config.some_key.injected_setting == 123)
Exemplo n.º 4
0
    def flattened_tree_of_eggs(self, fixture):
        """A Reahl application consists of a root egg and all its egg dependencies - with all such components
           often regarded in flattened order of dependence."""
        easter_egg.clear()
        easter_egg.add_dependency('reahl-component')

        # All eggs for a root egg can be found in dependency order
        components_in_order = ReahlEgg.compute_ordered_dependent_distributions(
            easter_egg.as_requirement_string())
        component_names_in_order = [
            i.project_name for i in components_in_order
        ]

        # (many valid topological sorts are possible and the algorithm is nondeterministic in some aspects that
        #  do not matter, hence many possible valid orderings are possible for this dependency tree)
        #  We assert here only what matters, else this test becomes a flipper:
        def is_ordered_before(higher, lower):
            return component_names_in_order.index(
                higher) < component_names_in_order.index(lower)

        vassert(component_names_in_order[:2] ==
                [easter_egg.project_name, 'reahl-component'])
        vassert(is_ordered_before('Babel', 'pytz'))
        vassert(is_ordered_before('python-dateutil', 'six'))