예제 #1
0
    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()
예제 #2
0
 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()
예제 #3
0
 def __init__(self, file_, retain_case):
     self.retain_case = retain_case
     self.config = ConfigReader(file_, case_sensitive=self.retain_case)