Fix for Windows line separator

svn: r22819
This commit is contained in:
Nick Hall 2013-08-08 12:45:23 +00:00
parent fe258bf600
commit 66166c2acc

View File

@ -27,6 +27,7 @@ from __future__ import print_function
import unittest
import time
import subprocess
import os
import xml.etree.ElementTree as ET
from ...lib.libgrampsxml import GRAMPS_XML_VERSION
@ -81,6 +82,10 @@ class VCardCheck(unittest.TestCase):
input_str = (self.header.encode('utf-8') +
ET.tostring(input_doc, encoding='utf-8'))
result_str, err_str = process.communicate(input_str)
separator = '\r' + os.linesep
expect_str = separator.join(expect_str) + (separator * 2)
if debug:
print(err_str)
print(result_str)
@ -89,7 +94,7 @@ class VCardCheck(unittest.TestCase):
def test_base(self):
self.do_test(self.database,
"\r\n".join(self.expect) + '\r\n\r\n')
self.expect)
def test_esc_string_none(self):
self.assertEqual(VCardWriter.esc("nothing"), "nothing")
@ -114,7 +119,7 @@ class VCardCheck(unittest.TestCase):
ET.SubElement(self.name, "title").text = 'Sir.'
self.expect[3] = "FN:Sir. Lastname"
self.expect[4] = "N:Lastname;;;Sir.;"
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_name_multiple_surname(self):
self.lastname.text = "Oranje"
@ -123,7 +128,7 @@ class VCardCheck(unittest.TestCase):
self.expect[3] = "FN:van Oranje Nassau"
self.expect[4] = "N:van Oranje,Nassau;;;;"
self.expect[5] = "SORT-STRING:" + "Oranje".ljust(55)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_name_callname(self):
# callname not in first names!
@ -132,7 +137,7 @@ class VCardCheck(unittest.TestCase):
self.expect[3] = "FN:B C Lastname"
self.expect[4] = "N:Lastname;A;B,C;;"
self.expect[5] = "SORT-STRING:" + "Lastname".ljust(25) + "B C".ljust(30)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_name_callname_in_addnames(self):
ET.SubElement(self.name, "first").text = "A B C"
@ -140,35 +145,35 @@ class VCardCheck(unittest.TestCase):
self.expect[3] = "FN:A B C Lastname"
self.expect[4] = "N:Lastname;B;A,C;;"
self.expect[5] = "SORT-STRING:" + "Lastname".ljust(25) + "A B C".ljust(30)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_name_no_callname(self):
ET.SubElement(self.name, "first").text = "A B C"
self.expect[3] = "FN:A B C Lastname"
self.expect[4] = "N:Lastname;A;B,C;;"
self.expect[5] = "SORT-STRING:" + "Lastname".ljust(25) + "A B C".ljust(30)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_name_no_additional_names(self):
ET.SubElement(self.name, "first").text = "A"
self.expect[3] = "FN:A Lastname"
self.expect[4] = "N:Lastname;A;;;"
self.expect[5] = "SORT-STRING:" + "Lastname".ljust(25) + "A".ljust(30)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_name_honprefix(self):
ET.SubElement(self.name, "title").text = "Sir"
self.expect[3] = "FN:Sir Lastname"
self.expect[4] = "N:Lastname;;;Sir;"
self.expect[5] = "SORT-STRING:" + "Lastname".ljust(55)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_name_honsuffix(self):
ET.SubElement(self.name, "suffix").text = "Jr."
self.expect[3] = "FN:Lastname\, Jr."
self.expect[4] = "N:Lastname;;;;Jr."
self.expect[5] = "SORT-STRING:" + "Lastname".ljust(55)+ "Jr."
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_nicknames_regular(self):
@ -178,7 +183,7 @@ class VCardCheck(unittest.TestCase):
name = ET.SubElement(self.person, "name", attrib=attribs)
ET.SubElement(name, 'nick').text = 'N.'
self.expect.insert(6, "NICKNAME:Nick,N.")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_nicknames_primary_nick(self):
ET.SubElement(self.name, 'nick').text = 'Nick'
@ -186,7 +191,7 @@ class VCardCheck(unittest.TestCase):
name = ET.SubElement(self.person, "name", attrib=attribs)
ET.SubElement(name, 'nick').text = 'N.'
self.expect.insert(6, "NICKNAME:Nick,N.")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_birthdate_regular(self):
events = ET.Element('events')
@ -198,7 +203,7 @@ class VCardCheck(unittest.TestCase):
attribs = {'hlink': '_e0000', 'role': 'Primary'}
ET.SubElement(self.person, 'eventref', attrib=attribs)
self.expect.insert(6, "BDAY:2001-02-28")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_birthdate_empty(self):
events = ET.Element('events')
@ -208,7 +213,7 @@ class VCardCheck(unittest.TestCase):
ET.SubElement(event, 'type').text = 'Birth'
attribs = {'hlink': '_e0000', 'role': 'Primary'}
ET.SubElement(self.person, 'eventref', attrib=attribs)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_birhtdate_textonly(self):
events = ET.Element('events')
@ -219,7 +224,7 @@ class VCardCheck(unittest.TestCase):
ET.SubElement(event, 'dateval', val='Christmas 2001')
attribs = {'hlink': '_e0000', 'role': 'Primary'}
ET.SubElement(self.person, 'eventref', attrib=attribs)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_birthdate_span(self):
events = ET.Element('events')
@ -231,7 +236,7 @@ class VCardCheck(unittest.TestCase):
ET.SubElement(event, 'datespan', attrib=attribs)
attribs = {'hlink': '_e0000', 'role': 'Primary'}
ET.SubElement(self.person, 'eventref', attrib=attribs)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_birthdate_range(self):
events = ET.Element('events')
@ -243,7 +248,7 @@ class VCardCheck(unittest.TestCase):
ET.SubElement(event, 'daterange', attrib=attribs)
attribs = {'hlink': '_e0000', 'role': 'Primary'}
ET.SubElement(self.person, 'eventref', attrib=attribs)
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_addresses_regular(self):
address = ET.SubElement(self.person, 'address')
@ -253,31 +258,31 @@ class VCardCheck(unittest.TestCase):
ET.SubElement(address, 'state').text = 'province'
ET.SubElement(address, 'postal').text = 'zip'
self.expect.insert(6, "ADR:;;pobox bis street;place;province;zip;country")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_addresses_phone(self):
address = ET.SubElement(self.person, 'address')
ET.SubElement(address, 'phone').text = '01234-56789'
self.expect.insert(6, "TEL:01234-56789")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_urls_email(self):
attribs = {'type': 'E-mail', 'href': 'me@example.com'}
ET.SubElement(self.person, 'url', attrib=attribs)
self.expect.insert(6, "EMAIL:me@example.com")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_urls_emial_mailto(self):
attribs = {'type': 'E-mail', 'href': 'mailto:me@example.com'}
ET.SubElement(self.person, 'url', attrib=attribs)
self.expect.insert(6, "EMAIL:me@example.com")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_urls_url(self):
attribs = {'type': 'Web Home', 'href': 'http://www.example.org'}
ET.SubElement(self.person, 'url', attrib=attribs)
self.expect.insert(6, "URL:http://www.example.org")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_occupation_regular(self):
events = ET.Element('events')
@ -289,7 +294,7 @@ class VCardCheck(unittest.TestCase):
attribs = {'hlink': '_e0000', 'role': 'Primary'}
ET.SubElement(self.person, 'eventref', attrib=attribs)
self.expect.insert(6, "ROLE:carpenter")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
def test_write_occupation_lastdate(self):
events = ET.Element('events')
@ -309,7 +314,7 @@ class VCardCheck(unittest.TestCase):
attribs = {'hlink': '_e0001', 'role': 'Primary'}
ET.SubElement(self.person, 'eventref', attrib=attribs)
self.expect.insert(6, "ROLE:foreman")
self.do_test(self.database, "\r\n".join(self.expect) + '\r\n\r\n')
self.do_test(self.database, self.expect)
if __name__ == "__main__":
unittest.main()