def test_pickling():
    # Create files
    with create_test_environment(test_cases[0]['config']) as dirname:
        # Load configuration
        master = ConfigMaster('veh')
        master.add_class('vehicles', '*.vehicles.yaml',
                         check=dummy_check,
                         instance=dummy_instance)
        master.load(dirname)
        s = BytesIO()
        pickle.dump(master, s)
def check_case(config, query, result):
    # Create files
    with create_test_environment(config) as dirname:
        # Load configuration
        master = ConfigMaster('veh')
        master.add_class('vehicles', '*.vehicles.yaml')
        master.load(dirname)
        spec = master.specs['vehicles'][query]

        if spec != result:
            print('Obtained:\n%s' % pformat(spec))
            print(' Desired:\n%s' % pformat(result))
            raise Exception('Wrong result')
def check_group_case(config, query, expected):
    with create_test_environment(config) as dirname:
        # Load configuration
        master = ConfigMaster('veh')
        master.add_class('vehicles', '*.vehicles.yaml')
        master.load(dirname)

        result = master.vehicles.expand_names(query)

        if set(expected) != set(result):
            print('Obtained:\n%s' % pformat(expected))
            print(' Desired:\n%s' % pformat(result))
            raise Exception('Wrong result')
def check_can_be_loaded(tc):
    # Create files
    with create_test_environment(tc['config']) as dirname:
        master = ConfigMaster('veh')

        def check_entry(entry):
            if not 'desc' in entry:
                raise ValueError('No desc field')

        master.add_class('things', '*.things.yaml', check=check_entry)
        master.load(dirname)
        master.specs['things'].make_sure_everything_read()

        should_have = tc.get('should_have', None)
        if should_have is not None:
            found = set(master.specs['things'].keys())
            if set(should_have) != found:
                msg = 'Expected %r, obtained %r.' % (should_have, found)
                raise Exception(msg)