Example #1
0
    def _check (self, base):

        f = pybut.dbname ()

        s = Registry.getSchema('org.pybliographer/bibtex/0.1')
        
        db = Store.get ('file').dbcreate (f, s)

        self.parser = WithComments ('latin-1')

        rs = self.parser.parse(open(fp('%s.bib' % base)), db)
        db.rs.update(rs)
        db.save ()

        # mess a bit with the file to discard the schema
        tree = Compat.ElementTree.ElementTree(file=open(f))
        for s in tree.findall('./pyblio-schema'):
            s.clear()
        for s in tree.findall('./txo-group'):
            s.clear()

        tree.write(open(f, 'w'), encoding="utf-8")
        
        pybut.fileeq (f, fp('%s.xml' % base))

        Store.get ('file').dbdestroy (f, nobackup = True)
        return
Example #2
0
    def testAddTextQualifiersBizarrOrder (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', 'some stupid comment', Attribute.Text)
        rec.add ('text.qtext', 'even more stuff', Attribute.Text)
        rec.add ('text', 'another comment', Attribute.Text)
        rec.add ('text.qtext', 'stuff for another comment', Attribute.Text)
        
        db.add (rec)

        sol = Store.Record ()

        at = Attribute.Text ('some stupid comment')
        at.q = { 'qtext': [
            Attribute.Text ('some stuff'),
            Attribute.Text ('even more stuff')] }

        at2 = Attribute.Text ('another comment')
        at2.q = {'qtext': [ Attribute.Text ('stuff for another comment')]}
        sol ['text'] = [ at, at2 ]

        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)
Example #3
0
    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)
Example #4
0
    def testSimple(self):
        Registry.load_default_settings()

        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)
Example #5
0
    def setUp(self):
        Registry.load_default_settings()

        s = Registry.getSchema("org.pybliographer/pubmed/0.1")
        fmt = Store.get("memory")

        self.db = fmt.dbcreate(None, s)
Example #6
0
    def setUp(self):
        self.db = Store.get("file").dbopen(pybut.src("ut_format/sample.bip"))

        self.rec = self.db[1]
        self.rec["journal"] = []

        return
Example #7
0
    def setUp(self):
        sa = Schema.Schema(open(pybut.src('ut_adapter/a.sip')))

        fmt = Store.get('memory')
        self.dba = fmt.dbcreate(None, sa)
        self.dbb = A2BAdapter(self.dba)
        return
Example #8
0
    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)
Example #9
0
    def setUp (self):

        self.hd = Store.get(self.fmt)
        self.nm = pybut.dbname ()

        sc = Schema.Schema(fp('schema.xml'))
        self.db = self.hd.dbcreate(self.nm, sc)
        return
Example #10
0
    def setUp(self):
        self.db = Store.get("file").dbopen(pybut.src("ut_format/sample.bip"))

        self.rec = self.db[1]
        self.rec["journal"] = []
        self.rec["title"] = [Attribute.Text(u"My < title &")]

        return
Example #11
0
    def _check (self, base):

        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
Example #12
0
 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)
Example #13
0
    def setUp (self):

        self.hd   = Store.get (self.fmt)
        self.name = pybut.dbname ()
        
        self.db = self.hd.dbimport (self.name, fp('collate.xml'))
        self.db.save ()

        return
Example #14
0
    def setUp(self):
        Registry.load_default_settings()

        s = Registry.getSchema("org.pybliographer/pubmed/0.1")
        fmt = Store.get("memory")

        self.db = fmt.dbcreate(None, s)

        self.cnx = PubMed(self.db)
        self.port = reactor.listenTCP(8000, Server())
Example #15
0
    def testQualifiedRead (self):
        """ Qualified fields can be read and saved again identically """
        
        db = Store.get ('file').dbopen (pybut.src('ut_store/qualified.xml'))

        fd = open (self.f, 'w')
        db.xmlwrite (fd)
        fd.close ()

        pybut.fileeq (self.f, pybut.src('ut_store/qualified.xml'))
        return
Example #16
0
    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
Example #17
0
    def setUp (self):

        self.hd   = Store.get (self.fmt)
        self.name = pybut.dbname ()
        
        TContent.count = self.count + 1

        sc = Schema.Schema(fp('schema.xml'))
        self.db = self.hd.dbcreate (self.name, sc)

        return
Example #18
0
    def testRead (self):
        """ A database can be read and saved again identically """

        db = Store.get ('file').dbopen (pybut.src('ut_store/simple.xml'))

        fd = open (self.f, 'w')
        db.xmlwrite (fd)
        fd.close ()

        pybut.fileeq (self.f, pybut.src('ut_store/simple.xml'))
        return
Example #19
0
    def testResultSet (self):

        db = Store.get('file').dbopen(pybut.src('ut_store/resultset.xml'))

        ks = db.rs[1]
        assert ks.name == 'gronf'

        ks = list(ks.iterkeys())
        ks.sort()

        assert ks == [1,2], 'got %s' % repr (ks)
Example #20
0
    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
Example #21
0
    def testResolveA2B(self):
        sa = Schema.Schema(open(pybut.src('ut_adapter/a.sip')))

        fmt = Store.get('memory')
        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')
Example #22
0
    def testReadEmpty (self):
        """ A schema in a database is equivalent to outside the database """
        
        db = Store.get ('file').dbopen (pybut.src('ut_store/empty.xml'))

        file = open (self.f, 'w')
        db.schema.xmlwrite (file)
        file.close ()

        pybut.fileeq (self.f, pybut.src(os.path.join ('ut_store', 's_simple.xml')))
        
        return
