def test_backup_dictionaries_to_json_and_reload(self): original_dictionaries = self.engine.config['dictionaries'] #import pdb; pdb.set_trace() backup_dictionary_stack(original_dictionaries, pdc.BACKUP_DICTIONARY_PATH) toggle_dict(self.engine, '-main.json') self.assertEqual( self.engine.config['dictionaries'], [ self.user, self.commands, self.english.replace(enabled=False), # turned off self.spanish, ]) restored_dictionaries = load_dictionary_stack_from_backup( pdc.BACKUP_DICTIONARY_PATH) self.engine.config = {'dictionaries': restored_dictionaries} self.assertEqual( self.engine.config['dictionaries'], [ self.user, self.commands, self.english, # turned back on again after restore self.spanish, ]) backup_dictionary_stack([], pdc.BACKUP_DICTIONARY_PATH)
def test_toggle_dict_shortest_path_is_default(self): toggle_dict(self.engine, '+main.json, -spanish/main.json') self.assertEqual(self.engine.config['dictionaries'], [ self.user, self.commands, self.english.replace(enabled=True), self.spanish.replace(enabled=False), ])
def test_toggle_dict_multiple(self): toggle_dict(self.engine, '+spanish/main.json, !commands.json, -user.json') self.assertEqual(self.engine.config['dictionaries'], [ self.user.replace(enabled=False), self.commands.replace(enabled=False), self.english, self.spanish, ])
def test_end_solo_dict_restores_previous_state(self): toggle_dict(self.engine, '-main.json') solo_dict(self.engine, '+spanish/main.json') end_solo_dict(self.engine, '') self.assertEqual(self.engine.config['dictionaries'], [ self.user, self.commands, self.english.replace(enabled=False), self.spanish, ])
def test_backed_up_dictionaries_restored_after_solo_if_backup_exists(self): toggle_dict(self.engine, '-main.json') #turned off before backup... original_dictionaries = self.engine.config['dictionaries'] backup_dictionary_stack(original_dictionaries, pdc.BACKUP_DICTIONARY_PATH) toggle_dict(self.engine, '+main.json') #but normal before solo_dict #Now that there's a backup file, do the first solo_dict since we've run... solo_dict(self.engine, '+spanish/main.json') end_solo_dict(self.engine, '') self.assertEqual( self.engine.config['dictionaries'], [ self.user, self.commands, self.english.replace( enabled=False), # turned back off again after restore self.spanish, ])
def test_toggle_dict_invalid_dictionary(self): with self.assertRaises(ValueError): toggle_dict(self.engine, '+foobar.json')
def test_toggle_dict_invalid_toggle(self): with self.assertRaises(ValueError): toggle_dict(self.engine, '=user.json')