diff --git a/papers/__main__.py b/papers/__main__.py index 2bbca70..7cbcff7 100644 --- a/papers/__main__.py +++ b/papers/__main__.py @@ -22,9 +22,10 @@ def savebib(my_bib, config): """ Given a Biblio object and its configuration, save them to disk. If you're using the git bib tracker, will trigger a git commit there. """ - logger.info('Saving '+config.bibtex) if papers.config.DRYRUN: + logger.info(f'DRYRUN: NOT saving {config.bibtex}') return + logger.info(f'Saving {config.bibtex}') if my_bib is not None: my_bib.save(config.bibtex) if config.git: diff --git a/tests/test_add.py b/tests/test_add.py index c930518..950587e 100644 --- a/tests/test_add.py +++ b/tests/test_add.py @@ -53,7 +53,6 @@ def test_fails_without_install(self): def test_add(self): self.assertTrue(os.path.exists(self.mybib)) - print("bibtex", self.mybib, 'exists?', os.path.exists(self.mybib)) paperscmd(f'add --bibtex {self.mybib} {self.pdf}') file_ = self._checkbib(dismiss_key=True) @@ -144,17 +143,38 @@ def setUp(self): self.pdf1, self.doi, self.key1, self.newkey1, self.year, self.bibtex1, self.file_rename1 = prepare_paper() self.pdf2, self.si, self.doi, self.key2, self.newkey2, self.year, self.bibtex2, self.file_rename2 = prepare_paper2() bib = '\n'.join([self.bibtex1, self.bibtex2]) - open(self.somebib,'w').write(bib) - self.my = Biblio.newbib(self.mybib, '') + open(self.mybib,'w').write(self.bibtex1) + open(self.somebib,'w').write(self.bibtex2) + self.my = Biblio.load(self.mybib, '') - def test_addbib(self): - self.assertTrue(self.key1 not in [e['ID'] for e in self.my.db.entries]) + def test_addbib_method(self): + self.assertTrue(self.key1 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 test_addbib_cmd(self): + bib = Biblio.load(self.mybib, '') + self.assertEqual(len(bib.db.entries), 1) + self.assertEqual(bib.db.entries[0]['ID'], self.key1) + paperscmd(f'add {self.somebib} --bibtex {self.mybib}') + bib = Biblio.load(self.mybib, '') + self.assertEqual(len(bib.db.entries), 2) + self.assertEqual(bib.db.entries[0]['ID'], self.key1) + self.assertEqual(bib.db.entries[1]['ID'], self.key2) + + def test_addbib_cmd_dryrun(self): + bib = Biblio.load(self.mybib, '') + self.assertEqual(len(bib.db.entries), 1) + self.assertEqual(bib.db.entries[0]['ID'], self.key1) + paperscmd(f'add {self.somebib} --bibtex {self.mybib} --dry-run') + bib = Biblio.load(self.mybib, '') + self.assertEqual(len(bib.db.entries), 1) + self.assertEqual(bib.db.entries[0]['ID'], self.key1) + self.assertTrue(self.key2 not in [e['ID'] for e in self.my.db.entries]) + def tearDown(self): os.remove(self.mybib) os.remove(self.somebib) @@ -193,8 +213,7 @@ def test_adddir_pdf_cmd(self): def tearDown(self): os.remove(self.mybib) shutil.rmtree(self.somedir) - if os.path.exists('.papersconfig.json'): - os.remove('.papersconfig.json') + paperscmd(f'uninstall') @@ -340,7 +359,7 @@ def test_add_same_but_key_fails(self): def test_add_same_but_file(self): open(self.otherbib, 'w').write(self.bibtex_hasfile) - paperscmd(f'add {self.otherbib} --bibtex {self.mybib} -u') + paperscmd(f'add {self.otherbib} --bibtex {self.mybib} -u --relative-path') self.assertMultiLineEqual(open(self.mybib).read().strip(), self.bibtex_hasfile) # entries did not change diff --git a/tests/test_biblio.py b/tests/test_biblio.py new file mode 100644 index 0000000..cdb7c7a --- /dev/null +++ b/tests/test_biblio.py @@ -0,0 +1,21 @@ +import os +import unittest +import tempfile +from papers.bib import Biblio +from tests.common import prepare_paper + +class TestBiblio(unittest.TestCase): + + def setUp(self): + self.mybib = tempfile.mktemp(prefix='papers.bib') + # self.somebib = tempfile.mktemp(prefix='papers.somebib.bib') + self.pdf, self.doi, self.key, self.newkey, self.year, self.bibtex, self.file_rename = prepare_paper() + open(self.mybib,'w').write(self.bibtex) + self.biblio = Biblio.load(self.mybib, '') + + def test_bib_equal(self): + self.assertTrue(self.biblio == self.biblio) + + def tearDown(self): + os.remove(self.mybib) + # os.remove(self.somebib) \ No newline at end of file diff --git a/tests/test_misc.py b/tests/test_misc.py new file mode 100644 index 0000000..e69de29