def test_overrides_are_not_saved(self): cfg = ConfigStruct('/home/mycfg', options={'one': 1, 'two': 2}) cfg.options.might_prefer(one='cage match', two=None) cfg.save() with open('/home/mycfg') as fh: body = fh.read().strip() assert 'two = 2' in body and 'one = 1' in body
def test_my_added_items(self): cfg = ConfigStruct('/home/mycfg', options={}) self.mfs.add_entries({'/home/mycfg': '[options]\nfancy = True\n'}) cfg.options.shoes = 'unlaced' cfg.save() with open('/home/mycfg') as fh: body = fh.read().strip() assert 'fancy = True' in body and 'shoes = unlaced' in body
def test_their_added_items(self): cfg = ConfigStruct('/home/mycfg', options={}) self.mfs.add_entries({'/home/mycfg': '[options]\nfancy = True\nshoes = laced'}) cfg.options.fancy = 'MINE, DAMMIT!' cfg.save() with open('/home/mycfg') as fh: body = fh.read().strip() assert 'fancy = MINE, DAMMIT!' in body and 'shoes = laced' in body
def test_default_logging_options(self): cfg = ConfigStruct('/home/mycfg', 'options') cfg.save() with open('/home/mycfg') as fh: body = fh.read().strip() assert 'log_level = info' in body and 'log_file = STDERR' in body
def test_with_defaults(self): cfg = ConfigStruct('/home/mycfg', options={'one': 1}) assert cfg.options.one == 1 cfg.save() with open('/home/mycfg') as fh: assert fh.read().strip() == '[options]\none = 1'
def test_empty_save(self): cfg = ConfigStruct('/home/mycfg') cfg.save() assert os.path.getsize('/home/mycfg') == 0