Ejemplo n.º 1
0
def test_config_inheritance_error(tmpfile, other_tmpfile):
    write_json(tmpfile, _config_type='test', _include=[other_tmpfile])
    write_json(other_tmpfile, _config_type='not_test')

    with pytest.raises(AssertionError):
        config = configs.load(tmpfile, 'test')

    with pytest.raises(AssertionError):
        config = configs.load(tmpfile)
Ejemplo n.º 2
0
def test_config_read(tmpfile):
    write_json(tmpfile, _config_type='test', test=True)

    config = configs.load(tmpfile, 'test')
    assert config['_config_type'] == 'test'
    assert config['test']

    config = configs.load(tmpfile)
    assert config['_config_type'] == 'test'
    assert config['test']

    with pytest.raises(AssertionError):
        config = configs.load(tmpfile, 'not_test')
Ejemplo n.º 3
0
def test_config_inheritance_complex(tmpfile, other_tmpfile):
    write_json(tmpfile,
               _config_type='test',
               _include=[other_tmpfile],
               dict_field={
                   'base': True,
                   'dict': {
                       'overwrite': True
                   }
               },
               list_field=[1])
    write_json(other_tmpfile,
               _config_type='test',
               dict_field={
                   'inherited': True,
                   'base': False,
                   'dict': {
                       'test': True,
                       'overwrite': False
                   }
               },
               list_field=[2])
    config = configs.load(tmpfile)
    assert config['dict_field']['base']
    assert config['dict_field']['inherited']
    assert config['dict_field']['dict']['test']
    assert config['dict_field']['dict']['overwrite']
    assert config['list_field'] == [1]
Ejemplo n.º 4
0
def test_config_inheritance_order(tmpfile, other_tmpfile, other_other_tmpfile):
    write_json(tmpfile,
               _config_type='test',
               _include=[other_tmpfile, other_other_tmpfile])
    write_json(other_tmpfile, _config_type='test', test=1)
    write_json(other_other_tmpfile, _config_type='test', test=2)

    config = configs.load(tmpfile)
    assert config['test'] == 2
Ejemplo n.º 5
0
def test_config_inheritance(tmpfile, other_tmpfile):
    write_json(tmpfile,
               _config_type='test',
               _include=[other_tmpfile],
               test=True)
    write_json(other_tmpfile, _config_type='test', inherited=True)

    config = configs.load(tmpfile, 'test')
    assert config['inherited']
    assert config['test']

    write_json(tmpfile,
               _config_type='test',
               _include=[other_tmpfile],
               test=True)
    write_json(other_tmpfile, _config_type='test', test=False)

    config = configs.load(tmpfile, 'test')
    assert config['test']
Ejemplo n.º 6
0
    def load(self, filepath=None):
        '''
        Loads a specified IO configuration

        :param filepath: path to io configuration file (JSON)

        '''
        if filepath is None:
            filepath = self.default_filepath
        config = configs.load(filepath)
        if (config['_config_type'] not in self._valid_config_types or
            config['io_class'] not in self._valid_config_classes):
            raise RuntimeError('Invalid configuration type for {}'.format(type(self).__name__))
        self._io_group_table = bidict.bidict(config['io_group'])
def test_conf_all_registers():
    default_filename = 'chip/default_lightpix_v1.json'
    data = configs.load(default_filename)

    c = Configuration_Lightpix_v1()
    print(data, len(data))
    print(c.register_names,len(c.register_names))
    # check that all registers are in the configuration file
    assert set(data['register_values'].keys()) == set(c.register_names)
    for register in c.register_names:
        print('testing {}'.format(register))
        config_value = data['register_values'][register]
        stored_value = getattr(c,register)

        # test getters
        assert stored_value == config_value

        # test setters
        if register == 'chip_id':
            new_value = 12
        elif isinstance(stored_value, list):
            new_value = []
            for value in stored_value:
                if value == 1:
                    new_value += [0]
                elif value == 0:
                    new_value += [1]
                else:
                    new_value += [value-1]
        elif isinstance(stored_value, int):
            if stored_value == 1:
                new_value = 0
            elif stored_value == 0:
                new_value = 1
            else:
                new_value = stored_value-1
        setattr(c,register,new_value)
        assert getattr(c,register) == new_value

        # test data getters
        assert list(c.register_map[register]) == [reg for reg,bits in getattr(c,register+'_data')]