Fix unit tests

svn: r22753
This commit is contained in:
Nick Hall 2013-07-28 15:04:26 +00:00
parent d6c870fde6
commit b2b4da2d37
9 changed files with 63 additions and 82 deletions

View File

View File

@ -18,15 +18,13 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# gen/lib/test/grampstype_test.py
# $Id$
""" unittest for grampstype """
import unittest as U
import unittest
from test.test_util import msg
from ..grampstype import GrampsType, _init_map
from ..grampstype import GrampsType
# some simple map items to test with
vals = "zz ab cd ef".split()
@ -49,58 +47,53 @@ class GT1(GT0):
class GT2(GT1):
_BLACKLIST = None
class Test1(U.TestCase):
class Test1(unittest.TestCase):
# some basic tests
def test1a_basic(s):
s.gt=GT0()
s.assertTrue(isinstance(s.gt, GrampsType))
def test_basic(self):
self.gt = GT0()
self.assertTrue(isinstance(self.gt, GrampsType))
# spot-check that MAPs get built
e = len(keys)
g= len(s.gt._E2IMAP)
s.assertEquals(g,e, msg(g,e, "expected length of E2IMAP"))
g = len(self.gt._E2IMAP)
self.assertEqual(g, e)
# init sets values for int, str, tuple
# (we ignore instance here -- maybe SB tested, too?)
# this test depends on having _DEFAULT=1, _CUSTOM=3
# NB: tuple tests w/ lengths < 2 fail before release 10403
def test1b_init_value(s):
def test_init_value(self):
for i, v, u in (
(None, 1,''), # all DEFAULT
(0, 0,''),
(1, 1,''),
(None, 1, 'abab'), # all DEFAULT
(0, 0, 'zzzz'),
(1, 1, 'abab'),
('efef', 3, 'efef'), # matches CUSTOM
('zzzz', 0,''),
('zzzz', 0, 'zzzz'),
('x', 3, 'x'), # nomatch gives CUSTOM
('', 3, ''), # nomatch gives CUSTOM
((0,'zero'), 0,'zero'), # normal behavior
((2,), 2,''), # DEFAULT-string, just like int
((), 1,''), # DEFAULT-pair
((0,'zero'), 0, 'zzzz'), # normal behavior
((2,), 2, 'cdcd'), # DEFAULT-string, just like int
((), 1, 'abab'), # DEFAULT-pair
):
s.gt = GT0(i)
g= s.gt.val
s.assertEquals(g,v,
msg(g,v, "initialization val from '%s'" % repr(i)))
g= s.gt.string
s.assertEquals(g,u,
msg(g,u, "initialization string from '%s'" % repr(i)))
self.gt = GT0(i)
g = self.gt.value
self.assertEqual(g, v)
g = self.gt.string
self.assertEqual(g, u)
# test blacklist functionality added to enable fix of bug #1680
class Test2(U.TestCase):
def test2a_blacklist(s):
s.gt=GT1()
class Test2(unittest.TestCase):
def test_blacklist(self):
self.gt = GT1()
# check that MAPs have lengths reduced by blacklist
e = len(keys) - len(BLIST)
g= len(s.gt._E2IMAP)
s.assertEquals(g,e, msg(g,e, "expected length of blacklisted MAP"))
g = len(self.gt._E2IMAP)
self.assertEqual(g, e)
s.ub=GT2()
self.ub=GT2()
# check that these MAPS are now un-blacklisted
e = len(keys)
g= len(s.ub._E2IMAP)
s.assertEquals(g,e, msg(g,e, "expected length of un-blacklisted MAP"))
g = len(self.ub._E2IMAP)
self.assertEqual(g, e)
if __name__ == "__main__":
U.main()
unittest.main()

View File

