2008-01-09 Raphael Ackermann <raphael.ackermann@gmail.com> From PEP8 Always use 'self' for the first argument to instance methods.
svn: r9767
This commit is contained in:
		
							
								
								
									
										13
									
								
								ChangeLog
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								ChangeLog
									
									
									
									
									
								
							| @@ -1,3 +1,16 @@ | ||||
| 2008-01-09 Raphael Ackermann <raphael.ackermann@gmail.com> | ||||
|     * src/gen/utils/callback.py | ||||
|     * src/ObjectSelector/_FamilyFilterFrame.py | ||||
|     * src/test/test/test_util_test.py | ||||
|     * src/test/test/gedread_util_test.py | ||||
|     * src/test/test_util.py | ||||
|     * src/test/gramps_cli_test.py | ||||
|     * src/test/ansel_utf8_test.py | ||||
|     * src/GrampsDbUtils/test/_GedcomChar_test.py | ||||
|     * src/GrampsDbUtils/test/_GrampsDbWRFactories_test.py | ||||
|     * src/GrampsDbUtils/test/GR_test.py | ||||
|     From PEP8 Always use 'self' for the first argument to instance methods. | ||||
|  | ||||
| 2008-01-09 Raphael Ackermann <raphael.ackermann@gmail.com> | ||||
|     * src/plugins/ExportVCard.py: in write_person use b_date instead of date | ||||
|     0001497: small typo and imports cleanup in ExportVCard.py | ||||
|   | ||||
| @@ -58,28 +58,28 @@ class nc(): | ||||
|  | ||||
|     NB: name _must_ match the X names in db get_number_of_X | ||||
|     """ | ||||
|     def dbncheck(s, dbcall): | ||||
|     def dbncheck(self, dbcall): | ||||
|         err = None | ||||
|         got = dbcall() | ||||
|         if not got == s.num: | ||||
|             err = "%s: got %d, expected %d" % (s.name, got, s.num) | ||||
|         if not got == self.num: | ||||
|             err = "%s: got %d, expected %d" % (self.name, got, self.num) | ||||
|         return err     | ||||
|     def __init__(s, name, num): | ||||
|         s.name = name | ||||
|         s.num = num | ||||
|         s.getname = "get_number_of_" + name        | ||||
|     def __call__(s, db): | ||||
|         dbcall = getattr(db,s.getname) | ||||
|         s.dbncheck(dbcall) | ||||
|     def __init__(self, name, num): | ||||
|         self.name = name | ||||
|         self.num = num | ||||
|         self.getname = "get_number_of_" + name        | ||||
|     def __call__(self, db): | ||||
|         dbcall = getattr(db,self.getname) | ||||
|         self.dbncheck(dbcall) | ||||
|  | ||||
| class fnci(): | ||||
|     """fnci (frag-numcheckset item) is a data container for: | ||||
|     a fragment of gedcom  | ||||
|     a sequence of nc items to check | ||||
|     """ | ||||
|     def __init__(s, frag, ncset): | ||||
|         s.frag = frag | ||||
|         s.ncset = ncset | ||||
|     def __init__(self, frag, ncset): | ||||
|         self.frag = frag | ||||
|         self.ncset = ncset | ||||
|  | ||||
| # test data table for Test1.test1a_numchecks | ||||
| fnumchecks = ( | ||||
| @@ -119,28 +119,28 @@ def _checklog(tlogger, pat=None): | ||||
|  | ||||
|  | ||||
| class Test1(U.TestCase): | ||||
|     def setUp(s): | ||||
|     def setUp(self): | ||||
|         # make a test subdir and compose some pathnames | ||||
|         s.tdir = tu.make_subdir("RG_test") | ||||
|         s.tdb = op.join(s.tdir,"test_db") | ||||
|         s.ifil = op.join(s.tdir,"test_in.ged") | ||||
|         s.lfil = op.join(s.tdir,"test.log") | ||||
|         self.tdir = tu.make_subdir("RG_test") | ||||
|         self.tdb = op.join(self.tdir,"test_db") | ||||
|         self.ifil = op.join(self.tdir,"test_in.ged") | ||||
|         self.lfil = op.join(self.tdir,"test.log") | ||||
|  | ||||
|     def test1a_numchecks(s): | ||||
|     def test1a_numchecks(self): | ||||
|         tl = tu.TestLogger() | ||||
|         for i,f in enumerate(fnumchecks): | ||||
|             gr.make_gedcom_input(s.ifil, f.frag) | ||||
|             db = gr.create_empty_db(s.tdb) | ||||
|             tl.logfile_init(s.lfil) | ||||
|             gr.gread(db,s.ifil) | ||||
|             gr.make_gedcom_input(self.ifil, f.frag) | ||||
|             db = gr.create_empty_db(self.tdb) | ||||
|             tl.logfile_init(self.lfil) | ||||
|             gr.gread(db,self.ifil) | ||||
|             errs = _checklog(tl, r"Line \d+") | ||||
|             s.assertEquals(errs, 0, | ||||
|             self.assertEquals(errs, 0, | ||||
|                 "ncset(%d): got %d unexpected log messages" % | ||||
|                 (i,errs)) | ||||
|             # ok, no log error message, check db counts | ||||
|             for call in f.ncset: | ||||
|                 err = call(db) | ||||
|                 s.assertFalse(err, err) | ||||
|                 self.assertFalse(err, err) | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     U.main() | ||||
|   | ||||
| @@ -40,22 +40,22 @@ class Test1_ansi(unittest.TestCase): | ||||
|     fil = os.path.join(cdir,enc) | ||||
|     exp  = utest_chars | ||||
|      | ||||
|     def setUp(s): | ||||
|         gen_chars(s.fil, s.enc) | ||||
|     def setUp(self): | ||||
|         gen_chars(self.fil, self.enc) | ||||
|  | ||||
|     def test1a_read_ansi(s):         | ||||
|         f = open(s.fil) | ||||
|     def test1a_read_ansi(self):         | ||||
|         f = open(self.fil) | ||||
|         ra= G.AnsiReader(f) | ||||
|         got = ra.readline() | ||||
|         s.assertEquals(got,s.exp, m(got,s.exp, "AnsiReader")) | ||||
|         self.assertEquals(got,self.exp, m(got,self.exp, "AnsiReader")) | ||||
|  | ||||
|     def test1b_read_codec_latin1(s): | ||||
|         got=codecs.open(s.fil, encoding=s.enc).read() | ||||
|         s.assertEquals(got,s.exp, m(got,s.exp, "using codec %s" % s.enc)) | ||||
|     def test1b_read_codec_latin1(self): | ||||
|         got=codecs.open(self.fil, encoding=self.enc).read() | ||||
|         self.assertEquals(got,self.exp, m(got,self.exp, "using codec %s" % self.enc)) | ||||
|  | ||||
|     def test1c_read_codec_cp1252(s): | ||||
|         got=codecs.open(s.fil, encoding=s.cp).read() | ||||
|         s.assertEquals(got,s.exp, m(got,s.exp, "using codec %s" % s.cp)) | ||||
|     def test1c_read_codec_cp1252(self): | ||||
|         got=codecs.open(self.fil, encoding=self.cp).read() | ||||
|         self.assertEquals(got,self.exp, m(got,self.exp, "using codec %s" % self.cp)) | ||||
|  | ||||
| ### | ||||
| class Test2_ansel(unittest.TestCase): | ||||
| @@ -64,14 +64,14 @@ class Test2_ansel(unittest.TestCase): | ||||
|     afil = os.path.join(cdir,enc) | ||||
|     exp  = a2u | ||||
|      | ||||
|     def setUp(s): | ||||
|         open(s.afil, "wb").write(atest_bytes) | ||||
|     def setUp(self): | ||||
|         open(self.afil, "wb").write(atest_bytes) | ||||
|  | ||||
|     def test2a_read_ansel(s): | ||||
|         f = open(s.afil) | ||||
|     def test2a_read_ansel(self): | ||||
|         f = open(self.afil) | ||||
|         ra = G.AnselReader(f) | ||||
|         got = ra.readline() | ||||
|         s.assertEquals(got,s.exp, m(got,s.exp, "AnselReader")) | ||||
|         self.assertEquals(got,self.exp, m(got,self.exp, "AnselReader")) | ||||
|  | ||||
| ### | ||||
| class Test3(unittest.TestCase): | ||||
| @@ -86,35 +86,35 @@ class Test3(unittest.TestCase): | ||||
|     f1byte = os.path.join(cdir, "1byte") | ||||
|     exp  = utest_chars | ||||
|      | ||||
|     def setUp(s): | ||||
|         gen_chars(s.ufil, s.enc) | ||||
|         if not os.path.exists(s.f1byte): | ||||
|             open(s.f1byte, "wb").write("1") | ||||
|     def setUp(self): | ||||
|         gen_chars(self.ufil, self.enc) | ||||
|         if not os.path.exists(self.f1byte): | ||||
|             open(self.f1byte, "wb").write("1") | ||||
|   | ||||
|     def test3a_u8_UTF8Reader_NO_BOM_sig(s): | ||||
|         f=open(s.ufil) | ||||
|     def test3a_u8_UTF8Reader_NO_BOM_sig(self): | ||||
|         f=open(self.ufil) | ||||
|         ra=G.UTF8Reader(f) | ||||
|         g = ra.readline() | ||||
|         s.assertEquals(g,s.exp, m(g,s.exp, "orig UTF8Reader")) | ||||
|         r2 = G.UTF8Reader(open(s.f1byte)) | ||||
|         self.assertEquals(g,self.exp, m(g,self.exp, "orig UTF8Reader")) | ||||
|         r2 = G.UTF8Reader(open(self.f1byte)) | ||||
|         g = r2.readline() | ||||
|         s.assertEquals(g,"1",  | ||||
|         self.assertEquals(g,"1",  | ||||
|             m(g,"1", "read 1-byte file")) | ||||
|    | ||||
|     # NB: utf_8 reads data and never expects a BOM-sig | ||||
|     def test3b_utf8_codec_NO_BOM_sig_as_expected(s): | ||||
|         g=codecs.open(s.ufil, encoding=s.enc).read() | ||||
|         s.assertEquals(g,s.exp, m(g,s.exp, "codec utf8")) | ||||
|         g=codecs.open(s.f1byte, encoding=s.enc).read() | ||||
|         s.assertEquals(g,"1", m(g,"1", "codec utf8")) | ||||
|     def test3b_utf8_codec_NO_BOM_sig_as_expected(self): | ||||
|         g=codecs.open(self.ufil, encoding=self.enc).read() | ||||
|         self.assertEquals(g,self.exp, m(g,self.exp, "codec utf8")) | ||||
|         g=codecs.open(self.f1byte, encoding=self.enc).read() | ||||
|         self.assertEquals(g,"1", m(g,"1", "codec utf8")) | ||||
|    | ||||
|     # NB: utf_8_sig reads data even absent a BOM-sig (GOOD!) | ||||
|     def test3c_utf8_sig_codec_NO_BOM_sig_tolerated_GOOD(s): | ||||
|         g=codecs.open(s.ufil, encoding=s.enc_sig).read() | ||||
|         s.assertEquals(g,s.exp,  | ||||
|             m(g,s.exp, "codec utf_8_sig NO sig input")) | ||||
|         g=codecs.open(s.f1byte, encoding=s.enc_sig).read() | ||||
|         s.assertEquals(g,"1",  | ||||
|     def test3c_utf8_sig_codec_NO_BOM_sig_tolerated_GOOD(self): | ||||
|         g=codecs.open(self.ufil, encoding=self.enc_sig).read() | ||||
|         self.assertEquals(g,self.exp,  | ||||
|             m(g,self.exp, "codec utf_8_sig NO sig input")) | ||||
|         g=codecs.open(self.f1byte, encoding=self.enc_sig).read() | ||||
|         self.assertEquals(g,"1",  | ||||
|             m(g,"1", "codec utf_8_sig NO sig input")) | ||||
|  | ||||
| ### | ||||
| @@ -127,32 +127,32 @@ class Test4(unittest.TestCase): | ||||
|     ufil = os.path.join(cdir, "chars.utf8_sig") | ||||
|     exp  = utest_chars | ||||
|      | ||||
|     def setUp(s): | ||||
|         gen_chars(s.ufil, s.enc_sig) | ||||
|     def setUp(self): | ||||
|         gen_chars(self.ufil, self.enc_sig) | ||||
|   | ||||
|     def test4a_u8_UTF8Reader_WITH_BOM_sig(s): | ||||
|         f=open(s.ufil) | ||||
|     def test4a_u8_UTF8Reader_WITH_BOM_sig(self): | ||||
|         f=open(self.ufil) | ||||
|         ra=G.UTF8Reader(f) | ||||
|         g = ra.readline() | ||||
|         s.assertEquals(g,s.exp, m(g,s.exp, "orig UTF8Reader")) | ||||
|         self.assertEquals(g,self.exp, m(g,self.exp, "orig UTF8Reader")) | ||||
|     | ||||
|     # utf_8 reads an initial BOM-sig as data -- oops, pity | ||||
|     #  write the test to verify this known codec behavior  | ||||
|     # ==> Recommend: do not use utf8 as input codec (use utf_8_sig) | ||||
|     def test4b_utf8_codec_WITH_BOM_sig_reads_as_data_PITY(s): | ||||
|         g=codecs.open(s.ufil, encoding=s.enc).read() | ||||
|     def test4b_utf8_codec_WITH_BOM_sig_reads_as_data_PITY(self): | ||||
|         g=codecs.open(self.ufil, encoding=self.enc).read() | ||||
|         e0=u'\ufeff' | ||||
|         s.assertEquals(g[0], e0,  | ||||
|         self.assertEquals(g[0], e0,  | ||||
|             m(g[0],e0, "codec utf8 reads 'BOM'-sig as data" )) | ||||
|         g = g[1:] | ||||
|         s.assertEquals(g,s.exp,  | ||||
|             m(g,s.exp, "codec utf8 reads rest of data ok")) | ||||
|         self.assertEquals(g,self.exp,  | ||||
|             m(g,self.exp, "codec utf8 reads rest of data ok")) | ||||
|    | ||||
|     # utf_8_sig reads and ignores the BOM-sig | ||||
|     def test4c_utf8_sig_codec_WITH_BOM_sig_as_expected(s): | ||||
|         g=codecs.open(s.ufil, encoding=s.enc_sig).read() | ||||
|         s.assertEquals(g,s.exp,  | ||||
|             m(g,s.exp, "codec utf_8_sig NO sig input")) | ||||
|     def test4c_utf8_sig_codec_WITH_BOM_sig_as_expected(self): | ||||
|         g=codecs.open(self.ufil, encoding=self.enc_sig).read() | ||||
|         self.assertEquals(g,self.exp,  | ||||
|             m(g,self.exp, "codec utf_8_sig NO sig input")) | ||||
|  | ||||
| ### | ||||
|  | ||||
|   | ||||
| @@ -12,9 +12,9 @@ class Test1(unittest.TestCase): | ||||
|     NB: if any test fails, check imports within that module | ||||
|  | ||||
|     """ | ||||
|     def test1a_buried_imports(s): | ||||
|     def test1a_buried_imports(self): | ||||
|         import sys | ||||
|         s.assertTrue(par in sys.path,  | ||||
|         self.assertTrue(par in sys.path,  | ||||
|             "par %r has to be in path!" % par) | ||||
|         ilist = ( | ||||
|             "_WriteGrdb", | ||||
| @@ -28,7 +28,7 @@ class Test1(unittest.TestCase): | ||||
|                 mod = __import__(m) | ||||
|             except ImportError: | ||||
|                 mod = None | ||||
|             s.assertTrue(mod, "try import of module %r" % m) | ||||
|             self.assertTrue(mod, "try import of module %r" % m) | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     unittest.main() | ||||
|   | ||||
| @@ -72,7 +72,7 @@ class FamilyFilterFrame(FilterFrameBase): | ||||
|             self._set_filter(filter_spec) | ||||
|  | ||||
|  | ||||
|     def _set_filter(filter_spec): | ||||
|     def _set_filter(self): | ||||
|         pass | ||||
|      | ||||
|     def on_apply(self,button): | ||||
|   | ||||
| @@ -454,12 +454,12 @@ class GrampsDBCallback(object): | ||||
|     # Class methods | ||||
|     # | ||||
|  | ||||
|     def __disable_all_signals(cls): | ||||
|     def __disable_all_signals(self): | ||||
|         GrampsDBCallback.__BLOCK_ALL_SIGNALS = True | ||||
|  | ||||
|     disable_all_signals = classmethod(__disable_all_signals) | ||||
|      | ||||
|     def __enable_all_signals(cls): | ||||
|     def __enable_all_signals(self): | ||||
|         GrampsDBCallback.__BLOCK_ALL_SIGNALS = False | ||||
|  | ||||
|     enable_all_signals = classmethod(__enable_all_signals) | ||||
|   | ||||
| @@ -169,7 +169,7 @@ class Test4(unittest.TestCase): | ||||
|         self.assertEquals(A.ansel_to_utf8(""), u"", "empty a2u") | ||||
|         self.assertEquals(A.utf8_to_ansel(u""), "", "empty u2a") | ||||
|  | ||||
|     def test4b_unmapped_combos(s): | ||||
|     def test4b_unmapped_combos(self): | ||||
|         """ 4b: (sample) unmapped (non-precomposed) combinations """ | ||||
|         samples = (  | ||||
|             # ansel, unicode, failure-report-message .. see function msg() | ||||
| @@ -181,17 +181,17 @@ class Test4(unittest.TestCase): | ||||
|         for a,u,m in samples: | ||||
|             # ansel to unicode and inverse | ||||
|             a2u=A.ansel_to_utf8(a) | ||||
|             s.assertEquals(a2u, u, msg(a2u, u, m, "a2u")) | ||||
|             self.assertEquals(a2u, u, msg(a2u, u, m, "a2u")) | ||||
|             a2u2a = A.utf8_to_ansel(a2u) | ||||
|             s.assertEquals(a2u2a, a, msg(a2u2a, a, m, "a2u2a")) | ||||
|             self.assertEquals(a2u2a, a, msg(a2u2a, a, m, "a2u2a")) | ||||
|  | ||||
|             # unicode to ansel and inverse | ||||
|             u2a = A.utf8_to_ansel(u) | ||||
|             s.assertEquals(u2a, a, msg(u2a, a, m, "u2a")) | ||||
|             self.assertEquals(u2a, a, msg(u2a, a, m, "u2a")) | ||||
|             u2a2u = A.ansel_to_utf8(u2a) | ||||
|             s.assertEquals(u2a2u, u, msg(u2a2u, u, m, "u2a2u")) | ||||
|             self.assertEquals(u2a2u, u, msg(u2a2u, u, m, "u2a2u")) | ||||
|          | ||||
|     def test4c_multiple_combos(s): | ||||
|     def test4c_multiple_combos(self): | ||||
|         """ 4c: (a2u) ignore multiple combinations (include precomposed) """ | ||||
|         samples = ( | ||||
|             ("b\xF0\xE5Ze", u"bZ\u0304e", "b <cedilla> Z+macron e"), | ||||
| @@ -203,9 +203,9 @@ class Test4(unittest.TestCase): | ||||
|         ) | ||||
|         for a,u,m in samples: | ||||
|             a2u=A.ansel_to_utf8(a) | ||||
|             s.assertEquals(a2u, u, msg(a2u,u,m, "a2u drop extra <combiners>")) | ||||
|             self.assertEquals(a2u, u, msg(a2u,u,m, "a2u drop extra <combiners>")) | ||||
|  | ||||
|     def test4d_multiple_combos(s): | ||||
|     def test4d_multiple_combos(self): | ||||
|         """ 4c: (u2a) ignore multiple combinations (include precomposed) """ | ||||
|         samples = ( | ||||
|             ("b\xE5Ze", u"bZ\u0304\u0327e", "b Z+macron <cedilla> e"), | ||||
| @@ -214,23 +214,23 @@ class Test4(unittest.TestCase): | ||||
|         ) | ||||
|         for a,u,m in samples: | ||||
|             u2a=A.utf8_to_ansel(u) | ||||
|             s.assertEquals(u2a, a, msg(u2a,a,m, "u2a drop extra <combiners>")) | ||||
|             self.assertEquals(u2a, a, msg(u2a,a,m, "u2a drop extra <combiners>")) | ||||
|  | ||||
| class Test99(unittest.TestCase): | ||||
|     """ test regression cases """ | ||||
|      | ||||
|     def test_99a(s): | ||||
|     def test_99a(self): | ||||
|         """ 99a: sanity check on counts """ | ||||
|         n1B= len(A._onebyte) | ||||
|         n2B= len(A._twobyte) | ||||
|         na = n1B+n2B | ||||
|         nu = len(A._utoa) | ||||
|         s.assertEquals(na, nu, msg(na, nu, "basic counts: a2u=u2a")) | ||||
|         self.assertEquals(na, nu, msg(na, nu, "basic counts: a2u=u2a")) | ||||
|         nac = len(A._acombiners) | ||||
|         nuc = len(A._ucombiners) | ||||
|         s.assertEquals(nac, nuc, msg(nac, nuc, "combiner counts: a2u=u2a")) | ||||
|         self.assertEquals(nac, nuc, msg(nac, nuc, "combiner counts: a2u=u2a")) | ||||
|  | ||||
|     def test_99b(s): | ||||
|     def test_99b(self): | ||||
|         """ 99b: fix incorrect mapping for ansel 0xAE | ||||
|          | ||||
|         It used-to-be U+02be but was changed March 2005 to U+02bc | ||||
| @@ -248,7 +248,7 @@ class Test99(unittest.TestCase): | ||||
|         ) | ||||
|         for a, u, m in revs: | ||||
|             g = A.ansel_to_utf8(a) | ||||
|             s.assertEquals(g,u,  | ||||
|             self.assertEquals(g,u,  | ||||
|             msg(g, u, m, "spec change")) | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|   | ||||
| @@ -24,37 +24,37 @@ out_ged = os.path.join(ddir,"test_out.ged") | ||||
|  | ||||
|  | ||||
| class Test(unittest.TestCase): | ||||
|     def setUp(s): | ||||
|     def setUp(self): | ||||
|         if not os.path.exists(min1r): | ||||
|             open(min1r,"wb").write(test_ged) | ||||
|         if os.path.exists(out_ged): | ||||
|             os.remove(out_ged) | ||||
|  | ||||
|     # silly test just to illustrate unittest setUp behavior | ||||
|     def test1_setup_works(s): | ||||
|         s.assertTrue(os.path.exists(ddir), "data dir %r exists" % ddir) | ||||
|         s.assertTrue(os.path.exists(min1r), "data file %r exists" % min1r) | ||||
|         s.assertFalse(os.path.exists(out_ged),  | ||||
|     def test1_setup_works(self): | ||||
|         self.assertTrue(os.path.exists(ddir), "data dir %r exists" % ddir) | ||||
|         self.assertTrue(os.path.exists(min1r), "data file %r exists" % min1r) | ||||
|         self.assertFalse(os.path.exists(out_ged),  | ||||
|             "NO out file %r yet" % out_ged) | ||||
|   | ||||
|     # This tests the fix for bug #1331-1334 | ||||
|     # read trivial gedcom input, write gedcom output | ||||
|     def test2_exec_CLI(s): | ||||
|     def test2_exec_CLI(self): | ||||
|         ifile = min1r | ||||
|         ofile = out_ged | ||||
|         gcmd = "./gramps.py -i%s -o%s" % (ifile, ofile) | ||||
|         rc = os.system("cd %s &&  python %s" % (pdir, gcmd))  | ||||
|         s.assertEquals(rc,0, tu.msg(rc,0, "executed CLI cmmand %r" % gcmd)) | ||||
|         self.assertEquals(rc,0, tu.msg(rc,0, "executed CLI cmmand %r" % gcmd)) | ||||
|         # simple validation o output | ||||
|         s.assertTrue(os.path.isfile(ofile), "output file created") | ||||
|         self.assertTrue(os.path.isfile(ofile), "output file created") | ||||
|         content = open(ofile).read() | ||||
|         g = re.search("INDI", content) | ||||
|         s.assertTrue(g, "found 'INDI' in output file") | ||||
|         self.assertTrue(g, "found 'INDI' in output file") | ||||
|  | ||||
|     # this verifies that files in the temporary "import dir"  | ||||
|     # get cleaned before (and after) running a CLI | ||||
|     # (eg cleanout stale files from prior crash-runs) | ||||
|     def test3_files_in_import_dir(s): | ||||
|     def test3_files_in_import_dir(self): | ||||
|         import const | ||||
|         ddir = os.path.join(const.TEMP_DIR,"import_dbdir") | ||||
|         os.makedirs(ddir) | ||||
| @@ -68,10 +68,10 @@ class Test(unittest.TestCase): | ||||
|         ofile = out_ged | ||||
|         gcmd = "./gramps.py -i%s -o%s" % (ifile, ofile) | ||||
|         rc = os.system("cd %s &&  python %s" % (pdir, gcmd))  | ||||
|         s.assertEquals(rc,0, tu.msg(rc,0, "executed CLI cmmand %r" % gcmd)) | ||||
|         self.assertEquals(rc,0, tu.msg(rc,0, "executed CLI cmmand %r" % gcmd)) | ||||
|  | ||||
|         for fn in bogofiles: | ||||
|             s.assertFalse(os.path.exists(fn)) | ||||
|             self.assertFalse(os.path.exists(fn)) | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|   | ||||
| @@ -12,11 +12,11 @@ from test import gedread_util as gr | ||||
|  | ||||
|  | ||||
| class Test(U.TestCase): | ||||
|     def setUp(s): | ||||
|     def setUp(self): | ||||
|         # make a dir to hold an input gedcom file | ||||
|         s.tdir = tu.make_subdir("gr_test") | ||||
|         self.tdir = tu.make_subdir("gr_test") | ||||
|  | ||||
|     def test1(s): | ||||
|     def test1(self): | ||||
|         prec=""" | ||||
| 0 @I1@ INDI | ||||
| 1 NAME GedRead TEST /Person/ | ||||
| @@ -24,31 +24,31 @@ class Test(U.TestCase): | ||||
|  | ||||
|         # create a gedcom input file | ||||
|         #  from canned head/tail -- see gedread_util | ||||
|         infil = os.path.join(s.tdir,"test_in.ged") | ||||
|         infil = os.path.join(self.tdir,"test_in.ged") | ||||
|         gr.make_gedcom_input(infil, prec) | ||||
|         s.assertTrue(os.path.isfile(infil),  | ||||
|         self.assertTrue(os.path.isfile(infil),  | ||||
|             "create input file %s" % infil) | ||||
|  | ||||
|         # create an empty database | ||||
|         dbpath = os.path.join(s.tdir,"test_db") | ||||
|         dbpath = os.path.join(self.tdir,"test_db") | ||||
|         db = gr.create_empty_db(dbpath) | ||||
|         s.assertTrue(os.path.isdir(dbpath), | ||||
|         self.assertTrue(os.path.isdir(dbpath), | ||||
|             "create database (dir) %s" % dbpath) | ||||
|  | ||||
|         # create logfile to test for read log-messages | ||||
|         # (note: uses recently added test_util  | ||||
|         log = os.path.join(s.tdir, "test_log") | ||||
|         log = os.path.join(self.tdir, "test_log") | ||||
|         tl = tu.TestLogger() | ||||
|         tl.logfile_init(log) | ||||
|         # now read the gedcom | ||||
|         gr.gread(db, infil) | ||||
|         logging.warn("nothing here") | ||||
|         loglines = tl.logfile_getlines() | ||||
|         s.assertEquals(len(loglines),1,  | ||||
|         self.assertEquals(len(loglines),1,  | ||||
|             "log has no unexpected content") | ||||
|         # verify one person in database  | ||||
|         np = db.get_number_of_people() | ||||
|         s.assertEquals(np,1,  | ||||
|         self.assertEquals(np,1,  | ||||
|             tu.msg(np,1, "db has exactly one person")) | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|   | ||||
| @@ -49,39 +49,39 @@ except ImportError: | ||||
|  | ||||
| # some enabling infrastructure features | ||||
| class Test1(U.TestCase): | ||||
|     def test1a_custom_exception(s): | ||||
|     def test1a_custom_exception(self): | ||||
|         tmsg = "testing" | ||||
|         try: | ||||
|             err = None | ||||
|             raise tu.TestError(tmsg) | ||||
|         except tu.TestError,e: | ||||
|             emsg = e.value | ||||
|         s.assertEqual(emsg, tmsg, | ||||
|         self.assertEqual(emsg, tmsg, | ||||
|             "raising TestError: g=%r e=%r" % (emsg, tmsg)) | ||||
|  | ||||
|     def test1b_msg_reporting_utility(s): | ||||
|     def test1b_msg_reporting_utility(self): | ||||
|         g,e = "got this", "expected that" | ||||
|         m,p = "your message here", "pfx" | ||||
|         tmsg0 = m + "\n .....got:'" + g + \ | ||||
|             "'\n expected:'" + e +"'" | ||||
|         tmsg1 = p + ": " + tmsg0 | ||||
|         s.assertEqual(tu.msg(g,e,m), tmsg0, "non-prefix message") | ||||
|         s.assertEqual(tu.msg(g,e,m,p), tmsg1, "prefix message") | ||||
|         self.assertEqual(tu.msg(g,e,m), tmsg0, "non-prefix message") | ||||
|         self.assertEqual(tu.msg(g,e,m,p), tmsg1, "prefix message") | ||||
|  | ||||
|  | ||||
| # path-related features (note use of tu.msg tested above) | ||||
| class Test2(U.TestCase): | ||||
|     def test2a_context_via_traceback(s): | ||||
|     def test2a_context_via_traceback(self): | ||||
|         e = os.path.basename(__file__).rstrip(".co")   # eg in *.py[co] | ||||
|         g = os.path.basename(tu._caller_context()[0]).rstrip('co') | ||||
|         s.assertEqual(g,e, tu.msg(g,e, "_caller_context")) | ||||
|         self.assertEqual(g,e, tu.msg(g,e, "_caller_context")) | ||||
|    | ||||
|     def test2b_absdir(s): | ||||
|     def test2b_absdir(self): | ||||
|         here = tu.absdir(); | ||||
|         g=tu.absdir(__file__) | ||||
|         s.assertEqual(g,here, tu.msg(g,here, "absdir")) | ||||
|         self.assertEqual(g,here, tu.msg(g,here, "absdir")) | ||||
|    | ||||
|     def test2c_path_append_parent(s): | ||||
|     def test2c_path_append_parent(self): | ||||
|         here = tu.absdir(); | ||||
|         par = os.path.dirname(here) | ||||
|         was_there = par in sys.path | ||||
| @@ -91,16 +91,16 @@ class Test2(U.TestCase): | ||||
|         np = len(sys.path) | ||||
|          | ||||
|         for p in (None, __file__): | ||||
|             s.assertFalse(par in sys.path, "par not in initial path") | ||||
|             self.assertFalse(par in sys.path, "par not in initial path") | ||||
|             if not p: | ||||
|                 g = tu.path_append_parent() | ||||
|             else: | ||||
|                 g = tu.path_append_parent(p) | ||||
|             s.assertEqual(g,par, tu.msg(g,par, "path_append_parent return")) | ||||
|             s.assertTrue(par in sys.path, "actually appends") | ||||
|             self.assertEqual(g,par, tu.msg(g,par, "path_append_parent return")) | ||||
|             self.assertTrue(par in sys.path, "actually appends") | ||||
|             sys.path.remove(par) | ||||
|             l= len(sys.path) | ||||
|             s.assertEqual(l,np, tu.msg(l,np,"numpaths")) | ||||
|             self.assertEqual(l,np, tu.msg(l,np,"numpaths")) | ||||
|         if was_there: | ||||
|             # restore entry state (but no multiples needed!) | ||||
|             sys.path.append(par) | ||||
| @@ -113,59 +113,59 @@ class Test3(U.TestCase): | ||||
|     home= os.environ["HOME"] | ||||
|     if home: | ||||
|         home_junk = os.path.join(home,"test_junk") | ||||
|     def _rmsubs(s): | ||||
|     def _rmsubs(self): | ||||
|         import shutil | ||||
|         for sub in s.asubs: | ||||
|         for sub in self.asubs: | ||||
|             if os.path.isdir(sub): | ||||
|                 shutil.rmtree(sub) | ||||
|    | ||||
|     def setUp(s): | ||||
|         s._rmsubs() | ||||
|         if s.home and not os.path.isdir(s.home_junk): | ||||
|             os.mkdir(s.home_junk) | ||||
|     def setUp(self): | ||||
|         self._rmsubs() | ||||
|         if self.home and not os.path.isdir(self.home_junk): | ||||
|             os.mkdir(self.home_junk) | ||||
|  | ||||
|     def tearDown(s): | ||||
|         s._rmsubs() | ||||
|         if s.home and os.path.isdir(s.home_junk): | ||||
|             os.rmdir(s.home_junk) | ||||
|     def tearDown(self): | ||||
|         self._rmsubs() | ||||
|         if self.home and os.path.isdir(self.home_junk): | ||||
|             os.rmdir(self.home_junk) | ||||
|  | ||||
|     def test3a_subdir(s): | ||||
|         for sub in s.asubs: | ||||
|             s.assertFalse(os.path.isdir(sub), "init: no dir %r" % sub) | ||||
|     def test3a_subdir(self): | ||||
|         for sub in self.asubs: | ||||
|             self.assertFalse(os.path.isdir(sub), "init: no dir %r" % sub) | ||||
|             b,d = os.path.dirname(sub), os.path.basename(sub) | ||||
|             md = tu.make_subdir(d, b) | ||||
|             s.assertTrue(os.path.isdir(sub), "made dir %r" % sub) | ||||
|             s.assertEqual(md,sub, tu.msg(md,sub,  | ||||
|             self.assertTrue(os.path.isdir(sub), "made dir %r" % sub) | ||||
|             self.assertEqual(md,sub, tu.msg(md,sub,  | ||||
|                 "make_subdir returns path")) | ||||
|  | ||||
|             s2 = os.path.join(sub,"sub2") | ||||
|             tu.make_subdir("sub2", sub) | ||||
|             s.assertTrue(os.path.isdir(s2), "made dir %r" % s2) | ||||
|             self.assertTrue(os.path.isdir(s2), "made dir %r" % s2) | ||||
|             f = os.path.join(s2,"test_file") | ||||
|  | ||||
|             open(f,"w").write("testing..") | ||||
|             s.assertTrue(os.path.isfile(f), "file %r exists" % f) | ||||
|             self.assertTrue(os.path.isfile(f), "file %r exists" % f) | ||||
|             tu.delete_tree(sub) | ||||
|             s.assertFalse(os.path.isdir(sub),  | ||||
|             self.assertFalse(os.path.isdir(sub),  | ||||
|                 "delete_tree removes subdir %r" % sub ) | ||||
|  | ||||
|     def test3b_delete_tree_constraint(s): | ||||
|         if s.home: | ||||
|     def test3b_delete_tree_constraint(self): | ||||
|         if self.home: | ||||
|             err = None | ||||
|             try: | ||||
|                 tu.delete_tree(s.home_junk) | ||||
|                 tu.delete_tree(self.home_junk) | ||||
|             except tu.TestError, e: | ||||
|                 err = e.value | ||||
|             s.assertFalse(err is None,  | ||||
|                 "deltree on %r raises TestError" % (s.home_junk)) | ||||
|             self.assertFalse(err is None,  | ||||
|                 "deltree on %r raises TestError" % (self.home_junk)) | ||||
|         else: | ||||
|             s.fail("Skip deltree constraint test, no '$HOME' var") | ||||
|             self.fail("Skip deltree constraint test, no '$HOME' var") | ||||
|  | ||||
| # logging (& misc?) | ||||
| class Test4(U.TestCase): | ||||
|     logf = "/tmp/__tu__log__" | ||||
|  | ||||
|     def test4a(s): | ||||
|     def test4a(self): | ||||
|         wmsg = "a warning message" | ||||
|         emsg = "an error message" | ||||
|         import logging | ||||
| @@ -173,13 +173,13 @@ class Test4(U.TestCase): | ||||
|         tl = tu.TestLogger() | ||||
|         for i in (1,2): | ||||
|             # 2 passes to test clearing old file | ||||
|             tl.logfile_init(s.logf) | ||||
|             tl.logfile_init(self.logf) | ||||
|             logging.warn(wmsg) | ||||
|             logging.info("nada") | ||||
|             logging.error(emsg) | ||||
|             ll = tl.logfile_getlines() | ||||
|             nl = len(ll) | ||||
|             s.assertEquals(nl,2,  | ||||
|             self.assertEquals(nl,2,  | ||||
|                 tu.msg(nl,2, "pass %d: expected line count" % i)) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -166,24 +166,24 @@ class TestLogger(): | ||||
|     Note that existing logging will still occur, possibly | ||||
|     resulting in console messages and popup dialogs | ||||
|     """ | ||||
|     def __init__(s, lvl=logging.WARN): | ||||
|     def __init__(self, lvl=logging.WARN): | ||||
|         logging.basicConfig(level=lvl) | ||||
|          | ||||
|     def logfile_init(s, lfname): | ||||
|     def logfile_init(self, lfname): | ||||
|         """init or re-init a logfile""" | ||||
|         if getattr(s, "lfh", None): | ||||
|             logging.getLogger().handlers.remove(s.lfh) | ||||
|         if getattr(self, "lfh", None): | ||||
|             logging.getLogger().handlers.remove(self.lfh) | ||||
|         if os.path.isfile(lfname): | ||||
|             os.unlink(lfname) | ||||
|         s.lfh = logging.FileHandler(lfname) | ||||
|         logging.getLogger().addHandler(s.lfh) | ||||
|         s.lfname = lfname | ||||
|         self.lfh = logging.FileHandler(lfname) | ||||
|         logging.getLogger().addHandler(self.lfh) | ||||
|         self.lfname = lfname | ||||
|      | ||||
|     def logfile_getlines(s): | ||||
|     def logfile_getlines(self): | ||||
|         """get current content of logfile as list of lines""" | ||||
|         txt = [] | ||||
|         if s.lfname and os.path.isfile(s.lfname): | ||||
|            txt = open(s.lfname).readlines()  | ||||
|         if self.lfname and os.path.isfile(self.lfname): | ||||
|            txt = open(self.lfname).readlines()  | ||||
|         return txt | ||||
|  | ||||
| #===eof=== | ||||
|   | ||||
		Reference in New Issue
	
	Block a user