def create(self, filename=None): """Create a sample file :param str filename: The name of the sample. Default to the name of the original file suffixed with `.sample` """ if filename is None: filename = f'{self.config.filename}.sample' try: os.remove(filename) except FileNotFoundError: pass with ConfigReader(filename, case_sensitive=self.retain_case) as sample: for section in self.config.sections: items = self.config.get_items(section) for k, v in items.items(): value = get_type(v) sample.set(k, value, section=section) sample.remove_section('main') sample.save()
def test_returns_false_if_config_file_not_exists(self): self.config = ConfigReader(self.file_path) self.assertFalse(os.path.isfile(self.config.filename)) self.config.close()
def __init__(self, file_, retain_case): self.retain_case = retain_case self.config = ConfigReader(file_, case_sensitive=self.retain_case)