Beispiel #1
0
    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
Beispiel #2
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
Beispiel #3
0
    def testIdempotent(self):
        src = fp('idempotent.bib')
        bt = BeefTeX.BeefTeX(src)

        tmp = pybut.dbname()
        bt.Save(tmp)

        pybut.fileeq(src, tmp)
Beispiel #4
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)
Beispiel #5
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
Beispiel #6
0
        def done(total):
            self.failUnlessEqual(total, 1641)
            self.failUnlessEqual(len(rs), 250)

            self.db.rs.update(rs)
            tmp = pybut.dbname()
            fd = open(tmp, "w")
            self.db.xmlwrite(fd)
            fd.close()

            pybut.fileeq(tmp, pybut.fp("ut_wok", "result.bip"))
Beispiel #7
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
Beispiel #8
0
    def testXMLWrite(self):
        r = Store.Record()
        k = r.add('a', 'A sample !', Attribute.Text)
        self.dba.add(r)

        tmp = pybut.dbname()
        fd = open(tmp, 'w')
        self.dbb.xmlwrite(fd)
        fd.close()

        pybut.fileeq(tmp, pybut.src('ut_adapter/saved-b.bip'))
Beispiel #9
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
Beispiel #10
0
    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)
Beispiel #11
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
Beispiel #12
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
Beispiel #13
0
    def testParsing(self):

        src = os.path.join(base, "search-0.xml")

        r = Reader()
        r.parse(Compat.ElementTree.ElementTree(file=open(src)), self.db)

        tmp = pybut.dbname()
        fd = open(tmp, "w")
        self.db.xmlwrite(fd)
        fd.close()

        pybut.fileeq(tmp, pybut.fp("ut_pubmed", "result.bip"))
Beispiel #14
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
Beispiel #15
0
    def testImport(self):
        db = self.hd.dbimport(self.name, fp('sample.xml'))
        try:
            os.stat(self.name)
            assert False, 'the file should not be created'
        except OSError:
            pass

        nmo = pybut.dbname ()
        
        fd = open (nmo, 'w')
        db.xmlwrite (fd)
        fd.close ()

        pybut.fileeq (nmo, fp('sample.xml'))
        return
Beispiel #16
0
    def testImport (self):
        ''' Import an XML database in the Store '''

        db = self.hd.dbimport (self.nm, fp('sample.xml'))
        db.save ()

        nmo = pybut.dbname ()
        
        fd = open (nmo, 'w')
        db.xmlwrite (fd)
        fd.close ()

        pybut.fileeq (nmo, fp('sample.xml'))
        self.hd.dbdestroy (self.nm, nobackup = True)

        os.unlink (nmo)
        return
Beispiel #17
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
Beispiel #18
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
Beispiel #19
0
    def testWrite(self):
        """ Writing does not modify the file """

        for sch in ("simple.xml", "qualifiers.xml", "group.xml"):
            file = pybut.dbname()

            schema = pybut.src(os.path.join("ut_schema", sch))
            a = Schema.Schema(schema)

            out = open(file, "w")
            a.xmlwrite(out)
            out.close()

            # both files should be identical
            pybut.fileeq(schema, file)

            try:
                os.unlink(file)
            except OSError:
                pass
Beispiel #20
0
    def testTxoInDB (self):

        """ Use Txos in database entries """
        
        # add some enums to the database
        a = self.db.schema.txo['a']

        e = Store.Record ()
        e ['enum-a'] = [ Attribute.Txo (a [1]) ]
        
        self.db.add (e)

        f = ',,enumdb-' + self.fmt

        fd = open (f, 'w')
        self.db.xmlwrite (fd)
        fd.close ()
        
        pybut.fileeq (f, fp('enumerate.xml'))
        os.unlink (f)
        return