Ejemplo n.º 1
0
def test():
    '''Test `garlicsim.asynchronous_crunching`.'''
    
    from . import simpacks as simpacks_package
    
    # Collecting all the test simpacks:
    simpacks = import_tools.import_all(simpacks_package).values()
    
    # Making sure that we didn't miss any simpack by counting the number of
    # sub-folders in the `simpacks` folder:
    simpacks_dir = \
        os.path.dirname(simpacks_package.__file__)
    assert len(path_tools.list_sub_folders(simpacks_dir)) == \
           len(simpacks)
    
    for simpack in simpacks:
        
        test_garlicsim.verify_simpack_settings(simpack)
        
        cruncher_types = \
            garlicsim.misc.SimpackGrokker(simpack).available_cruncher_types
        
        for cruncher_type in cruncher_types:
            
            yield check, simpack, cruncher_type
Ejemplo n.º 2
0
def test_endable():
    '''
    Test handling of endable simpacks.
    
    All simpacks end when they get a world-state with clock reading of 4 or
    more.
    '''
    
    from . import simpacks as simpacks_package
    
    # Collecting all the test simpacks:
    simpacks = import_tools.import_all(simpacks_package).values()
    
    # Making sure that we didn't miss any simpack by counting the number of
    # sub-folders in the `simpacks` folder:
    simpacks_dir = \
        os.path.dirname(simpacks_package.__file__)
    assert len(path_tools.list_sub_folders(simpacks_dir)) == \
           len(simpacks)
    
    for simpack in simpacks:

        test_garlicsim.verify_simpack_settings(simpack)
        
        cruncher_types = \
            garlicsim.misc.SimpackGrokker(simpack).available_cruncher_types
        
        for cruncher_type in cruncher_types:
            yield check, simpack, cruncher_type
Ejemplo n.º 3
0
def test_simpacks():
    from . import simpacks as simpacks_package
    
    # Collecting all the test simpacks:
    simpacks = import_tools.import_all(simpacks_package).values()
    
    # Making sure that we didn't miss any simpack by counting the number of
    # sub-folders in the `simpacks` folder:
    simpacks_dir = os.path.dirname(simpacks_package.__file__)
    assert len(path_tools.list_sub_folders(simpacks_dir)) == \
           len(simpacks)
    
    for simpack in simpacks:
        test_garlicsim.verify_simpack_settings(simpack)
        yield check_simpack, simpack
Ejemplo n.º 4
0
def create(package):
    '''
    Get all objects defined in modules/packages that live in a warehouse.
    
    What is a warehouse? A warehouse is a package that has within it modules
    and packages, and it uses this function to automatically retrieve all the
    objects from all these modules and packages, and get them in one list.
    
    What is it good for? In the GarlicSim project, there is a warehouse called
    crunchers_warehouse. Inside it there are various modules that define
    different types of "crunchers". One is a module cruncher_thread, which
    defines CruncherThread, another is a module cruncher_process, which
    defines CruncherProcess. The warehouse uses this function to keep a list of
    all these crunchers. If one day there will be added a module that defines
    CruncherWhatever, and it will be added to the warehouse, the list will
    automatically include it. This makes it very frictionless to add/remove
    crunchers in the warehouse.
    
    How to use this function? This way works, written in the warehouse's
    __init__:
    
    import sys
    from garlicsim.general_misc import warehouse
    this_module = sys.modules[__name__]
    objects = warehouse.create(this_module)
    
    That's it. Assuming the package's name is `my_package`, the list of objects
    will now be available as `my_package.objects`.
    
    
    todo: works when frozen? Use pkg_resources?
    '''
    
    things = {}
    modules = import_tools.import_all(package, graceful_fail=True)
    for (module_name, module) in modules.items():
        if not hasattr(module, '__all__'):
            raise WarehouseError('''Module in warehouse must define __all__ \
which declares exactly which objects should be collected.''')
        for name in module.__all__:
            if name in things:
                raise WarehouseError('''Duplicity in warehouse: the name %s \
is defined in two different modules: %s and %s.''' % \
                    (name, things[name].__module__, module.__name__))
            things[name] = getattr(module, name)
        
    return things
def test_simpacks():
    '''Test invalid simpacks.'''
    from . import simpacks as invalid_simpacks_package
    
    # Collecting all the test simpacks:
    simpacks = list(import_tools.import_all(invalid_simpacks_package).values())
    
    # Making sure that we didn't miss any simpack by counting the number of
    # sub-folders in the `simpacks` folder:
    simpacks_dir = \
        os.path.dirname(invalid_simpacks_package.__file__)
    assert len(simpacks) == len(
        path_tools.list_sub_folders(simpacks_dir, exclude='__pycache__')
    )
           
    
    for simpack in simpacks:
        test_garlicsim.verify_simpack_settings(simpack)
        yield check_simpack, simpack
Ejemplo n.º 6
0
def test():
    """Test changing things while crunching."""
    from . import simpacks as simpacks_package

    # Collecting all the test simpacks:
    simpacks = list(import_tools.import_all(simpacks_package).values())

    # Making sure that we didn't miss any simpack by counting the number of
    # sub-folders in the `simpacks` folder:
    simpacks_dir = os.path.dirname(simpacks_package.__file__)
    assert len(path_tools.list_sub_folders(simpacks_dir, exclude="__pycache__")) == len(simpacks)

    for simpack in simpacks:

        test_garlicsim.verify_simpack_settings(simpack)

        cruncher_types = garlicsim.misc.SimpackGrokker(simpack).available_cruncher_types

        for cruncher_type in cruncher_types:
            yield check, simpack, cruncher_type
Ejemplo n.º 7
0
def test():
    '''Test changing things while crunching.'''
    from . import simpacks as simpacks_package

    # Collecting all the test simpacks:
    simpacks = import_tools.import_all(simpacks_package).values()

    # Making sure that we didn't miss any simpack by counting the number of
    # sub-folders in the `simpacks` folder:
    simpacks_dir = \
        os.path.dirname(simpacks_package.__file__)
    assert len(path_tools.list_sub_folders(simpacks_dir)) == \
           len(simpacks)

    for simpack in simpacks:

        test_garlicsim.verify_simpack_settings(simpack)

        cruncher_types = \
            garlicsim.misc.SimpackGrokker(simpack).available_cruncher_types

        for cruncher_type in cruncher_types:
            yield check, simpack, cruncher_type