Ejemplo n.º 1
0
def test_instance():
    data="""
"adder.easy_algo_family.yaml": | 
    description: desc
    interface: easy_algo_tests.validity.MyAdderInterface

"one.adder.yaml": |
    description: desc
    constructor: easy_algo_tests.validity.One
    parameters:

"not_sub.adder.yaml": |
    description: desc
    constructor: easy_algo_tests.validity.Two
    parameters:

"""
    d = dtu.dir_from_data(data)
    sources = [d]
    db = EasyAlgoDB(sources)
     
    print format_db(db)
    
    family = db.get_family('adder')
    assert family.valid == True
    
    one = db.create_instance('adder', 'one')
    
    assert type(one).__name__ == 'One'

    try:
        db.create_instance('not_found', 'does_not_exist')
        raise Exception()
    except Exception as e:
        assert 'not find' in str(e), e
    
    try:
        db.create_instance('adder', 'does_not_exist')
        raise Exception()
    except Exception as e:
        assert 'not find' in str(e), e
        
    try:
        db.create_instance('adder', 'not_sub')
        raise Exception()
    except Exception as e:
        assert 'MyAdderInterface' in str(e)
Ejemplo n.º 2
0
def test_instance():
    data = """
"adder.easy_algo_family.yaml": | 
    description: desc
    interface: easy_algo_tests.validity.MyAdderInterface

"one.adder.yaml": |
    description: desc
    constructor: easy_algo_tests.validity.One
    parameters:

"not_sub.adder.yaml": |
    description: desc
    constructor: easy_algo_tests.validity.Two
    parameters:

"""
    d = dtu.dir_from_data(data)
    sources = [d]
    db = EasyAlgoDB(sources)

    print((format_db(db)))

    family = db.get_family("adder")
    assert family.valid == True

    one = db.create_instance("adder", "one")

    assert type(one).__name__ == "One"

    try:
        db.create_instance("not_found", "does_not_exist")
        raise Exception()
    except Exception as e:
        assert "not find" in str(e), e

    try:
        db.create_instance("adder", "does_not_exist")
        raise Exception()
    except Exception as e:
        assert "not find" in str(e), e

    try:
        db.create_instance("adder", "not_sub")
        raise Exception()
    except Exception as e:
        assert "MyAdderInterface" in str(e)
Ejemplo n.º 3
0
def call_summary():
    db = get_easy_algo_db()
    s = format_db(db)
    logger.info(s)

    errors = []
    for f in db.family_name2config.values():
        if not f.valid:
            errors.append('Family %s: %s' %
                          (f.family_name, f.error_if_invalid))
        for i in f.instances.values():
            if not i.valid:
                errors.append('Family %s / instance %r: %s' %
                              (f, i.instance_name, i.error_if_invalid))

    if errors:
        msg = '\n' + '\n'.join(f.instances)
        raise Exception(msg)
Ejemplo n.º 4
0
def call_summary():
    db = get_easy_algo_db()
    s = format_db(db)
    dtu.logger.info(s)

    errors = []
    for f in list(db.family_name2config.values()):
        if not f.valid:
            errors.append(f"Family {f.family_name}: {f.error_if_invalid}")
        for i in list(f.instances.values()):
            if not i.valid:
                errors.append(
                    f"Family {f.family_name} / instance {i.instance_name!r}:\n\n"
                    f"{dtu.indent(i.error_if_invalid, '  ')}"
                )

    if errors:
        msg = "\n" + "\n".join(errors)
        raise Exception(msg)
Ejemplo n.º 5
0
    def go(self):
        args = self.options.get_extra()
        db = get_easy_algo_db()
        colorize = True
        verbose = self.options.verbose
        if len(args) == 0:
            s = format_db(db, verbose=verbose, colorize=colorize)

        elif len(args) == 1:
            family = db.get_family(args[0])

            s = format_instances(family,
                                 colorize=colorize,
                                 verbose=self.options.verbose)
        elif len(args) == 2:
            family_name = args[0]
            family = db.get_family(family_name)
            instance_name = args[1]
            instance = db.create_instance(family_name, instance_name)

            s = instance
        print(s)