def test1(self):
        'mcni.pyre_support: componentfactory'
        from mcni.pyre_support import componentfactory
        f = componentfactory('sources', 'MonochromaticSource')
        from mcni.pyre_components.MonochromaticSource import MonochromaticSource
        self.assertEqual(f, MonochromaticSource)

        f1 = componentfactory('sources', 'Source_simple', 'mcstas2')
        import mcstas2.pyre_support
        f1a = mcstas2.pyre_support.componentfactory('sources', 'Source_simple')
        self.assertEqual(f1, f1a)
        return
Beispiel #2
0
    def test1(self):
        'mcni.pyre_support: componentfactory'
        from mcni.pyre_support import componentfactory
        f = componentfactory( 'sources', 'MonochromaticSource' )
        from mcni.pyre_components.MonochromaticSource import MonochromaticSource
        self.assertEqual( f, MonochromaticSource )

        f1 = componentfactory( 'sources', 'Source_simple', 'mcstas2' )
        import mcstas2.pyre_support 
        f1a = mcstas2.pyre_support.componentfactory( 'sources', 'Source_simple' )
        self.assertEqual( f1, f1a )
        return
Beispiel #3
0
def componentinfo(*args, **kwds):
    kwds = dict(kwds)
    type = kwds['type']; del kwds['type']
    category = kwds.get('category')
    if kwds.has_key('category'): del kwds['category']
    supplier = kwds.get('supplier')
    if kwds.has_key('supplier'): del kwds['supplier']
    
    # find the component factory and instantiate a componnet
    from mcni._find_component import find
    found = find(type, category=category, supplier=supplier)
    if found is None:
        msg = "Failed to find component (type=%s, category=%s, supplier=%s)" % (type, category, supplier)
        raise RuntimeError, msg
    type, category, supplier = found
    factory = componentfactory(type=type, category=category, supplier=supplier)
    if hasattr(factory, 'factoryfactory'):
        factory = factory(*args, **kwds)
    comp = factory('component')
    # docs for parameters
    from mcni.pyre_support._invutils import getComponentPropertyNameTipPairs
    params = getComponentPropertyNameTipPairs(comp)
    l = ['  * %s: %s' % (k,v) for k,v in params]
    # title
    simple_description = comp.simple_description
    title = '%s: %s' % (type, simple_description)
    full_description = comp.full_description
    #
    startend = '='*70; separator = '-'*70
    l = [startend, title, separator, full_description, separator, 'Parameters:'] + l + [startend]
    #
    return '\n'.join(l)
Beispiel #4
0
 def test_NeutronFromStorage(self):
     'mcni.pyre_support.componentfactory: sources/NeutronFromStorage'
     from mcni.pyre_support import componentfactory
     f = componentfactory( 'sources', 'NeutronFromStorage' )
     from mcni.pyre_components.NeutronFromStorage import NeutronFromStorage
     self.assertEqual( f, NeutronFromStorage )
     return
Beispiel #5
0
 def test_MonochromaticSource(self):
     'mcni.pyre_support.componentfactory: sources/MonochromaticSource'
     from mcni.pyre_support import componentfactory
     f = componentfactory( 'sources', 'MonochromaticSource' )
     from mcni.pyre_components.MonochromaticSource import MonochromaticSource
     self.assertEqual( f, MonochromaticSource )
     return
 def test_NeutronToStorage(self):
     'mcni.pyre_support.componentfactory: monitors/NeutronToStorage'
     from mcni.pyre_support import componentfactory
     f = componentfactory('monitors', 'NeutronToStorage')
     from mcni.pyre_components.NeutronToStorage import NeutronToStorage
     self.assertEqual(f, NeutronToStorage)
     return
 def test_NeutronToStorage(self):
     'mcni.pyre_support.componentfactory: monitors/NeutronToStorage'
     from mcni.pyre_support import componentfactory
     f = componentfactory( 'monitors', 'NeutronToStorage' )
     from mcni.pyre_components.NeutronToStorage import NeutronToStorage
     self.assertEqual( f, NeutronToStorage )
     return
Beispiel #8
0
def componentinfo(*args, **kwds):
    kwds = dict(kwds)
    type = kwds['type']
    del kwds['type']
    category = kwds.get('category')
    if kwds.has_key('category'): del kwds['category']
    supplier = kwds.get('supplier')
    if kwds.has_key('supplier'): del kwds['supplier']

    # find the component factory and instantiate a componnet
    from mcni._find_component import find
    found = find(type, category=category, supplier=supplier)
    if found is None:
        msg = "Failed to find component (type=%s, category=%s, supplier=%s)" % (
            type, category, supplier)
        raise RuntimeError, msg
    type, category, supplier = found
    factory = componentfactory(type=type, category=category, supplier=supplier)
    if hasattr(factory, 'factoryfactory'):
        factory = factory(*args, **kwds)
    comp = factory('component')
    # docs for parameters
    from mcni.pyre_support._invutils import getComponentPropertyNameTipPairs
    params = getComponentPropertyNameTipPairs(comp)
    l = ['  * %s: %s' % (k, v) for k, v in params]
    # title
    simple_description = comp.simple_description
    title = '%s: %s' % (type, simple_description)
    full_description = comp.full_description
    #
    startend = '=' * 70
    separator = '-' * 70
    l = [
        startend, title, separator, full_description, separator, 'Parameters:'
    ] + l + [startend]
    #
    return '\n'.join(l)