Exemplo n.º 1
0
 def isduplicate(a, b):
     """test Biblio's eq method for duplicates
     """
     db = bibtexparser.loads(a + '\n' + b)
     e1, e2 = db.entries
     refs = Biblio()
     return refs.eq(e1, e2)
Exemplo n.º 2
0
 def isduplicate(self, a, b):
     """test Biblio's eq method for duplicates
     """
     db = bibtexparser.loads(a + '\n' + b)
     e1, e2 = db.entries
     refs = Biblio(similarity=self.similarity)
     return refs.eq(e1, e2)
Exemplo n.º 3
0
class TestAddBib(unittest.TestCase):
    def setUp(self):
        self.mybib = tempfile.mktemp(prefix='papers.bib')
        self.somebib = tempfile.mktemp(prefix='papers.somebib.bib')
        self.pdf1, self.doi, self.key1, self.newkey1, self.year, self.bibtex1 = prepare_paper(
        )
        self.pdf2, self.si, self.doi, self.key2, self.newkey2, self.year, self.bibtex2 = prepare_paper2(
        )
        bib = '\n'.join([self.bibtex1, self.bibtex2])
        with open(self.somebib, 'w') as somebfile:
            somebfile.write(bib)
        self.my = Biblio(db=self.mybib)

    def test_addbib(self):
        self.assertTrue(self.key1 not in [e['ID'] for e in self.my.db.entries])
        self.assertTrue(self.key2 not in [e['ID'] for e in self.my.db.entries])
        self.my.add_bibtex_file(self.somebib)
        self.assertEqual(len(self.my.db.entries), 2)
        self.assertEqual(self.my.db.entries[0]['ID'], self.key1)
        self.assertEqual(self.my.db.entries[1]['ID'], self.key2)

    def tearDown(self):
        os.remove(self.mybib)
        os.remove(self.somebib)
        if os.path.exists('.papersconfig.json'):
            os.remove('.papersconfig.json')
Exemplo n.º 4
0
 def test_adddir_pdf(self):
     self.my = Biblio(db=self.mybib)
     self.my.scan_dir(self.somedir)
     self.assertEqual(len(self.my.db.entries), 2)
     keys = [self.my.db.entries[0]['ID'], self.my.db.entries[1]['ID']]
     self.assertEqual(sorted(keys),
                      sorted([self.newkey1,
                              self.newkey2]))  # PDF: update key
Exemplo n.º 5
0
 def test_adddir_pdf_cmd(self):
     sp.check_call('papers add --recursive --bibtex {} {}'.format(
         self.mybib, self.somedir),
                   shell=True)
     self.my = Biblio(self.mybib)
     self.assertEqual(len(self.my.db.entries), 2)
     keys = [self.my.db.entries[0]['ID'], self.my.db.entries[1]['ID']]
     self.assertEqual(sorted(keys),
                      sorted([self.newkey1,
                              self.newkey2]))  # PDF: update key
Exemplo n.º 6
0
 def setUp(self):
     self.mybib = tempfile.mktemp(prefix='papers.bib')
     self.somebib = tempfile.mktemp(prefix='papers.somebib.bib')
     self.pdf1, self.doi, self.key1, self.newkey1, self.year, self.bibtex1 = prepare_paper(
     )
     self.pdf2, self.si, self.doi, self.key2, self.newkey2, self.year, self.bibtex2 = prepare_paper2(
     )
     bib = '\n'.join([self.bibtex1, self.bibtex2])
     with open(self.somebib, 'w') as somebfile:
         somebfile.write(bib)
     self.my = Biblio(db=self.mybib)
Exemplo n.º 7
0
class TestAddDir(unittest.TestCase):
    def setUp(self):
        self.pdf1, self.doi, self.key1, self.newkey1, self.year, self.bibtex1 = prepare_paper(
        )
        self.pdf2, self.si, self.doi, self.key2, self.newkey2, self.year, self.bibtex2 = prepare_paper2(
        )
        self.somedir = tempfile.mktemp(prefix='papers.somedir')
        self.subdir = os.path.join(self.somedir, 'subdir')
        os.makedirs(self.somedir)
        os.makedirs(self.subdir)
        shutil.copy(self.pdf1, self.somedir)
        shutil.copy(self.pdf2, self.subdir)
        self.mybib = tempfile.mktemp(prefix='papers.bib')
        sp.check_call('papers install --local --bibtex {}'.format(self.mybib),
                      shell=True)

    def test_adddir_pdf(self):
        self.my = Biblio(db=self.mybib)
        self.my.scan_dir(self.somedir)
        self.assertEqual(len(self.my.db.entries), 2)
        keys = [self.my.db.entries[0]['ID'], self.my.db.entries[1]['ID']]
        self.assertEqual(sorted(keys),
                         sorted([self.newkey1,
                                 self.newkey2]))  # PDF: update key

    def test_adddir_pdf_cmd(self):
        sp.check_call('papers add --recursive --bibtex {} {}'.format(
            self.mybib, self.somedir),
                      shell=True)
        self.my = Biblio(self.mybib)
        self.assertEqual(len(self.my.db.entries), 2)
        keys = [self.my.db.entries[0]['ID'], self.my.db.entries[1]['ID']]
        self.assertEqual(sorted(keys),
                         sorted([self.newkey1,
                                 self.newkey2]))  # PDF: update key

    def tearDown(self):
        os.remove(self.mybib)
        shutil.rmtree(self.somedir)
        if os.path.exists('.papersconfig.json'):
            os.remove('.papersconfig.json')