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

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

        pybut.fileeq(src, tmp)
示例#3
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
示例#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)
示例#5
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
示例#6
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
示例#7
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
示例#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'))
示例#9
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
示例#10
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"))
示例#11
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)
示例#12
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"))
示例#13
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
示例#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
示例#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
示例#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
示例#17
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
示例#18
0
    def setUp (self):

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

        self.db = self.hd.dbimport (self.name, self.dbfile)
        self.db.save ()

        # create a RS with all the entries
        self.rs = self.db.rs.new()
        
        for k in self.db.entries:
            self.rs.add (k)

        self.a = Store.Record ()
        self.b = Store.Record ()
        return
示例#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
示例#20
0
    def testGroup(self):
        """ Some fields have Txo groups."""

        import sys

        a = Schema.Schema(pybut.src("ut_schema/group.xml"))

        assert a["toto"].group == "toto"

        # Create a database, and check that the Txo has indeed been
        # prefilled.
        file = pybut.dbname()

        fmt = Store.get("file")
        db = fmt.dbcreate(file, a)

        keys = db.schema.txo["toto"].keys()
        keys.sort()

        self.failUnlessEqual(keys, [1, 2])
        return
示例#21
0
    def testComplex(self):
        """ Accents and escaping """

        file = pybut.dbname()

        import sys

        a = Schema.Schema(pybut.src("ut_schema/complex.xml"))

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

        # both files should be identical
        d1 = open(file).read()
        d2 = open(pybut.src("ut_schema/complex.xml")).read()

        assert d1 == d2

        try:
            os.unlink(file)
        except OSError:
            pass
示例#22
0
    def setUp(self):

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

        return
示例#23
0
 def setUp(self):
     self.hd = Store.get('memory')
     self.name = pybut.dbname()
     return