示例#1
0
    def test_Collection(self):
        from pyglottolog.monsterlib._bibfiles_db import Database

        if not PY2:  # pragma: no cover
            return

        db = self.tmp_path('test.sqlite')
        with capture(self.api.bibfiles.to_sqlite, db) as out:
            self.assertIn('ENTRYTYPE', out)
        with capture(self.api.bibfiles.to_sqlite, db) as out:
            pass
        with capture(self.api.bibfiles.to_sqlite, db, rebuild=True) as out:
            pass

        db = Database(db, self.api.bibfiles)
        with capture(db.recompute, reload_priorities=self.api.bibfiles) as out:
            self.assertEqual(len(out.splitlines()), 34)
        with capture(db.is_uptodate, self.api.bibfiles[1:],
                     verbose=True) as out:
            self.assertEqual(len(out.splitlines()), 3)
        db.to_bibfile(self.tmp_path('out.bib'))
        db.to_csvfile(self.tmp_path('out.csv'))
        db.to_replacements(self.tmp_path('out.json'))
        self.assertEqual(db.to_hhmapping(), {'s:Karang:Tati-Harzani': 41999})
        with capture(db.trickle) as out:
            self.assertIn('2 changed 1 added in a', out)
        key, (entrytype, fields) = db[('b.bib', 'arakawa97')]
        self.assertEqual(entrytype, 'article')
        self.assertEqual(fields['volume'], '16')
        with capture(db.stats) as out:
            pass

        for attr in ['splits', 'merges', 'identified', 'combined']:
            with capture(getattr(db, 'show_' + attr)) as out:
                pass
示例#2
0
    def test_Collection(self):
        from pyglottolog.monsterlib._bibfiles import Collection
        from pyglottolog.monsterlib._bibfiles_db import Database

        if not PY2:  # pragma: no cover
            return

        c = Collection(self.references.joinpath('bibtex'))
        with capture(c.check_all) as out:
            self.assertNotIn('invalid', out)
        with capture(c.roundtrip_all) as out:
            self.assertIn('a.bib', out)
        with capture(c['b.bib'].show_characters) as out:
            self.assertIn('CJK UNIFIED IDEOGRAPH', out)
        abib = c[0]
        self.assertEqual(len(list(abib.iterentries())), 2)
        assert abib.size
        assert abib.mtime

        db = self.tmp_path('test.sqlite').as_posix()
        with capture(c.to_sqlite, db) as out:
            self.assertIn('entries total', out)
        with capture(c.to_sqlite, db) as out:
            pass
        with capture(c.to_sqlite, db, rebuild=True) as out:
            pass

        db = Database(db)
        with capture(db.recompute, reload_priorities=c) as out:
            self.assertEqual(len(out.splitlines()), 32)
        with capture(db.is_uptodate, c[1:], verbose=True) as out:
            self.assertEqual(len(out.splitlines()), 3)
        db.to_bibfile(self.tmp_path('out.bib'))
        db.to_csvfile(self.tmp_path('out.csv'))
        db.to_replacements(self.tmp_path('out.json'))
        self.assertEqual(db.to_hhmapping(), {'s:Karang:Tati-Harzani': 41999})
        with capture(db.trickle, c) as out:
            self.assertIn('2 changed 0 added in a.bib', out)
        key, (entrytype, fields) = db[('b.bib', 'arakawa97')]
        self.assertEqual(entrytype, 'article')
        self.assertEqual(fields['volume'], '16')
        with capture(db.stats) as out:
            pass

        for attr in ['splits', 'merges', 'identified', 'combined']:
            with capture(getattr(db, 'show_' + attr)) as out:
                pass
示例#3
0
 def to_sqlite(self, filename, rebuild=False):
     """Return a database with the bibfiles loaded."""
     return Database.from_bibfiles(self, filename, rebuild=rebuild)
示例#4
0
 def to_sqlite(self, filename, rebuild=False):
     """Return a database with the bibfiles loaded."""
     return Database.from_bibfiles(self, filename, rebuild=rebuild)