def _with_contact_table(args, **kwargs): args = cli.parse_args(args) options = '\n'.join('{}={}'.format(key, kwargs[key]) for key in kwargs) conf = config.Config( io.StringIO('[addressbooks]\n[[test]]\npath=.\n' '[contact table]\n' + options)) return cli.merge_args_into_config(args, conf)
def test_load_non_existing_file_fails(self): filename = "I hope this file never exists" stdout = io.StringIO() with mock.patch("sys.stdout", stdout): with self.assertRaises(SystemExit): config.Config(filename) self.assertEqual(stdout.getvalue(), "Config file " + filename + " not available\n")
def __fill_cache(self): khard_config = config.Config() for vcard in khard.get_contacts(khard_config.abooks, '', 'name', False, False): for type, email_list in vcard.get_email_addresses().items(): for email in email_list: self.__cache.append({ 'word': "{0} <{1}>".format(vcard.get_first_name_last_name(), email) })
def __fill_cache(self): khard_config = config.Config() khard_config.init_address_books() for vcard in khard.get_contacts(khard_config.abooks, query.AnyQuery(), False, False): for type, email_list in vcard.emails.items(): for email in email_list: self.__cache.append({ 'word': "{0} <{1}>".format(vcard.get_first_name_last_name(), email) })
def __fill_cache(self): khard_config = config.Config() abooks = [] for addressbook in khard_config.get_all_address_books(): abooks.append(khard_config.get_address_book( addressbook.name, None)) for vcard in khard.get_contacts(abooks, '', 'name', False, False): for type, email_list in vcard.get_email_addresses().items(): for email in email_list: self.__cache.append({ 'word': "{0} <{1}>".format( remove_accents(vcard.get_first_name_last_name()), email) })
def test_editor_defaults_to_vim(self): c = config.Config("test/fixture/minimal.conf") self.assertEqual(c.editor, 'vim')
def test_preferred_version_defaults_to_3(self): c = config.Config("test/fixture/minimal.conf") self.assertEqual(c.preferred_vcard_version, '3.0')
def _merge(args): args, _conf = cli.parse_args(args) # This config file just loads all defaults from the config.spec. conf = config.Config(io.StringIO('[addressbooks]\n[[test]]\npath=.')) return cli.merge_args_into_config(args, conf)
def test_show_uids_defaults_to_true(self): c = config.Config("test/fixture/minimal.conf") self.assertTrue(c.show_uids)
def test_group_by_addressbook_defaults_to_false(self): c = config.Config("test/fixture/minimal.conf") self.assertFalse(c.group_by_addressbook)
def test_default_action_defaults_to_list(self): c = config.Config("test/fixture/minimal.conf") self.assertEqual(c.default_action, 'list')
def test_set_preferred_version(self): c = config.Config("test/fixture/minimal.conf") c.preferred_vcard_version = "11" self.assertEqual(c.preferred_vcard_version, "11")
def test_load_minimal_file_by_name(self): cfg = config.Config("test/fixture/minimal.conf") self.assertEqual(cfg.editor, "editor") self.assertEqual(cfg.merge_editor, "meditor")
def test_merge_editor_defaults_to_vimdiff(self): c = config.Config("test/fixture/minimal.conf") self.assertEqual(c.merge_editor, 'vimdiff')
def test_load_empty_file_fails(self): stdout = io.StringIO() with mock.patch("sys.stdout", stdout): with self.assertRaises(SystemExit): config.Config("/dev/null") self.assertTrue(stdout.getvalue().startswith('Error in config file\n'))
def test_load_empty_file_fails(self): with tempfile.NamedTemporaryFile() as name: with self.assertLogs(level=logging.ERROR): with self.assertRaises(config.ConfigError): config.Config(name)
def test_default_action_defaults_to_none(self): c = config.Config("test/fixture/minimal.conf") self.assertIsNone(c.default_action)
def test_load_empty_file_fails(self): stdout = io.StringIO() with tempfile.NamedTemporaryFile() as name: with self.assertLogs(level=logging.ERROR) as cm: with self.assertRaises(SystemExit): config.Config(name)
def test_localize_dates_defaults_to_true(self): c = config.Config("test/fixture/minimal.conf") self.assertTrue(c.localize_dates)
def test_default_value_is_3(self): c = config.Config("test/fixture/minimal.conf") self.assertEqual(c.preferred_vcard_version, "3.0")
def test_preferred_phone_number_type_defaults_to_pref(self): c = config.Config("test/fixture/minimal.conf") self.assertListEqual(c.preferred_phone_number_type, ['pref'])
def test_debug_defaults_to_false(self): c = config.Config("test/fixture/minimal.conf") self.assertFalse(c.debug)
def test_preferred_email_address_type_defaults_to_pref(self): c = config.Config("test/fixture/minimal.conf") self.assertListEqual(c.preferred_email_address_type, ['pref'])
def test_reverse_defaults_to_false(self): c = config.Config("test/fixture/minimal.conf") self.assertFalse(c.reverse)
def test_private_objects_defaults_to_empty(self): c = config.Config("test/fixture/minimal.conf") self.assertListEqual(c.private_objects, [])
def test_show_nicknames_defaults_to_false(self): c = config.Config("test/fixture/minimal.conf") self.assertFalse(c.show_nicknames)
def test_search_in_source_files_defaults_to_false(self): c = config.Config("test/fixture/minimal.conf") self.assertFalse(c.search_in_source_files)
def test_sort_defaults_to_first_name(self): c = config.Config("test/fixture/minimal.conf") self.assertEqual(c.sort, 'first_name')
def test_skip_unparsable_defaults_to_false(self): c = config.Config("test/fixture/minimal.conf") self.assertFalse(c.skip_unparsable)