def test_to_bibtex(): papis.config.set('bibtex-journal-key', 'journal_abbrev') doc = from_data({'title': 'Hello', 'type': 'book', 'journal': 'jcp'}) doc.set_folder('path/to/superfolder') assert( to_bibtex(doc) == '@book{superfolder,\n journal = {jcp},\n title = {Hello},\n type = {book},\n}\n' ) doc['journal_abbrev'] = 'j' assert( to_bibtex(doc) == '@book{superfolder,\n journal = {j},\n title = {Hello},\n type = {book},\n}\n' ) del doc['title'] doc['ref'] = 'hello1992' assert( to_bibtex(doc) == '@book{hello1992,\n journal = {j},\n type = {book},\n}\n' )
def test_format_doc(): tests.setup_test_library() document = from_data(dict(author='Fulano', title='Something')) papis.config.utils.set('format-jinja2-enable', True) assert format_doc('{{doc["author"]}}{{doc["title"]}}', document) == \ 'FulanoSomething' assert format_doc( '{{doc["author"]}}{{doc["title"]}}{{doc["blahblah"]}}', document ) == 'FulanoSomething' papis.config.utils.set('format-jinja2-enable', False) assert format_doc('{doc[author]}{doc[title]}', document) == \ 'FulanoSomething' assert format_doc('{doc[author]}{doc[title]}{doc[blahblah]}', document) ==\ 'FulanoSomething' assert(format_doc( '{doc[author]}{doc[title]}{doc[blahblah]}', dict(title='hell')) == 'hell')
def test_to_bibtex() -> None: papis.config.set('bibtex-journal-key', 'journal_abbrev') doc = from_data({ 'title': 'Hello', 'author': 'Fernandez, Gilgamesh', 'year': "3200BCE", 'type': 'book', 'journal': 'jcp' }) doc.set_folder('path/to/superfolder') assert \ to_bibtex(doc) == \ ("@book{HelloFernan3200bce,\n" " author = {Fernandez, Gilgamesh},\n" " journal = {jcp},\n" " title = {Hello},\n" " type = {book},\n" " year = {3200BCE},\n" "}\n") doc['journal_abbrev'] = 'j' assert \ to_bibtex(doc) == \ ('@book{HelloFernan3200bce,\n' ' author = {Fernandez, Gilgamesh},\n' ' journal = {j},\n' ' title = {Hello},\n' ' type = {book},\n' ' year = {3200BCE},\n' '}\n') del doc['title'] doc['ref'] = 'hello1992' assert (to_bibtex(doc) == '@book{hello1992,\n' ' journal = {j},\n' ' author = {Fernandez, Gilgamesh},\n', ' type = {book},\n' ' year = {3200BCE},\n' '}\n')
def test_from_data() -> None: doc = from_data({'title': 'Hello World', 'author': 'turing'}) assert (isinstance(doc, Document))
def test_to_json() -> None: doc = from_data({'title': 'Hello World'}) assert (to_json(doc) == '{"title": "Hello World"}')