Example #23
0
    def testEmpty (self):
        """ Create an empty database with a schema """

        schema = Schema.Schema (pybut.src(os.path.join ('ut_store', 's_simple.xml')))

        db = Store.get ('file').dbcreate (self.f, schema)
        db.save ()
        
        assert len (db.entries) == 0

        pybut.fileeq (self.f, pybut.src('ut_store/empty.xml'))
        return
Example #24
0
    def setUp(self):
        Registry.load_default_settings()

        s = Registry.getSchema('org.pybliographer/crossref/0.1')
        fmt = Store.get('memory')

        self.db = fmt.dbcreate(None, s)

        self.cnx = CrossRef.DOIQuery(self.db, 'user', 'pass')
        self.cnx.baseURL = 'http://localhost:8000/query'
        
        self.port = reactor.listenTCP(8000, Server())
        return
Example #25
0
    def testTxoFromSchema (self):
        """ Taxonomy fields can be read and saved """

        tmp = pybut.dbname()
        s = Schema.Schema(pybut.src('ut_store/taxoschema.xml'))
        db = Store.get('file').dbcreate(tmp,s)

        fd = open (self.f, 'w')
        db.xmlwrite (fd)
        fd.close ()

        pybut.fileeq (self.f, pybut.src('ut_store/taxoschemadb.xml'))
        return
Example #26
0
    def setUp(self):
        Registry.load_default_settings()

        s = Registry.getSchema("org.pybliographer/wok/0.1")
        fmt = Store.get("memory")

        self.db = fmt.dbcreate(None, s)

        self.cnx = WOK.WOK(self.db)
        self.port = reactor.listenTCP(8000, Server())

        self.cnx.baseURL = "http://localhost:8000/esti"
        return
Example #27
0
    def _check (self, base):
        f = pybut.dbname()

        db = Store.get ('file').dbopen (fp('%s.xml' % base))
        fd = open (f, 'w')
        
        self.writer = WithCaseHandler ()
        
        self.writer.write (fd, db.entries, db)

        fd.close ()
        
        pybut.fileeq (f, fp('%s.bib' % base))
        return
Example #28
0
    def __init__(self, legacy, citator, wp):
        self.citator = citator
        schema = Registry.getSchema('org.pybliographer/bibtex/0.1')
        self.db = Store.get('memory').dbcreate(None, schema)
        self.legacy = legacy
        self.reader = BibTeX.Reader()
        # TODO: once we have per-field queries in pyblio-1.3, directly
        # search for the key instead of keeping this cache
        self.mapping = {}

        self.citator.prepare(self.db, wp, _extract_id)
        
        # pre-fill the pyblio db with the bibtex records indicated in
        # the document, in the extra field. We don't have a clean way
        # to obtain the same record id as the last time when importing
        # from bibtex, so we create a new db afresh, and shuffle
        # things in a second pass.
        tmp = Store.get('memory').dbcreate(None, schema)
        renaming = {}

        self.missing = []
        fetched = self.citator.wp.fetch()
        if fetched is None:
            return

        for pyblio_uid, name, bibtex_key in fetched:
            full_key = Key(legacy, str(bibtex_key))
            if not legacy.has_key(full_key):
                self.missing.append(bibtex_key)
                continue
            tmp_key = self._transfer_entry(tmp, full_key)
            renaming[tmp_key] = pyblio_uid
            self.mapping[full_key] = pyblio_uid

        for tmp_key, record in tmp.entries.iteritems():
            self.db.add(record, key=renaming[tmp_key])
Example #29
0
    def testAuthorYear(self):
        from Pyblio.Cite.Style.BibTeX import AlphaKey
        
        db = Store.get('memory').dbimport(None, pybut.src('ut_citation/sample.bip'))
        g = AlphaKey(db)

        res = [g.make_key(uid) for uid in range(1, 7)]
        
        self.failUnlessEqual(
            res, ['GF06',
                  'Gob06',
                  'Oth06',
                  '06',
                  'Gob',
                  'Unknown'])
Example #30
0
    def testWrite (self):
        """ A new database can be saved with its schema """

        schema = Schema.Schema (pybut.src(os.path.join ('ut_store', 's_full.xml')))
        db = Store.get ('file').dbcreate (self.f, schema)
        
        e = Store.Record ()

        scn = Attribute.Person (last = 'Last 2')
        scn.q ['role'] = [ Attribute.Text ('Editor') ]
        
        e ['author'] = [ Attribute.Person (last = u'Last 1é'), scn ]

        url1 = Attribute.URL ('http://pybliographer.org')
        url1.q ['desc'] = [ Attribute.Text ('Main site') ]
        url1.q ['lang'] = [ Attribute.Txo (db.schema.txo ['language'].byname ('EN')) ]

        url2 = Attribute.URL ('http://pybliographer.org')
        url2.q ['desc'] = [ Attribute.Text ('Main site') ]
        url2.q ['lang'] = [ Attribute.Txo (db.schema.txo ['language'].byname ('FR')) ]
        e ['url']    = [ url1, url2 ]

        e ['text']   = [ Attribute.Text (u'sample text é') ]

        rich = Attribute.Text (u'sample text é')
        rich.q ['comment'] = [ Attribute.Text ('bullshit') ]
        
        e ['rich']   = [ rich ]
        e ['date']   = [ Attribute.Date (year = 2003) ]
        e ['id']     = [ Attribute.ID ('Hehe') ]
        
        db.add (e)

        db.header = u"Hi, I'm a database description"

        rs = db.rs.new()
        rs.name = "sample"

        rs.add (1)
        db.rs.update(rs)

        db.save ()

        pybut.fileeq (self.f, pybut.src('ut_store/simple.xml'))
        return