diff --git a/gramps/gen/lib/test/__init__.py b/gramps/gen/lib/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gramps/gen/lib/test/grampstype_test.py b/gramps/gen/lib/test/grampstype_test.py index 68bc7f8f1..bda3e78e2 100644 --- a/gramps/gen/lib/test/grampstype_test.py +++ b/gramps/gen/lib/test/grampstype_test.py @@ -18,25 +18,23 @@ # 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() keys = list(range(len(vals))) -MAP = [ (k,v*2,v) for (k,v) in zip(keys, vals) ] +MAP = [(k, v*2, v) for (k, v) in zip(keys, vals)] BLIST= [1,3] class GT0(GrampsType): - _DEFAULT = 1 # just avoiding the pre-coded 0 - _CUSTOM = 3 # just avoiding the pre-coded 0 + _DEFAULT = 1 # just avoiding the pre-coded 0 + _CUSTOM = 3 # just avoiding the pre-coded 0 _DATAMAP = MAP # NOTE: this type of code might be used in a migration utility @@ -47,60 +45,55 @@ class GT1(GT0): _BLACKLIST = BLIST class GT2(GT1): - _BLACKLIST=None - -class Test1(U.TestCase): + _BLACKLIST = None +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")) + e = len(keys) + 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): - for i,v,u in ( - (None, 1,''), # all DEFAULT - (0, 0,''), - (1, 1,''), - ('efef', 3,'efef'), # matches CUSTOM - ('zzzz', 0,''), - ('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 + def test_init_value(self): + for i, v, u in ( + (None, 1, 'abab'), # all DEFAULT + (0, 0, 'zzzz'), + (1, 1, 'abab'), + ('efef', 3, 'efef'), # matches CUSTOM + ('zzzz', 0, 'zzzz'), + ('x', 3, 'x'), # nomatch gives CUSTOM + ('', 3, ''), # nomatch gives CUSTOM + ((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")) + e = len(keys) - len(BLIST) + 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")) - + e = len(keys) + g = len(self.ub._E2IMAP) + self.assertEqual(g, e) if __name__ == "__main__": - U.main() - + unittest.main() diff --git a/gramps/gen/lib/test/merge_test.py b/gramps/gen/lib/test/merge_test.py index d55589ef2..5483f2fd6 100644 --- a/gramps/gen/lib/test/merge_test.py +++ b/gramps/gen/lib/test/merge_test.py @@ -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, diff --git a/gramps/gen/utils/test/__init__.py b/gramps/gen/utils/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gramps/gen/utils/test/callback_test.py b/gramps/gen/utils/test/callback_test.py index 198a6e9df..1684c4a1e 100644 --- a/gramps/gen/utils/test/callback_test.py +++ b/gramps/gen/utils/test/callback_test.py @@ -23,9 +23,6 @@ import unittest -from test import test_util as tu -tu.path_append_parent() - from ..callback import Callback try: diff --git a/gramps/plugins/export/test/__init__.py b/gramps/plugins/export/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gramps/plugins/export/test/exportvcard_test.py b/gramps/plugins/export/test/exportvcard_test.py index d0427cb02..2a0ca4c14 100644 --- a/gramps/plugins/export/test/exportvcard_test.py +++ b/gramps/plugins/export/test/exportvcard_test.py @@ -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): diff --git a/gramps/plugins/importer/test/__init__.py b/gramps/plugins/importer/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gramps/plugins/importer/test/importvcard_test.py b/gramps/plugins/importer/test/importvcard_test.py index 9d3555630..1278e90f8 100644 --- a/gramps/plugins/importer/test/importvcard_test.py +++ b/gramps/plugins/importer/test/importvcard_test.py @@ -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):
- + \n
""" % \ (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")