def test_reading_generated_file(self): dump = self.config.dump() re_init_config = BootConfigParser(dump) re_init_dump = re_init_config.dump() self.assertEqual(dump.splitlines(), re_init_dump.splitlines())
def get_value(self, name, config_filter=Filter.ALL, fallback=True, ignore_comments=False): lines = read_file_contents_as_lines(self.path) if not lines: return 0 config = BootConfigParser(lines) return config.get( name, config_filter=config_filter, fallback=fallback, ignore_comments=ignore_comments )
def set_value(self, name, value=None, config_filter=Filter.ALL): # if the value argument is None, the option will be commented out lines = read_file_contents_as_lines(self.path) if not lines: # this is true if the file is empty, not sure that was intended. return logger.info('writing value to {} {} {}'.format(self.path, name, value)) config = BootConfigParser(lines) config.set(name, value, config_filter=config_filter) with open_locked(self.path, "w") as boot_config_file: boot_config_file.write(config.dump()) # flush changes to disk boot_config_file.flush() os.fsync(boot_config_file.fileno())
def test_empty_list_init(self): test = BootConfigParser([]) self.check_null_get(test)
def test_empty_string_init(self): test = BootConfigParser('') self.check_null_get(test)
def test_none_init(self): test = BootConfigParser(None) self.check_null_get(test)
def test_list_init(self): test = BootConfigParser(self.base_config.splitlines()) self.compare_config_dumps(self.base_config, test.dump())
def setUp(self): self.base_config = BASE_TEST_CONFIG self.config = BootConfigParser(self.base_config)