def test_open_sets_and_close_clears_config_and_filename(self): cfg = IniConfig() cfg.open(f'{ASSETS_DIR}/1.ini') self.assert_equal({'some': {'thing': 'some value'}}, cfg.as_dict()) self.assert_equal(f'{ASSETS_DIR}/1.ini', cfg.config_file) self.assert_equal([f'{ASSETS_DIR}/1.ini'], cfg.loaded_files) cfg.close() self.assert_equal({}, cfg.as_dict()) self.assert_is_none(cfg.config_file) self.assert_equal([], cfg.loaded_files)
def test_config_can_be_extended_by_multiple_ini_files(self): cfg = IniConfig() cfg.open(f'{ASSETS_DIR}/1.ini') self.assert_equal(f'{ASSETS_DIR}/1.ini', cfg.config_file) self.assert_equal([f'{ASSETS_DIR}/1.ini'], cfg.loaded_files) self.assert_equal({'some': {'thing': 'some value'}}, cfg.as_dict()) cfg.open(f'{ASSETS_DIR}/2.ini', merge=True) self.assert_equal(f'{ASSETS_DIR}/1.ini', cfg.config_file) self.assert_equal([f'{ASSETS_DIR}/{x}.ini' for x in range(1, 3)], cfg.loaded_files) self.assert_equal({'more': {'stuff': '4444'}, 'some': {'thing': 'some value'}}, cfg.as_dict()) cfg.open(f'{ASSETS_DIR}/3.ini', merge=True) self.assert_equal(f'{ASSETS_DIR}/1.ini', cfg.config_file) self.assert_equal([f'{ASSETS_DIR}/{x}.ini' for x in range(1, 4)], cfg.loaded_files) self.assert_equal( {'some': {'thing': 'some value', 'thingy': 'multi\nline stuff'}, 'more': {'stuff': 'more.stuff.!\\nx'}}, cfg.as_dict())
def test_config_cannot_be_opened_twice_without_close(self): cfg = IniConfig() cfg.open(f'{ASSETS_DIR}/1.ini') self.assert_raises(IniConfigError, cfg.open, f'{ASSETS_DIR}/2.ini') cfg.close() cfg.open(f'{ASSETS_DIR}/2.ini') self.assert_equal({'more': {'stuff': '4444'}}, cfg.as_dict()) self.assert_equal(f'{ASSETS_DIR}/2.ini', cfg.config_file) self.assert_equal([f'{ASSETS_DIR}/2.ini'], cfg.loaded_files)