<commit_before># -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2010 <NAME>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.
#
# Author: <NAME> <<EMAIL>>
#


def test_extension_reg():
    _clear_registry()
    from giblets import Component, ComponentManager, ExtensionPoint, ExtensionInterface, implements


    # a Train is extended by a bunch of train cars...
    class ITrainCar(ExtensionInterface):
        pass

    class Train(Component):
        cars = ExtensionPoint(ITrainCar)

    class EngineCar(Component):
        implements(ITrainCar)
        
    class PassengerCar(Component):
        implements(ITrainCar)
        
    class CafeCar(Component):
        implements(ITrainCar)
    
    class CabooseCar(Component):
        implements(ITrainCar)
        

    # an irrelevant interface and implementation...
    class IZooAnimal(ExtensionInterface):
        pass
        
    class Zebra(Component):
        implements(IZooAnimal)

    # create a component manager and the train associated with it 
    mgr1 = ComponentManager()
    train1 = Train(mgr1)
    
    # components are singletons w/ respect to manager
    assert id(train1) == id(Train(mgr1))
    
    # check that all of the extensions for the extension point were registered
    for cls in (EngineCar, PassengerCar, CafeCar, CabooseCar):
        assert _has_exactly(1, cls, train1.cars)
    
    # check that the Zebra is not a part of the train
    assert _has_exactly(0, Zebra, train1.cars)
    
    # create a different component manager and the train associated with it, 
    # check the same stuff...
    mgr2 = ComponentManager()
    train2 = Train(mgr2)
    assert id(train2) == id(Train(mgr2))
    for cls in (EngineCar, PassengerCar, CafeCar, CabooseCar):
        assert _has_exactly(1, cls, train2.cars)
    assert _has_exactly(0, Zebra, train2.cars)

    # now check that the trains and extensions produced by the
    # different component managers are different.
    assert train1 != train2
    for cls in (EngineCar, PassengerCar, CafeCar, CabooseCar):
        i1 = [x for x in train1.cars if isinstance(x, cls)][0]
        i2 = [x for x in train2.cars if isinstance(x, cls)][0]
        assert id(i1) != id(i2)
        
        
def test_multi_extension():
    _clear_registry()
    from giblets import Component, ComponentManager, ExtensionPoint, ExtensionInterface, implements
    
    # set up some scenarios that test components providing multiple 
    # extensions and extension interfaces that imply other 
    # extension interfaces by inheritance
        
    # a parking lot gets all wheeled vehicles
    class IWheeledVehicle(ExtensionInterface):
        pass
    class ParkingLot(Component):
        vehicles = ExtensionPoint(IWheeledVehicle)

    # an airport gets all flying vehicles
    class IFlyingVehicle(ExtensionInterface):
        pass
    class Airport(Component):
        vehicles = ExtensionPoint(IFlyingVehicle)
    
    # a flying parking lot is only populated by flying cars, 
    # which also happen to be wheeled and flying
    class IFlyingCar(IWheeledVehicle, IFlyingVehicle):
        pass
    class FlyingParkingLot(Component):
        vehicles = ExtensionPoint(IFlyingCar)

    # now some vehicles implementing the various types...    <commit_msg>nicer spelling of getting the first item to satisfy a condition in an iterable<commit_after># -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2010 <NAME>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.
#
# Author: <NAME> <<EMAIL>>
#


def test_extension_reg():
    _clear_registry()
    from giblets import Component, ComponentManager, ExtensionPoint, ExtensionInterface, implements


    # a Train is extended by a bunch of train cars...
    class ITrainCar(ExtensionInterface):
        pass

    class Train(Component):
        cars = ExtensionPoint(ITrainCar)

    class EngineCar(Component):
        implements(ITrainCar)
        
    class PassengerCar(Component):
        implements(ITrainCar)
        
    class CafeCar(Component):
        implements(ITrainCar)
    
    class CabooseCar(Component):
        implements(ITrainCar)
        

    # an irrelevant interface and implementation...
    class IZooAnimal(ExtensionInterface):
        pass
        
    class Zebra(Component):
        implements(IZooAnimal)

    # create a component manager and the train associated with it 
    mgr1 = ComponentManager()
    train1 = Train(mgr1)
    
    # components are singletons w/ respect to manager
    assert id(train1) == id(Train(mgr1))
    
    # check that all of the extensions for the extension point were registered
    for cls in (EngineCar, PassengerCar, CafeCar, CabooseCar):
        assert _has_exactly(1, cls, train1.cars)
    
    # check that the Zebra is not a part of the train
    assert _has_exactly(0, Zebra, train1.cars)
    
    # create a different component manager and the train associated with it, 
    # check the same stuff...
    mgr2 = ComponentManager()
    train2 = Train(mgr2)
    assert id(train2) == id(Train(mgr2))
    for cls in (EngineCar, PassengerCar, CafeCar, CabooseCar):
        assert _has_exactly(1, cls, train2.cars)
    assert _has_exactly(0, Zebra, train2.cars)

    # now check that the trains and extensions produced by the
    # different component managers are different.
    assert train1 != train2
    for cls in (EngineCar, PassengerCar, CafeCar, CabooseCar):
        i1 = (x for x in train1.cars if isinstance(x, cls)).next()
        i2 = (x for x in train2.cars if isinstance(x, cls)).next()
        assert id(i1) != id(i2)
        
        
def test_multi_extension():
    _clear_registry()
    from giblets import Component, ComponentManager, ExtensionPoint, ExtensionInterface, implements
    
    # set up some scenarios that test components providing multiple 
    # extensions and extension interfaces that imply other 
    # extension interfaces by inheritance
        
    # a parking lot gets all wheeled vehicles
    class IWheeledVehicle(ExtensionInterface):
        pass
    class ParkingLot(Component):
        vehicles = ExtensionPoint(IWheeledVehicle)

    # an airport gets all flying vehicles
    class IFlyingVehicle(ExtensionInterface):
        pass
    class Airport(Component):
        vehicles = ExtensionPoint(IFlyingVehicle)
    
    # a flying parking lot is only populated by flying cars, 
    # which also happen to be wheeled and flying
    class IFlyingCar(IWheeledVehicle, IFlyingVehicle):
        pass
    class FlyingParkingLot(Component):
        vehicles = ExtensionPoint(IFlyingCar)

    # now some vehicles implementing the various types...    
{'fraction_non_alphanumeric': 0.07225730650609487, 'fraction_numerical': 0.01057423997650169, 'mean_word_length': 2.9593023255813953, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5729881', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1875, 'n_words': 653}