From 82aad31e5dec1104266984c3429add2c7de9b8be Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Wed, 21 Feb 2018 13:55:24 +0900 Subject: [PATCH 1/4] test for common_string parsing --- tests/str_fixtures.py | 8 ++++++++ tests/test_endecoder.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/str_fixtures.py b/tests/str_fixtures.py index 2036943..03360b8 100644 --- a/tests/str_fixtures.py +++ b/tests/str_fixtures.py @@ -69,6 +69,14 @@ bibtex_no_citekey = """@Manual{, } """ +bibtex_month= """@inproceedings{Goyal2017, + author = {Goyal, Anirudh and Sordoni, Alessandro and C{\^{o}}t{\'{e}}, Marc-Alexandre and Ke, Nan Rosemary and Bengio, Yoshua}, + title = {Z-Forcing: Training Stochastic Recurrent Networks}, + year = {2017}, + month = dec, + pages = {6716--6726}, +} +""" sample_conf = """ [main] diff --git a/tests/test_endecoder.py b/tests/test_endecoder.py index 06aae45..27efe75 100644 --- a/tests/test_endecoder.py +++ b/tests/test_endecoder.py @@ -9,7 +9,7 @@ from pubs import endecoder from pubs.p3 import ustr from fixtures import dummy_metadata -from str_fixtures import bibtex_raw0, metadata_raw0, turing_bib +from str_fixtures import bibtex_raw0, metadata_raw0, turing_bib, bibtex_month def compare_yaml_str(s1, s2): @@ -35,6 +35,7 @@ class TestEnDecode(unittest.TestCase): self.assertIsInstance(data, ustr) def test_endecode_bibtex(self): + """Test that multiple encode/decode step preserve data""" decoder = endecoder.EnDecoder() entry = decoder.decode_bibdata(bibtex_raw0) @@ -51,6 +52,14 @@ class TestEnDecode(unittest.TestCase): self.assertEqual(bibraw1, bibraw2) + def test_endecode_bibtex(self): + """Test if `month=dec` is correctly recognized and transformed into + `month={December}`""" + decoder = endecoder.EnDecoder() + entry = decoder.decode_bibdata(bibtex_month)['Goyal2017'] + + self.assertEqual(entry['month'], 'December') + def test_endecode_bibtex_editor(self): decoder = endecoder.EnDecoder() entry = decoder.decode_bibdata(turing_bib) From adbeb7f2b3116e228373a0ae09ade6b547eb13f6 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Wed, 21 Feb 2018 14:05:47 +0900 Subject: [PATCH 2/4] activating common strings by default in parser; fixes #122 --- pubs/endecoder.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pubs/endecoder.py b/pubs/endecoder.py index 321eff4..bf4a77a 100644 --- a/pubs/endecoder.py +++ b/pubs/endecoder.py @@ -115,11 +115,12 @@ class EnDecoder(object): try: try: entries = bp.bparser.BibTexParser( - bibdata, homogenize_fields=True, - customization=customizations).get_entry_dict() + bibdata, common_strings=True, + customization=customizations, + homogenize_fields=True).get_entry_dict() except TypeError: entries = bp.bparser.BibTexParser( - bibdata, + bibdata, common_strings=True, customization=customizations).get_entry_dict() # Remove id from bibtexparser attribute which is stored as citekey From 596ea81a34d8029d413b2f86f0232a216ff6f5b6 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Wed, 21 Feb 2018 14:23:47 +0900 Subject: [PATCH 3/4] fix dependency to bibtexparser Under certain circumstances, when installing bibtexparser 1.0.1 release in develop mode, it can be recognized as bibtexparser 1.0 by the pkg_resource module, preventing pubs to execute. This is obviously very bad. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5559148..62a9d3f 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ setup( ], }, - install_requires=['pyyaml', 'bibtexparser>=1.0.1', 'python-dateutil', 'requests', + install_requires=['pyyaml', 'bibtexparser>=1.0', 'python-dateutil', 'requests', 'configobj', 'beautifulsoup4'], # to be made optional? tests_require=['pyfakefs>=2.7'], From 3e376e2d8b336d9cc2c24d4f349f219aa9043b76 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Tue, 27 Feb 2018 13:18:55 +0900 Subject: [PATCH 4/4] remove obsolete exception catching --- pubs/endecoder.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pubs/endecoder.py b/pubs/endecoder.py index bf4a77a..5f75397 100644 --- a/pubs/endecoder.py +++ b/pubs/endecoder.py @@ -113,15 +113,10 @@ class EnDecoder(object): def decode_bibdata(self, bibdata): """""" try: - try: - entries = bp.bparser.BibTexParser( - bibdata, common_strings=True, - customization=customizations, - homogenize_fields=True).get_entry_dict() - except TypeError: - entries = bp.bparser.BibTexParser( - bibdata, common_strings=True, - customization=customizations).get_entry_dict() + entries = bp.bparser.BibTexParser( + bibdata, common_strings=True, + customization=customizations, + homogenize_fields=True).get_entry_dict() # Remove id from bibtexparser attribute which is stored as citekey for e in entries: