示例#1
0
文件: config.py 项目: yiu31802/ave
def t11(pretty, factory):
    # build valid config file
    factory.write_config(
        FILENAME, {
            '*': {
                'groups': {
                    'a': {
                        'usb.pc.vcc': 1,
                        'usb.pc.d+': 2
                    },
                    'b': {
                        'usb.pc.vcc': 3,
                        'usb.pc.d+': 4
                    }
                }
            },
            '456': {
                'groups': {
                    'a': {
                        'usb.pc.vcc': 1,
                        'usb.pc.d+': 2
                    },
                    'b': {
                        'usb.pc.vcc': 5,
                        'usb.pc.d+': 6
                    }
                }
            }
        })

    try:
        r1 = Relay(PROFILE_1, home=factory.HOME.path)
    except Exception, e:
        print('FAIL %s: first __init__() failed: %s' % (pretty, e))
        return False
示例#2
0
文件: config.py 项目: yiu31802/ave
def t08(pretty, factory):
    # build valid config file
    factory.write_config(
        FILENAME, {
            '123': {
                'groups': {
                    'a': {
                        'usb.pc.vcc': 1,
                        'usb.pc.d+': 2
                    },
                    'b': {
                        'usb.pc.vcc': 3,
                        'usb.pc.d+': 4
                    }
                }
            },
            '456': {
                'groups': {
                    'group_1': {
                        'usb.pc.vcc': 1,
                        'usb.pc.d+': 2
                    },
                    'group_2': {
                        'usb.pc.vcc': 5,
                        'usb.pc.d+': 6
                    }
                }
            }
        })
    try:
        r = Relay(PROFILE_1, home=factory.HOME.path)
    except Exception, e:
        print('FAIL %s: could not initialize: %s' % (pretty, str(e)))
        return False
示例#3
0
文件: config.py 项目: yiu31802/ave
def t07(pretty, factory):
    # build invalid config file. circuit number is used twice
    factory.write_config(
        FILENAME, {
            '123': {
                'groups': {
                    'a': {
                        'usb.pc.vcc': 1,
                        'usb.pc.d+': 2
                    },
                    'b': {
                        'usb.pc.vcc': 3,
                        'usb.pc.d+': 2
                    }
                }
            }
        })
    try:
        Relay(PROFILE_1, home=factory.HOME.path)
        print('FAIL %s: __init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'port 2 is used more than once' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
示例#4
0
文件: config.py 项目: yiu31802/ave
def t01(pretty, factory):
    try:
        dev = Relay(PROFILE_1, home=factory.HOME.path)
        print('FAIL %s: __init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'no such config file: %s' % factory.HOME.path not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
示例#5
0
文件: config.py 项目: yiu31802/ave
def t04(pretty, factory):
    # build invalid config file. groups must be string:integer dictionaries
    factory.write_config(FILENAME, {'123': {'groups': {'a': {'foo': 'bar'}}}})
    try:
        Relay(PROFILE_1, home=factory.HOME.path)
        print('FAIL %s: __init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'circuit "foo" is not an integer' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
示例#6
0
文件: config.py 项目: yiu31802/ave
def t03(pretty, factory):
    # build invalid config file
    factory.write_config(FILENAME, {'123': {'groups': {'a': None}}})
    try:
        Relay(PROFILE_1, home=factory.HOME.path)
        print('FAIL %s: __init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'group "a" is not a dictionary' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
示例#7
0
文件: config.py 项目: yiu31802/ave
def t05(pretty, factory):
    # build config file with invalid content. group contains a circuit with
    # an unknown label "foo"
    factory.write_config(FILENAME, {'123': {'groups': {'a': {'foo': 5}}}})
    try:
        Relay(PROFILE_1, home=factory.HOME.path)
        print('FAIL %s: __init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'circuit identifier "foo" is invalid' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
示例#8
0
文件: config.py 项目: yiu31802/ave
def t02(pretty, factory):
    # build a broken config file
    path = os.path.join(factory.HOME.path, '.ave', 'config', 'devantech.json')
    with open(path, 'w') as f:
        f.write('{ "serial": "foobar" ')  # missing end bracket

    try:
        Relay(PROFILE_1, home=factory.HOME.path)
        print('FAIL %s: __init__() did not fail' % pretty)
        return False
    except Exception, e:
        if not str(e).startswith('could not load config file: Expecting '):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
示例#9
0
文件: config.py 项目: yiu31802/ave
def t06(pretty, factory):
    # build invalid config file. circuit number is out of bounds
    factory.write_config(FILENAME,
                         {'123': {
                             'groups': {
                                 'a': {
                                     'usb.pc.vcc': 9
                                 }
                             }
                         }})
    try:
        Relay(PROFILE_1, home=factory.HOME.path)
        print('FAIL %s: __init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'port 9 is out of bounds' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
示例#10
0
文件: config.py 项目: yiu31802/ave
def t09(pretty, factory):
    # build invalid config file
    factory.write_config(
        FILENAME, {
            '123': {
                'groups': {
                    'group_1': {
                        'usb.pc.vcc': 1,
                        'usb.pc.d+': 2
                    },
                    'group_2': {
                        'usb.pc.vcc': 3,
                        'usb.pc.d+': 4
                    }
                }
            },
            '456': {
                'groups': {
                    'group_1': {
                        'usb.pc.vcc': 1,
                        'usb.pc.d+': 2
                    },
                    'group_2': {
                        'usb.pc.vcc': 3,
                        'usb.pc.d+': 4
                    }
                }
            }
        })
    try:
        profile = BoardProfile({
            'type': 'relay',
            'serial': 'serial_3',
            'device_node': None,
            'vendor': 'devantech'
        })
        Relay(profile, home=factory.HOME.path)
        print('FAIL %s: __init__() did not fail' % pretty)
        return False
    except Exception, e:
        if 'no values for device with serial' not in str(e):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
示例#11
0
文件: config.py 项目: yiu31802/ave
                    },
                    'b': {
                        'usb.pc.vcc': 3,
                        'usb.pc.d+': 4
                    }
                }
            }
        })
    try:
        r1 = Relay(PROFILE_1, home=factory.HOME.path)
    except Exception, e:
        print('FAIL %s: first __init__() failed: %s' % (pretty, e))
        return False

    try:
        r2 = Relay(PROFILE_2, home=factory.HOME.path)
    except Exception, e:
        print('FAIL %s: first __init__() failed: %s' % (pretty, e))
        return False

    expect = {
        'groups': {
            'a': {
                'usb.pc.vcc': 1,
                'usb.pc.d+': 2
            },
            'b': {
                'usb.pc.vcc': 3,
                'usb.pc.d+': 4
            }
        },