Пример #1
0
def test_modify_context_during_CVEI():
    """Custom logic made possible via convenience members"""

    count = {"#": 0}

    class MyCollector(api.ContextPlugin):
        order = api.CollectorOrder

        def process(self, context):
            camera = context.create_instance("MyCamera")
            model = context.create_instance("MyModel")

            camera.data["family"] = "camera"
            model.data["family"] = "model"

            count["#"] += 1

    class MyValidator(api.InstancePlugin):
        order = api.ValidatorOrder

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

    api.register_plugin(MyCollector)
    api.register_plugin(MyValidator)

    context = api.Context()

    assert count["#"] == 0, count

    util.collect(context)

    assert count["#"] == 1, count

    context[:] = filter(lambda i: i.data["family"] == "camera", context)

    util.validate(context)

    # Only model remains
    assert count["#"] == 11, count

    # No further processing occurs.
    util.extract(context)
    util.integrate(context)

    assert count["#"] == 11, count
Пример #2
0
def test_publishing_validators():
    """Running validators with targets works"""

    count = {"#": 0}

    class plugin(api.ContextPlugin):
        order = api.ValidatorOrder
        targets = ["custom"]

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

    api.register_plugin(plugin)

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

    assert count["#"] == 1, count
Пример #3
0
def test_modify_context_during_CVEI():
    """Custom logic made possible via convenience members"""

    count = {"#": 0}

    class MyCollector(api.ContextPlugin):
        order = api.CollectorOrder

        def process(self, context):
            camera = context.create_instance("MyCamera")
            model = context.create_instance("MyModel")

            camera.data["family"] = "camera"
            model.data["family"] = "model"

            count["#"] += 1

    class MyValidator(api.InstancePlugin):
        order = api.ValidatorOrder

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

    api.register_plugin(MyCollector)
    api.register_plugin(MyValidator)

    context = api.Context()

    assert count["#"] == 0, count

    util.collect(context)

    assert count["#"] == 1, count

    context[:] = filter(lambda i: i.data["family"] == "camera", context)

    util.validate(context)

    # Only model remains
    assert count["#"] == 11, count

    # No further processing occurs.
    util.extract(context)
    util.integrate(context)

    assert count["#"] == 11, count
Пример #4
0
def test_publishing_validators():
    """Running validators with targets works"""

    count = {"#": 0}

    class plugin(api.ContextPlugin):
        order = api.ValidatorOrder
        targets = ["custom"]

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

    api.register_plugin(plugin)

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

    assert count["#"] == 1, count
Пример #5
0
def test_convenience_functions():
    """convenience functions works as expected"""

    count = {"#": 0}

    class Collector(api.ContextPlugin):
        order = api.CollectorOrder

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

    class Validator(api.InstancePlugin):
        order = api.ValidatorOrder

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

    class Extractor(api.InstancePlugin):
        order = api.ExtractorOrder

        def process(self, instance):
            count["#"] += 100

    class Integrator(api.ContextPlugin):
        order = api.IntegratorOrder

        def process(self, instance):
            count["#"] += 1000

    class PostIntegrator(api.ContextPlugin):
        order = api.IntegratorOrder + 0.1

        def process(self, instance):
            count["#"] += 10000

    class NotCVEI(api.ContextPlugin):
        """This plug-in is too far away from Integration to qualify as CVEI"""
        order = api.IntegratorOrder + 2.0

        def process(self, instance):
            count["#"] += 100000

    assert count["#"] == 0

    for Plugin in (Collector,
                   Validator,
                   Extractor,
                   Integrator,
                   PostIntegrator,
                   NotCVEI):
        api.register_plugin(Plugin)

    context = util.collect()

    assert count["#"] == 1

    util.validate(context)

    assert count["#"] == 11

    util.extract(context)

    assert count["#"] == 111

    util.integrate(context)

    assert count["#"] == 11111
Пример #6
0
def test_convenience_functions():
    """convenience functions works as expected"""

    count = {"#": 0}

    class Collector(api.ContextPlugin):
        order = api.CollectorOrder

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

    class Validator(api.InstancePlugin):
        order = api.ValidatorOrder

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

    class Extractor(api.InstancePlugin):
        order = api.ExtractorOrder

        def process(self, instance):
            count["#"] += 100

    class Integrator(api.ContextPlugin):
        order = api.IntegratorOrder

        def process(self, instance):
            count["#"] += 1000

    class PostIntegrator(api.ContextPlugin):
        order = api.IntegratorOrder + 0.1

        def process(self, instance):
            count["#"] += 10000

    class NotCVEI(api.ContextPlugin):
        """This plug-in is too far away from Integration to qualify as CVEI"""
        order = api.IntegratorOrder + 2.0

        def process(self, instance):
            count["#"] += 100000

    assert count["#"] == 0

    for Plugin in (Collector,
                   Validator,
                   Extractor,
                   Integrator,
                   PostIntegrator,
                   NotCVEI):
        api.register_plugin(Plugin)

    context = util.collect()

    assert count["#"] == 1

    util.validate(context)

    assert count["#"] == 11

    util.extract(context)

    assert count["#"] == 111

    util.integrate(context)

    assert count["#"] == 11111