Exemplo n.º 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
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 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)
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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')
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
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)
Exemplo n.º 13
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
Exemplo n.º 14
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)
Exemplo n.º 15
0
    def testDefaultName(self):
        """ Check that the default names are used when no locale is specified """

        a = Schema.Schema(pybut.src("ut_schema/simple.xml"))["author"]

        assert a.name == "Author"
        return
Exemplo n.º 16
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
Exemplo n.º 17
0
    def testFullTextQuery(self):
        """ Full text query """

        sc = Schema.Schema(pybut.src("ut_query/schema.xml"))
        self.db = self.hd.dbcreate(self.name, sc)
        if self.indexed:
            self.db.index()

        import random

        # generate 64 base words
        words = []
        letter = "abcdefgh"

        for a in letter:
            for b in letter:
                words.append(a + b)

        def phrase():
            random.shuffle(words)
            return string.join(words[:5], " ")

        # Fill the db with some phrases
        entries = {}
        for w in words:
            entries[w] = []

        for i in range(0, 16):

            e = Store.Record()

            a, b, c = phrase(), phrase(), phrase()

            e["title"] = [Attribute.Text(a), Attribute.Text(b)]
            e["url"] = [Attribute.URL(c)]

            k = self.db.add(e)

            for w in a.split() + b.split() + c.split():
                if k not in entries[w]:
                    entries[w].append(k)

        # Search the occurences of every word
        for w in words:

            rs = self.db.query(Query.AnyWord(w))

            vals = []
            for v in rs:
                vals.append(v)

            real = [] + entries[w]

            vals.sort()
            real.sort()

            assert vals == real, "%s != %s" % (vals, real)
        return
Exemplo n.º 18
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
Exemplo n.º 19
0
    def testDuplicate(self):
        """ Forbid field duplication """

        try:
            Schema.Schema(pybut.src("ut_schema/duplicate.xml"))
            assert False

        except Schema.SchemaError, msg:
            pass
Exemplo n.º 20
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
Exemplo n.º 21
0
    def textHasFieldQuery(self):

        db = self.hd.dbimport(self.name, pybut.src("ut_query/hasfield.xml"))
        if self.indexed:
            db.index()

        got = self._res(db.query(Query.HasField("a")))

        assert got == [1, 3, 4], "got %s" % got
        return
Exemplo n.º 22
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)
Exemplo n.º 23
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'))
Exemplo n.º 24
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
Exemplo n.º 25
0
    def testNotQuery(self):

        db = self.hd.dbimport(self.name, pybut.src("ut_query/and.xml"))
        if self.indexed:
            db.index()

        g = db.schema.txo["a"]

        q = ~(Query.Txo("txo", g[2]) | Query.AnyWord("First"))

        res = self._res(db.query(q))
        assert res == [4], "got %s" % repr(res)
Exemplo n.º 26
0
    def testSimple(self):
        """ Open a simple document """

        s = Schema.Schema(pybut.src("ut_schema/simple.xml"))

        assert s.has_key("author")
        assert s.has_key("url")

        a = s["author"]
        assert a.names["en"] == "Author (en)"

        return
Exemplo n.º 27
0
    def testL10nName(self):
        """ Check that names are localized """

        from Pyblio import I18n

        I18n.lz.lang = "en_US"
        I18n.lz.lang_one = "en"

        a = Schema.Schema(pybut.src("ut_schema/simple.xml"))["author"]

        assert a.name == "Author (en)", a.name
        return
Exemplo n.º 28
0
    def testOrQuery(self):

        db = self.hd.dbimport(self.name, pybut.src("ut_query/and.xml"))
        if self.indexed:
            db.index()

        g = db.schema.txo["a"]

        q = Query.Txo("txo", g[2]) | Query.AnyWord("First")

        res = self._res(db.query(q))
        assert res == [1, 2, 3], "got %s" % ` res `

        return
Exemplo n.º 29
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
Exemplo n.º 30
0
    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