@ -23,12 +23,9 @@
""" Unittest that tests the code involved in merging """
import unittest
import sys
import os
sys.path.append(os.curdir)
from .. import (Person, Surname, Name, NameType, Family, FamilyRelType,
Event, EventType, Source, Place, Citation,
Event, EventType, Source, Place, Citation, Date,
Repository, RepositoryType, MediaObject, Note, NoteType,
StyledText, StyledTextTag, StyledTextTagType, Tag,
ChildRef, ChildRefType, Attribute, MediaRef, AttributeType,

View File

View File

@ -23,9 +23,6 @@
import unittest
from test import test_util as tu
tu.path_append_parent()
from ..callback import Callback
try:

View File

View File

@ -25,23 +25,20 @@ Unittest for export to VCard
To be called from src directory.
"""
from __future__ import print_function
import unittest
import sys
import os
if sys.version_info[0] < 3:
from StringIO import StringIO
else:
from io import StringIO
import time
sys.path.append(os.curdir)
sys.path.append(os.path.join(os.curdir, 'plugins', 'export'))
sys.path.append(os.path.join(os.curdir, 'plugins', 'lib'))
import subprocess
import libxml2
from gramps.plugins.lib.libgrampsxml import GRAMPS_XML_VERSION
from gramps.version import VERSION
import exportvcard
from gramps.plugins.export.exportvcard import VCardWriter
class VCardCheck(unittest.TestCase):
def setUp(self):
@ -80,7 +77,7 @@ class VCardCheck(unittest.TestCase):
if debug:
print(input_strfile.getvalue())
process = subprocess.Popen('python gramps.py -i - -f gramps -e - -f vcf',
process = subprocess.Popen('python Gramps.py -i - -f gramps -e - -f vcf',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
result_str, err_str = process.communicate(input_strfile.getvalue())
if err_str:
@ -95,20 +92,20 @@ class VCardCheck(unittest.TestCase):
"\r\n".join(self.expect) + '\r\n\r\n')
def test_esc_string_none(self):
self.assertEqual(ExportVCard.VCardWriter.esc("nothing"), "nothing")
self.assertEqual(VCardWriter.esc("nothing"), "nothing")
def test_esc_string_all(self):
self.assertEqual(ExportVCard.VCardWriter.esc("backslash\\_comma,_semicolon;"),
self.assertEqual(VCardWriter.esc("backslash\\_comma,_semicolon;"),
"backslash\\\\_comma\\,_semicolon\\;")
def test_esc_string_list(self):
self.assertEqual(ExportVCard.VCardWriter.esc(["comma,", "semicolon;"]),["comma\\,", "semicolon\\;"])
self.assertEqual(VCardWriter.esc(["comma,", "semicolon;"]),["comma\\,", "semicolon\\;"])
def test_esc_string_tuple(self):
self.assertEqual(ExportVCard.VCardWriter.esc(("comma,", "semicolon;")),("comma\\,", "semicolon\\;"))
self.assertEqual(VCardWriter.esc(("comma,", "semicolon;")),("comma\\,", "semicolon\\;"))
def test_esc_string_wrongtype(self):
self.assertRaises(TypeError, ExportVCard.VCardWriter.esc,
self.assertRaises(TypeError, VCardWriter.esc,
{"comma,":"semicolon;"})
def test_write_formatted_name_title(self):

View File

View File

@ -37,18 +37,15 @@ else:
from io import StringIO
import time
import unittest
sys.path.append(os.curdir)
sys.path.append(os.path.join(os.curdir, 'plugins','import'))
sys.path.append(os.path.join(os.curdir, 'plugins', 'lib'))
import subprocess
import libxml2
import libxslt
from gramps.plugins.lib.libgrampsxml import GRAMPS_XML_VERSION
from gramps.gen.const import ROOT_DIR, VERSION
import importvcard
from importvcard import VCardParser
from gramps.gen.const import ROOT_DIR
from gramps.version import VERSION
from gramps.plugins.importer.importvcard import (VCardParser, fitin,
splitof_nameprefix)
class VCardCheck(unittest.TestCase):
def setUp(self):
@ -63,7 +60,7 @@ class VCardCheck(unittest.TestCase):
<database xmlns="http://gramps-project.org/xml/%s/">
<header>
<created date="%04d-%02d-%02d" version="%s"/>
<researcher/>
<researcher>\n </researcher>
</header>""" % \
(GRAMPS_XML_VERSION, GRAMPS_XML_VERSION, GRAMPS_XML_VERSION,
date[0], date[1], date[2], VERSION)
@ -100,7 +97,7 @@ class VCardCheck(unittest.TestCase):
buf = libxml2.createOutputBuffer(expect_canonical_strfile, 'UTF-8')
self.string2canonicalxml(expect_str, buf)
process = subprocess.Popen('python gramps.py '
process = subprocess.Popen('python Gramps.py '
'--config=preferences.eprefix:DEFAULT -i - -f vcf -e - -f gramps',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
result_str, err_str = process.communicate(input_str)
@ -122,26 +119,26 @@ class VCardCheck(unittest.TestCase):
self.do_test("\r\n".join(self.vcard), self.gramps)
def test_splitof_nameprefix_noprefix(self):
self.assertEqual(ImportVCard.splitof_nameprefix("Noprefix"), ('',"Noprefix"))
self.assertEqual(splitof_nameprefix("Noprefix"), ('',"Noprefix"))
def test_splitof_nameprefix_prefix(self):
self.assertEqual(ImportVCard.splitof_nameprefix("van Prefix"), ('van',"Prefix"))
self.assertEqual(splitof_nameprefix("van Prefix"), ('van',"Prefix"))
def test_splitof_nameprefix_doublespace(self):
self.assertEqual(ImportVCard.splitof_nameprefix("van Prefix"), ('van',"Prefix"))
self.assertEqual(splitof_nameprefix("van Prefix"), ('van',"Prefix"))
def test_fitin_regular(self):
self.assertEqual(ImportVCard.fitin("Mr. Gaius Julius Caesar",
self.assertEqual(fitin("Mr. Gaius Julius Caesar",
"Gaius Caesar", "Julius"), 6)
def test_fitin_wrong_receiver(self):
self.assertEqual(ImportVCard.fitin("A B C", "A D", "B"), -1)
self.assertEqual(fitin("A B C", "A D", "B"), -1)
def test_fitin_wrong_element(self):
self.assertRaises(ValueError, ImportVCard.fitin, "A B C", "A C", "D")
self.assertRaises(ValueError, fitin, "A B C", "A C", "D")
def test_fitin_last_element(self):
self.assertRaises(IndexError, ImportVCard.fitin, "A B C", "A B", "C")
self.assertRaises(IndexError, fitin, "A B C", "A B", "C")
def test_name_value_split_begin_colon(self):
self.vcard.insert(4, ":email@example.com")