def testAddOnlyQualifiers (self): db = Store.get ('file').dbopen (pybut.src('ut_store/addsimple.xml')) rec = Store.Record () rec.add ('text.qtext', 'some stuff', Attribute.Text) rec.add ('text.qtext', 'even more stuff', Attribute.Text) try: db.add (rec) except Exceptions.SchemaError: pass else: assert 0, 'db.add should not be allowed as there is ' \ 'Attribute.UnknownContent in rec' sol = Store.Record () at = Attribute.UnknownContent () at.q = { 'qtext': [ Attribute.Text ('some stuff'), Attribute.Text ('even more stuff')] } sol ['text'] = [ at ] assert sol.deep_equal (rec), "\n%s\n not equal to \n%s\n (Think of non-displayed" \ " qualifiers, if you can't see any difference.)" % (sol, rec) suite = pybut.suite (TestStore) if __name__ == '__main__': pybut.run (suite)
class TestISI (pybut.TestCase): def setUp(self): Registry.load_default_settings() def tearDown(self): Registry.reset() def parse (self, file): schema = Registry.getSchema("org.pybliographer/wok/0.1") fd = open (file) self.fn = pybut.dbname () self.db = Store.get('file').dbcreate (self.fn, schema) self.p = ISI.Reader() self.p.parse(fd, self.db) return def testText (self): self.parse(pybut.src('ut_isi/text.isi')) self.db.save () pybut.fileeq(self.fn, pybut.src('ut_isi/text.xml')) return suite = pybut.suite (TestISI) if __name__ == '__main__': pybut.run (suite)
# Check that emitting works p.emit('yorgl') assert count == ['1234'] # Check that we can unregister our function p.unregister('yorgl', free_function) p.emit('yorgl') assert count == ['1234'], count def testMethod(self): o = Bound() p = Publish() p.register('yorgl', o.bound, '1234') # Check that emitting works p.emit('yorgl') assert o.count == ['1234'] # Check that we can unregister our function p.unregister('yorgl', o.bound) p.emit('yorgl') assert o.count == ['1234'] suite = pybut.suite(TestCallback) if __name__ == '__main__': pybut.run (suite)
return pybut.fp(*(('ut_beeftex',) + args)) class TestBeefTeX(pybut.TestCase): def testIdempotent(self): src = fp('idempotent.bib') bt = BeefTeX.BeefTeX(src) tmp = pybut.dbname() bt.Save(tmp) pybut.fileeq(src, tmp) def testTransform(self): bt = BeefTeX.BeefTeX(fp('transform.bib')) self.failUnlessEqual(bt.Keys(), ['a', 'c', 'd']) bt.Delete('d') self.failUnlessEqual(bt.Keys(), ['a', 'c']) tmp = pybut.dbname() bt.Save(tmp) pybut.fileeq(fp('transformed.bib'), tmp) suite = pybut.suite(TestBeefTeX) if __name__ == '__main__': pybut.run (suite)
q = OrderBy ('a', asc = False) self.isLess (q, self.b, self.a) def testShorterIsLess (self): self.a ['a'] = [ Attribute.Text ('ABC') ] self.b ['a'] = [ Attribute.Text ('ABCD') ] q = OrderBy ('a') self.isLess (q, self.a, self.b) q = OrderBy ('a', asc = False) self.isLess (q, self.b, self.a) def testShorterIsLessThanMultiple (self): self.a ['a'] = [ Attribute.Text ('ABC'), Attribute.Text ('DEF')] self.b ['a'] = [ Attribute.Text ('ABCD'), Attribute.Text ('EF') ] q = OrderBy ('a') self.isLess (q, self.a, self.b) q = OrderBy ('a', asc = False) self.isLess (q, self.b, self.a) suite = pybut.suite (TestOrdering) if __name__ == '__main__': pybut.run (suite)
# path. self.failUnlessEqual(Registry.schemas(), ["with-path"]) def testCategories(self): c = Registry.get("with-path", "importers") assert len(c) == 2 def testAdapters(self): c = Registry.get("with-adapter", "adapters") self.failUnlessEqual(len(c), 1) c = c[0] self.failUnlessEqual(c.target, "another/format") def testUnique(self): fd = open(",,sample.rip", "w") fd.write( """ [with-path] path: %(system)s/bibtex-2.xml """ ) fd.close() self.failUnlessRaises(AssertionError, Registry.load_settings, ".") suite = pybut.suite(TestRegistry) if __name__ == "__main__": pybut.run(suite)
import os, pybut, sys from Pyblio import Tools class TestTools (pybut.TestCase): """ Perform tests on the Pyblio.Tools module """ def testIdMake (self): """ Check the id generator """ # No proposal k = Tools.id_make (1, None) assert k == (2, 1) # The proposed id is smaller than the latest k = Tools.id_make (2, 1) assert k == (2, 1) # The proposed id is larget than the latest k = Tools.id_make (2, 4) assert k == (5, 4) return suite = pybut.suite (TestTools) if __name__ == '__main__': pybut.run (suite)
class TestSimpleQueryFile(TestSimpleQuery, pybut.TestCase): fmt = "file" class TestSimpleQueryFileIndexed(TestSimpleQuery, pybut.TestCase): fmt = "file" indexed = True class TestSimpleQueryDB(TestSimpleQuery, pybut.TestCase): fmt = "bsddb" files = [TestSimpleQueryFile, TestSimpleQueryFileIndexed] bsddb = [TestSimpleQueryDB] # in some cases, we cannot check for bsddb (too old) try: m = Store.get("bsddb") suite = pybut.suite(*(files + bsddb)) except ImportError, msg: print "warning: only testing the file store: %s" % msg suite = pybut.suite(*files) if __name__ == "__main__": pybut.run(suite)
source = pybut.src('ut_bst', 'abbrv.bst') o = BST.BST(open(source)) db = Store.get('memory').dbcreate( None, Registry.getSchema('org.pybliographer/bibtex/0.1')) reader = BibTeX.Reader() rs = reader.parse(open(pybut.src('ut_bst', 'simple.bib')), db) state = BST.State(rs, db) o.Run(state) output = """\ \\begin{thebibliography}{1} \\bibitem{1} Frederic Gobry and First Last. \\newblock This is a title. \\newblock {\em My journal}, 12(123), 2007. \\bibitem{2} Frederic Gobry and First Last. \\newblock {\em This is a title}. \\end{thebibliography} """ self.failUnlessEqual(state.output, output) suite = pybut.suite(TestBST) if __name__ == '__main__': pybut.run(suite)
def _cmp(self, v, s): stage2 = v(self.db) stage3 = stage2(self.rec) r = HTML.generate(stage3) assert r == s, "expected %s, got %s" % (repr(s), repr(r)) def testEscape(self): v = one("title") + " ok &" self._cmp(v, "My < title & ok &") class TestOutputText(TestOutput): def _cmp(self, v, s): stage2 = v(self.db) stage3 = stage2(self.rec) r = Text.generate(stage3) assert r == s, "expected %s, got %s" % (repr(s), repr(r)) def testEscape(self): v = one("title") + " ok &" self._cmp(v, "My < title & ok &") suite = pybut.suite(TestFormat, TestOutputHTML, TestOutputText) if __name__ == "__main__": pybut.run(suite)
d1 = open(file).read() d2 = open(pybut.src("ut_schema/complex.xml")).read() assert d1 == d2 try: os.unlink(file) except OSError: pass def testTypes(self): """ Attribute types """ from Pyblio import Attribute s = Schema.Schema(pybut.src("ut_schema/types.xml")) assert s["url"].type is Attribute.URL assert s["text"].type is Attribute.Text assert s["author"].type is Attribute.Person assert s["date"].type is Attribute.Date assert s["id"].type is Attribute.ID assert s["enum"].type is Attribute.Txo return suite = pybut.suite(TestSchema) if __name__ == "__main__": pybut.run(suite)
from Pyblio.Cite.WP.File import File from Pyblio.Cite import Citator class TestCitation(pybut.TestCase): def setUp(self): self.fd = StringIO() self.wp = File(self.fd) self.db = Store.get('memory').dbimport(None, pybut.src('ut_citation/sample.bip')) self.cit = Citator.Citator() self.cit.xmlload(pybut.src('ut_citation/sample.cip')) self.cit.prepare(self.db, self.wp) def testInsert(self): self.cit.cite([1]) self.failUnlessEqual(self.wp.cited, [(1, '1', None)]) self.cit.update() content = self.fd.getvalue() expected = u'''\ <table> <tr><td>[1]</td><td>Fr\xe9d\xe9ric Gobry and G\xe9d\xe9ric Fobrz. A title. 2006.</td></tr> </table>''' self.failUnlessEqual(content, expected) suite = pybut.suite (TestCitation, TestGenerateKeys) if __name__ == '__main__': pybut.run (suite)
(6, 'A1', u'Gobry 2, Frederic')])], \ 'obtained %s' % `r` return def testMultiLines (self): r = self.parsingOk (''' TY - TYPE\r A1 - Gobry,\r Frederic\r ER - \r TY - TYPE\r A1 - Gobry 2,\r Frederic\r ER - \r ''') assert r == [('D', [(2, 'TY', u'TYPE'), (3, 'A1', u'Gobry, Frederic')]), ('D', [(7, 'TY', u'TYPE'), (8, 'A1', u'Gobry 2, Frederic')])], \ 'obtained %s' % `r` return suite = pybut.suite (TestTagged, TestRISTransport) if __name__ == '__main__': pybut.run (suite)
f = pybut.dbname () s = Schema.Schema (pybut.src('ut_xmlmarc/schema.xml')) db = Store.get ('file').dbcreate (f, s) self.parser = XMLMARC.SimpleReader(mapping) rs = self.parser.parse(open(pybut.src('ut_xmlmarc/%s.xml' % base)), db) db.rs.update(rs) db.save () pybut.fileeq (f, pybut.src('ut_xmlmarc/r-%s.xml' % base)) Store.get ('file').dbdestroy (f, nobackup = True) return def testBase (self): self._check ('simple') def testControl (self): """ handling of control fields """ self._check ('control') suite = pybut.suite (TestImport) if __name__ == '__main__': pybut.run (suite)
class TestRIS (pybut.TestCase): def parse (self, file): fd = open (file) self.fn = pybut.dbname () s = Schema.Schema (pybut.src('standard.xml')) self.db = Store.get ('file').dbcreate (self.fn, s) self.p = RIS.Reader () self.p.parse (fd, self.db) return def testText (self): self.parse (pybut.src('ut_ris/text.ris')) self.db.save () pybut.fileeq (self.fn, pybut.src('ut_ris/text.xml')) return suite = pybut.suite (TestRIS) if __name__ == '__main__': pybut.run (suite)
def testEmpty (self): self._check ('exp-simple') def testNested (self): self._check('exp-nested') def testNested (self): self._check('exp-no-key') from Pyblio.Parsers.Syntax.BibTeX.Coding import encode class TestBibTeXEncoder(pybut.TestCase): def testEncoder(self): """ Some trivial conversion tasks """ self.failUnlessEqual(encode(u'héß\u0010'), r'h\'e\ss{}\char16{}') def testEncodeI(self): """ Check that an accent on a 'i' uses \i to avoid a double accent """ self.failUnlessEqual(encode(u'îï'), r'\^{\i}\"{\i}') def testMultiCommand(self): """ Check that commands are properly separated by {} """ self.failUnlessEqual(encode(u'©æ'), r'\copyright{}\ae{}') suite = pybut.suite (TestBibTeXEncoder, TestBibTeXReader, TestBibTeXImport, TestBibTeXExport) if __name__ == '__main__': pybut.run (suite)
self.dba = fmt.dbcreate(None, sa) from Pyblio import Registry Registry.reset() Registry.load_settings(pybut.src('ut_adapter')) dest = Adapter.adapt_schema(self.dba, 'b') self.failUnlessEqual(dest.schema.id, 'b') class TestAdapters(pybut.TestCase): def setUp(self): Registry.load_default_settings() def tearDown(self): Registry.reset() def check(self, name, schema): src = Store.get('file').dbopen( pybut.src('ut_adapter/' + name + '-src.bip')) dst = Adapter.adapt_schema(src, schema) tmp = pybut.dbname() fd = open(tmp, 'w') dst.xmlwrite(fd) fd.close() pybut.fileeq(pybut.src('ut_adapter/' + name + '-dst.bip'), tmp) def testWOK2BibTeX(self): self.check('wok-to-bibtex', 'org.pybliographer/bibtex/0.1') suite = pybut.suite(TestFromAtoB, TestResolution) if __name__ == '__main__': pybut.run (suite)
assert idx == ['www', 'pybliographer', 'org', 'faq', 'toto'] assert Attribute.Date (year = 2003).index () == [] return def testSort (self): coll = Attribute.Text (u"HÉHÉ les Gens, s'il vous plaît.").sort () assert coll == u"héhé les gens, s'il vous plaît." coll = Attribute.Person (first = u'Jean-Albert', last = u'Dââ Schnock').sort () assert coll == u"dââ schnock\0jean-albert" for d, c in (((2003, None, None), '20030000'), ((2003, 11, None), '20031100'), ((2003, 11, 13 ), '20031113')): coll = Attribute.Date (year = d [0], month = d [1], day = d [2]).sort () assert coll == c coll = Attribute.URL ('http://pybliographer.org/FAQ/').sort () assert coll == 'http://pybliographer.org/FAQ/' return suite = pybut.suite (TestAttribute) if __name__ == '__main__': pybut.run (suite)