示例#1
0
def test_per_session_targets():
    """Register targets per session works"""

    util.publish(targets=["custom"])

    registered_targets = api.registered_targets()
    assert registered_targets == [], registered_targets
示例#2
0
def test_publishing_explicit_targets_with_global():
    """Publishing with explicit and globally registered targets works"""

    count = {"#": 0}

    class Plugin1(api.ContextPlugin):
        targets = ["custom"]

        def process(self, context):
            count["#"] += 1

    class Plugin2(api.ContextPlugin):
        targets = ["foo"]

        def process(self, context):
            count["#"] += 10

    api.register_target("foo")
    api.register_target("custom")
    api.register_plugin(Plugin1)
    api.register_plugin(Plugin2)

    util.publish(targets=["custom"])

    assert count["#"] == 1, count
    assert api.registered_targets() == ["foo", "custom"]

    api.deregister_all_targets()
示例#3
0
def plot_publish(families, targets=None, identifiers=None, keys=None):
    """Parse and plot all plugins by families and targets

    Args:
        families (list): List of interested instance family names
        targets (list, optional): List of target names
        identifiers (list, optional): List of interested dict names, take
            ["context.data", "instance.data"] if not provided.
        keys (list, optional): List of interested key names, return all dict
            keys if not provided.

    """
    if not targets:
        targets = ["default"] + api.registered_targets()

    plugins = api.discover()
    plugins = logic.plugins_by_families(plugins, families)
    plugins = logic.plugins_by_targets(plugins, targets)

    reports = list()

    for plugin in plugins:
        report = plot_plugin(plugin, identifiers, keys)
        if report:
            reports.append(report)

    return reports
示例#4
0
def test_per_session_targets():
    """Register targets per session works"""

    util.publish(targets=["custom"])

    registered_targets = api.registered_targets()
    assert registered_targets == [], registered_targets
示例#5
0
def cli():
    parser = argparse.ArgumentParser()
    parser.add_argument("--demo", action="store_true")
    parser.add_argument("--aschild",
                        action="store_true",
                        help="Run as child of another process")
    parser.add_argument("--targets",
                        nargs="*",
                        help="Targets to run plugins against.")

    kwargs = parser.parse_args()

    if kwargs.targets is None:
        kwargs.targets = ["default"] + api.registered_targets()

    return app.main(**kwargs.__dict__)