Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import shutil
import subprocess as sp
import tempfile
import unittest
from pathlib import Path

import bibtexparser
Expand Down
20 changes: 15 additions & 5 deletions tests/test_biblio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@
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.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, '')
(
self.pdf,
self.doi,
self.key,
self.newkey,
self.year,
self.bibtex,
self.file_rename,
) = prepare_paper()
with open(self.mybib, "w") as the_file:
the_file.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)
# os.remove(self.somebib)
35 changes: 18 additions & 17 deletions tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
class TestBibtexFileEntry(unittest.TestCase):

def test_parse_file(self):
file = parse_file('file.pdf:/path/to/file.pdf:pdf')
self.assertEqual(file, ['/path/to/file.pdf'])
file = parse_file(':/path/to/file.pdf:pdf')
self.assertEqual(file, ['/path/to/file.pdf'])
file = parse_file('/path/to/file.pdf:pdf')
self.assertEqual(file, ['/path/to/file.pdf'])
file = parse_file('/path/to/file.pdf')
self.assertEqual(file, ['/path/to/file.pdf'])
file = parse_file(':/path/to/file.pdf:')
self.assertEqual(file, ['/path/to/file.pdf'])

the_file = parse_file("file.pdf:/path/to/file.pdf:pdf")
self.assertEqual(the_file, ["/path/to/file.pdf"])
the_file = parse_file(":/path/to/file.pdf:pdf")
self.assertEqual(the_file, ["/path/to/file.pdf"])
the_file = parse_file("/path/to/file.pdf:pdf")
self.assertEqual(the_file, ["/path/to/file.pdf"])
the_file = parse_file("/path/to/file.pdf")
self.assertEqual(the_file, ["/path/to/file.pdf"])
the_file = parse_file(":/path/to/file.pdf:")
self.assertEqual(the_file, ["/path/to/file.pdf"])
del the_file

def test_parse_files(self):
files = parse_file(':/path/to/file1.pdf:pdf;:/path/to/file2.pdf:pdf')
Expand All @@ -40,13 +40,14 @@ def test_parse_file_invalid_format_raises(self):


def test_format_file(self):
field = format_file(['/path/to/file.pdf'])
self.assertEqual(field, ':/path/to/file.pdf:pdf')

field = format_file(["/path/to/file.pdf"])
self.assertEqual(field, ":/path/to/file.pdf:pdf")
del field

def test_format_files(self):
field = format_file(['/path/to/file1.pdf','/path/to/file2.pdf'])
self.assertEqual(field, ':/path/to/file1.pdf:pdf;:/path/to/file2.pdf:pdf')
field = format_file(["/path/to/file1.pdf", "/path/to/file2.pdf"])
self.assertEqual(field, ":/path/to/file1.pdf:pdf;:/path/to/file2.pdf:pdf")
del field

def test_format_file_relative_to_root(self):
"""format_file with relative_to=os.sep uses abspath"""
Expand Down Expand Up @@ -163,4 +164,4 @@ class TestUnicode(BibTest):


class TestUnicodeVsLatexEncoding(BibTest):
pass
pass
16 changes: 13 additions & 3 deletions tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@
class TestSimple(unittest.TestCase):

def setUp(self):
self.pdf, self.doi, self.key, self.newkey, self.year, self.bibtex, self.file_rename = prepare_paper()
(
self.pdf,
self.doi,
self.key,
self.newkey,
self.year,
self.bibtex,
self.file_rename,
) = prepare_paper()
self.assertTrue(os.path.exists(self.pdf))

def test_doi(self):
self.assertEqual(paperscmd(f'doi {self.pdf}', sp_cmd='check_output').strip(), self.doi)
self.assertEqual(
paperscmd(f"doi {self.pdf}", sp_cmd="check_output").strip(), self.doi
)

def test_fetch(self):
bibtexs = paperscmd(f'fetch {self.doi}', sp_cmd='check_output').strip()
Expand All @@ -22,4 +32,4 @@ def test_fetch(self):
self.assertEqual([dict(e.items()) for e in db1.entries], [dict(e.items()) for e in db2.entries])

def test_fetch_scholar(self):
extract_pdf_metadata(self.pdf, scholar=True)
extract_pdf_metadata(self.pdf, scholar=True)
21 changes: 13 additions & 8 deletions tests/test_filecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
"""
import os
import shutil
import subprocess as sp
import tempfile
import unittest
from pathlib import Path

import bibtexparser

from papers.bib import Biblio
from papers.entries import get_entry_val
Expand All @@ -19,7 +14,15 @@
class TestFileCheck(BibTest):

def setUp(self):
self.pdf, self.doi, self.key, self.newkey, self.year, self.bibtex, self.file_rename = prepare_paper()
(
self.pdf,
self.doi,
self.key,
self.newkey,
self.year,
self.bibtex,
self.file_rename,
) = prepare_paper()
self.assertTrue(os.path.exists(self.pdf))
self.temp_dir = tempfile.TemporaryDirectory()
self.workdir = self.temp_dir.name
Expand All @@ -32,7 +35,8 @@ def papers(self, cmd):
return paperscmd(cmd, cwd=self.workdir)

def test_filecheck_rename(self):
paperscmd(f"""add --bibtex {self.mybib} --filesdir {self.filesdir} {self.pdf} --doi {self.doi} << EOF
paperscmd(
f"""add --bibtex {self.mybib} --filesdir {self.filesdir} {self.pdf} --doi {self.doi} << EOF
u
EOF""", cwd=self.workdir)
file_rename = os.path.join(self.filesdir, self.file_rename)
Expand All @@ -44,6 +48,7 @@ def test_filecheck_rename(self):
biblio = Biblio.load(self.mybib, '')
e = next(ent for ent in biblio.entries if get_entry_val(ent, 'ID', '').lower() == self.key.lower())
files = biblio.get_files(e)
del biblio
self.assertTrue(len(files) == 1)
self.assertEqual(files[0], os.path.abspath(file_rename))

Expand Down Expand Up @@ -99,4 +104,4 @@ def test_filecheck_clean_filesdir(self):
self.papers('uninstall')

def tearDown(self):
self.temp_dir.cleanup()
self.temp_dir.cleanup()