def test_both_toronto_and_non_toronto_phone_numbers(self): names = [{'name': 'John', 'hp': '647-000-1000', 'ha': '1 Loop Dr.', 'fav': True}, {'surname': 'Kiwi', 'name': 'Frank', 'cp': '416-222-1890', 'ha': '10 Infinite Loop Dr.'}, {'surname': 'Larry', 'name': 'Sans', 'wp': '800-000-8501', 'fav': True}, {'surname': 'Op', 'name': 'Erica', 'hp': '512-354-1890', 'email': '*****@*****.**', 'ha': '13 Infinite Loop Dr.'}] names_416 = [{'surname': 'Kiwi', 'name': 'Frank', 'cp': '416-222-1890', 'ha': '10 Infinite Loop Dr.'}] names_647 = [{'name': 'John', 'hp': '647-000-1000', 'ha': '1 Loop Dr.', 'fav': True}] head, tail, size = build_node_list(names) self.pb_actual._set_list(head, tail, size) pb_416, pb_647 = a1.PhoneBook(), a1.PhoneBook() head, tail, size = build_node_list(names_416) pb_416._set_list(head, tail, size) head, tail, size = build_node_list(names_647) pb_647._set_list(head, tail, size) actual_416, actual_647 = self.pb_actual.toronto_phone() self.assertTrue(compare_phonebooks(pb_416, actual_416), 'Phone book content not the same') self.assertTrue(compare_phonebooks(pb_647, actual_647), 'Phone book content not the same')
def start(self): """Starts the interface""" try: if not os.path.exists(tel.CONFIG.CONFIG_DIR): os.mkdir(tel.CONFIG.CONFIG_DIR) (options, args) = self._parse_args() self.phonebook = phonebook.PhoneBook(options.file) options.command_function(options, *args) except KeyboardInterrupt: sys.exit(_('Dying peacefully ...'))
def test_return_type(self): names_exp = [{'surname': 'Kiwi', 'name': 'Frank', 'cp': '437-222-1890', 'wp': '800-222-1890'}] names_act = [{'surname': 'Kiwi', 'name': 'Frank', 'wp': '800-222-1890'}] names_to_sync = [{'surname': 'Kiwi', 'name': 'Frank', 'cp': '437-222-1890'}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) pb_sync = a1.PhoneBook() head, tail, size = build_node_list(names_to_sync) pb_sync._set_list(head, tail, size) actual = self.pb_actual.sync_phonebook(pb_sync) self.assertIsNone(actual, 'Incorrect return type')
def test_sync_contact_different_people(self): names_exp = [{'surname': 'Kiwi', 'name': 'Frank', 'wp': '800-222-1890'}, {'surname': 'Larry', 'name': 'Sans', 'hp': '616-000-8501', 'fav': True}] names_act = [{'surname': 'Kiwi', 'name': 'Frank', 'wp': '800-222-1890'}] names_to_sync = [{'surname': 'Larry', 'name': 'Sans', 'hp': '616-000-8501', 'fav': True}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) pb_sync = a1.PhoneBook() head, tail, size = build_node_list(names_to_sync) pb_sync._set_list(head, tail, size) self.pb_actual.sync_phonebook(pb_sync) self.assertTrue(compare_phonebooks(self.pb_expect, self.pb_actual), 'Failed to sync 2 phone books with 2 different people contact')
def test_sync_contact_same_person(self): names_exp = [{'surname': 'Kiwi', 'name': 'Frank', 'cp': '437-222-1890', 'wp': '800-222-1890'}, {'surname': 'Kiwi', 'name': 'Frank', 'hp': '115-885-1287'}] names_act = [{'surname': 'Kiwi', 'name': 'Frank', 'cp': '437-222-1890', 'wp': '800-222-1890'}] names_to_sync = [{'surname': 'Kiwi', 'name': 'Frank', 'hp': '115-885-1287'}] head, tail, size = build_node_list(names_exp) self.pb_expect._set_list(head, tail, size) head, tail, size = build_node_list(names_act) self.pb_actual._set_list(head, tail, size) pb_sync = a1.PhoneBook() head, tail, size = build_node_list(names_to_sync) pb_sync._set_list(head, tail, size) self.pb_actual.sync_phonebook(pb_sync) self.assertTrue(compare_phonebooks(self.pb_expect, self.pb_actual), 'Failed to sync 2 phone books with 1 same person contact')
def _cmd_import(self, options, *args): """Import phone books""" for path in args: # import all specified phone books if os.path.exists(path): if (os.path.abspath(path) == os.path.abspath( self.phonebook.path)): resp = raw_input( _('Do you really want to import the ' 'phone book you\'re just using? ')) if resp.lower() != 'y': print _('Not importing %s...') % path continue import_book = phonebook.PhoneBook(path) for entry in import_book: # enable auto-generation of index entry.index = None self.phonebook.add(entry) self.phonebook.save()
import utils import os import phonebook as pb import pbshell as sh DEFAULT_PATH = "users.dat" book = pb.PhoneBook(DEFAULT_PATH) shell = sh.PBShell(book) if __name__ == '__main__': shell.cmdloop()
import phonebook contact_1 = phonebook.Contact('Василий', 'Иванов', 89213457896, email='*****@*****.**') contact_2 = phonebook.Contact('Пётр', 'Сидоров', 756392, 89213457896, email='*****@*****.**', vk='vk.com/1234455433', home=998877) telephone_book = phonebook.PhoneBook('Новая телефонная книга') telephone_book.add_contact(contact_1) telephone_book.add_contact(contact_2) telephone_book.add_contact('Иван', 'Конюхов', 83246544466, 332211, email='*****@*****.**') telephone_book.add_contact('Unknown', 'number', 88001239090) telephone_book.show_contacts() telephone_book.delete_contact_by_number(88001239090) telephone_book.show_contacts() print('Список избранных номеров:') print(telephone_book.find_all_favorite_numbers()) print()
import contact import phonebook if __name__ == '__main__': anton = contact.Contact('Anton', 'Vasilyev', '+7123', telegram='telega', email='*****@*****.**', work_phone='+7456') vasya = contact.Contact('Vasya', 'Pupkin', '+7697', fav_contact='Anton Vasilyev', email='*****@*****.**') pb = phonebook.PhoneBook('Телефонная книга') # print(anton) # print(vasya) # Карточка контакта pb.add_contact(anton) pb.add_contact(vasya) # Добавляем контакты pb.show_contacts() # Показать добавленные контакты pb.del_contact('+7123') # Удаление контакта
#!/usr/bin/python # # \file main2.py # \author Martin Reddy # \brief Demonstrate calling a C++ API from Python. # # Copyright (c) 2010, Martin Reddy. All rights reserved. # Distributed under the X11/MIT License. See LICENSE.txt. # See http://APIBook.com/ for the latest version. # import phonebook # create the phonebook book = phonebook.PhoneBook() # add one contact p = phonebook.Person() p.name = 'Martin' p.home_number = '(123) 456-7890' book.add_person(p) # add another contact p = phonebook.Person() p.name = 'Genevieve' p.home_number = '(123) 456-7890' book.add_person(p) # display number of contacts added print "No. of contacts =", book.size()
def setUp(self): self.pb_expect = a1.PhoneBook() self.pb_actual = a1.PhoneBook()
def test_init_with_contact(self): c = a1.Contact(surname='Alex', cp='647-000-1000') pb = a1.PhoneBook(c) self.assertEqual(c, pb.get_head().get_element(), 'Failed to create new Phone book with only one contact') self.assertEqual(c, pb.get_tail().get_element(), 'Failed to create new Phone book with only one contact') self.assertEqual(1, pb.size(), 'Failed to create new Phone book with only one contact')