@classmethod
def read_csv(cls, csvPath):
- csvReader = iter(csv.reader(open(csvPath, "rU")))
+ try:
+ csvReader = iter(csv.reader(open(csvPath, "rU")))
+ except IOError, e:
+ if e.errno != 2:
+ raise
+ return
header = csvReader.next()
nameColumn, phoneColumns = cls._guess_columns(header)
"""
for root, dirs, filenames in os.walk(self.__path):
for filename in filenames:
- name, ext = filename.rsplit(".", 1)
+ try:
+ name, ext = filename.rsplit(".", 1)
+ except ValueError:
+ continue
+
if ext in self.FILETYPE_SUPPORT:
yield self, os.path.join(root, filename), name
--- /dev/null
+familyname,phone,addr1,addr2,addr3,addr4,name1,name2,name3,name4\r
+"Last, First","555-123-4567","1234 Foo St","Austin, Texas 78727","","","First <name@domain.com>"\r
--- /dev/null
+Name,E-mail,Notes,Section 1 - Description,Section 1 - Email,Section 1 - IM,Section 1 - Phone,Section 1 - Mobile,Section 1 - Pager,Section 1 - Fax,Section 1 - Company,Section 1 - Title,Section 1 - Other,Section 1 - Address,Section 2 - Description,Section 2 - Email,Section 2 - IM,Section 2 - Phone,Section 2 - Mobile,Section 2 - Pager,Section 2 - Fax,Section 2 - Company,Section 2 - Title,Section 2 - Other,Section 2 - Address,Section 3 - Description,Section 3 - Email,Section 3 - IM,Section 3 - Phone,Section 3 - Mobile,Section 3 - Pager,Section 3 - Fax,Section 3 - Company,Section 3 - Title,Section 3 - Other,Section 3 - Address\r
+First Last,name@domain.com,"Categories: Others\r
+\r
+\r
+Categories: Others",Other,name2@domain.com,,,,,,,,,,Personal,name3@domain.com; name4@domain.com; name5@domain.com; name6@domain.com,,17471234567,5551234567,,,,,,\r
+First1 Last,,"Categories: Friends\r
+",Personal,,,,5557654321,,,,,,\r
--- /dev/null
+Name,E-mail Address,Categories,Company,Job Title,Home Address,Home Phone,Mobile Phone,Business Phone,GrandCentral,Suffix,Title,Initials,Web Page,Notes\r
+First Last,,Family,,,1234567 Foo St Austn Tx 78727,5559983254,5554023626,5559988899,,,,,,\r
+First1 Last,,Others,,,,5556835460,,,,,,,,\r
--- /dev/null
+from __future__ import with_statement
+
+import os
+import warnings
+
+import test_utils
+
+import sys
+sys.path.append("../src")
+
+import file_backend
+
+
+def test_factory():
+ warnings.simplefilter("always")
+ try:
+ csvPath = os.path.join(os.path.dirname(__file__), "basic_data")
+ factory = file_backend.FilesystemAddressBookFactory(csvPath)
+ assert factory.factory_name() == "File"
+ abooks = list(factory.get_addressbooks())
+ abooks.sort()
+ assert len(abooks) == 4
+ abookNames = [abook[2] for abook in abooks]
+ assert abookNames == ["basic", "empty", "google", "grandcentral"], "%s" % abookNames
+
+ for abook_factory, abookId, abookName in abooks:
+ abook = abook_factory.open_addressbook(abookId)
+ assert isinstance(abook, file_backend.CsvAddressBook)
+ finally:
+ warnings.resetwarnings()
+
+
+def test_nonexistent_csv():
+ warnings.simplefilter("always")
+ try:
+ csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "nonexistent.csv")
+ abook = file_backend.CsvAddressBook(csvPath)
+
+ assert abook.factory_name() == "csv"
+
+ contacts = list(abook.get_contacts())
+ assert len(contacts) == 0
+ finally:
+ warnings.resetwarnings()
+
+
+def test_empty_csv():
+ warnings.simplefilter("always")
+ try:
+ csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "empty.csv")
+ abook = file_backend.CsvAddressBook(csvPath)
+
+ assert abook.factory_name() == "csv"
+
+ contacts = list(abook.get_contacts())
+ assert len(contacts) == 0
+ finally:
+ warnings.resetwarnings()
+
+
+def test_basic_csv():
+ warnings.simplefilter("always")
+ try:
+ csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "basic.csv")
+ abook = file_backend.CsvAddressBook(csvPath)
+
+ assert abook.factory_name() == "csv"
+
+ contacts = list(abook.get_contacts())
+ contacts.sort()
+ assert len(contacts) == 1
+
+ contactId, contactName = contacts[0]
+ assert contactName == "Last, First"
+ assert abook.contact_source_short_name(contactId) == "csv"
+
+ details = list(abook.get_contact_details(contactId))
+ assert len(details) == 1
+ details.sort()
+ assert details == [("phone", "555-123-4567")], "%s" % details
+ finally:
+ warnings.resetwarnings()
+
+
+def test_google_csv():
+ warnings.simplefilter("always")
+ try:
+ csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "google.csv")
+ abook = file_backend.CsvAddressBook(csvPath)
+
+ assert abook.factory_name() == "csv"
+
+ contacts = list(abook.get_contacts())
+ contacts.sort()
+ assert len(contacts) == 2
+
+ contactId, contactName = contacts[0]
+ assert contactName == "First Last"
+ assert abook.contact_source_short_name(contactId) == "csv"
+
+ details = list(abook.get_contact_details(contactId))
+ assert len(details) == 2
+ details.sort()
+ assert details == [
+ ("Section 2 - Mobile", "5551234567"),
+ ("Section 2 - Phone", "17471234567"),
+ ], "%s" % details
+
+ contactId, contactName = contacts[1]
+ assert contactName == "First1 Last"
+ assert abook.contact_source_short_name(contactId) == "csv"
+
+ details = list(abook.get_contact_details(contactId))
+ assert len(details) == 1
+ details.sort()
+ assert details == [("Section 1 - Mobile", "5557654321")], "%s" % details
+ finally:
+ warnings.resetwarnings()
+
+
+def test_grandcentral_csv():
+ warnings.simplefilter("always")
+ try:
+ csvPath = os.path.join(os.path.dirname(__file__), "basic_data", "grandcentral.csv")
+ abook = file_backend.CsvAddressBook(csvPath)
+
+ assert abook.factory_name() == "csv"
+
+ contacts = list(abook.get_contacts())
+ contacts.sort()
+ assert len(contacts) == 2
+
+ contactId, contactName = contacts[0]
+ assert contactName == "First Last"
+ assert abook.contact_source_short_name(contactId) == "csv"
+
+ details = list(abook.get_contact_details(contactId))
+ assert len(details) == 3
+ details.sort()
+ assert details == [
+ ("Business Phone", "5559988899"),
+ ("Home Phone", "5559983254"),
+ ("Mobile Phone", "5554023626"),
+ ], "%s" % details
+
+ contactId, contactName = contacts[1]
+ assert contactName == "First1 Last"
+ assert abook.contact_source_short_name(contactId) == "csv"
+
+ details = list(abook.get_contact_details(contactId))
+ assert len(details) == 1
+ details.sort()
+ assert details == [("Home Phone", "5556835460")], "%s" % details
+ finally:
+ warnings.resetwarnings()
import os
import time
+import warnings
import test_utils
del handle
-def test_startup_with_no_data_dir_with_dummy_hildon():
+def atest_startup_with_no_data_dir_with_dummy_hildon():
+ warnings.simplefilter("always")
hildonPath = os.path.join(os.path.dirname(__file__), "dummy_hildon")
sys.path.insert(0, hildonPath)
import hildon
finally:
dc_glade.hildon = None
sys.path.remove(hildonPath)
+ warnings.resetwarnings()
-def test_startup_with_no_data_dir():
+def atest_startup_with_no_data_dir():
+ warnings.simplefilter("always")
dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "notexistent_data")
dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
os.removedirs(dc_glade.Dialcentral._data_path)
except:
pass
+ warnings.resetwarnings()
-def test_startup_with_empty_data_dir():
+def atest_startup_with_empty_data_dir():
+ warnings.simplefilter("always")
dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "empty_data")
dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
os.removedirs(dc_glade.Dialcentral._data_path)
except:
pass
+ warnings.resetwarnings()
-def test_startup_with_basic_data_dir():
- dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "basic_data")
- dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
+def atest_startup_with_basic_data_dir():
+ warnings.simplefilter("always")
+ try:
+ dc_glade.Dialcentral._data_path = os.path.join(os.path.dirname(__file__), "basic_data")
+ dc_glade.Dialcentral._user_settings = "%s/settings.ini" % dc_glade.Dialcentral._data_path
- startup(dc_glade.Dialcentral)
+ startup(dc_glade.Dialcentral)
+ finally:
+ warnings.resetwarnings()