Repository: sciunto-org/python-bibtexparser (python)

Issue:
Change default value of parser.homogenise_fields
Change default value of parser.homogenise_fields in bparser to be more conservative by default.

Also, check that some unittests exist to test this feature.

Add some comments in the tutorial.

Original bug report #93

Pull request:
Defaultvalue
Fixes #94. Unittest already implemented.

Patch:
diff --git a/CHANGELOG b/CHANGELOG
index 4096b55..bdeb337 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,8 @@ v0.XXX
 * ENH: we use pyparsing (#64) by Olivier Magin.
 * DOC: fix typos in tutorial
 * DOC: include docs/ in manifest
+* API: fix spelling "homogenize". Affects customization and bparser
+* API: BibtexParser: homogenize_fields is now False by default (#94)
 
 v0.6.2
 ======
diff --git a/bibtexparser/bparser.py b/bibtexparser/bparser.py
index e68f358..ac21a2f 100644
--- a/bibtexparser/bparser.py
+++ b/bibtexparser/bparser.py
@@ -42,7 +42,7 @@ class BibTexParser(object):
 
         parser = BibTexParser()
         parser.ignore_nonstandard_types = False
-        parser.homogenise_fields = False
+        parser.homogenize_fields = False
         bib_database = bibtexparser.loads(bibtex_str, parser)
 
     """
@@ -63,7 +63,7 @@ class BibTexParser(object):
     def __init__(self, data=None,
                  customization=None,
                  ignore_nonstandard_types=True,
-                 homogenise_fields=True,
+                 homogenize_fields=False,
                  common_strings=False):
         """
         Creates a parser for rading BibTeX files
@@ -86,10 +86,10 @@ class BibTexParser(object):
         #: Default: `True`.
         self.ignore_nonstandard_types = ignore_nonstandard_types
 
-        #: Sanitise BibTeX field names, for example change `url` to `link` etc.
+        #: Sanitize BibTeX field names, for example change `url` to `link` etc.
         #: Field names are always converted to lowercase names.
-        #: Default: `True`.
-        self.homogenise_fields = homogenise_fields
+        #: Default: `False`.
+        self.homogenize_fields = homogenize_fields
 
         # On some sample data files, the character encoding detection simply
         # hangs We are going to default to utf8, and mandate it.
@@ -253,14 +253,14 @@ class BibTexParser(object):
             return key
 
     def _clean_field_key(self, key):
-        """ Clean a bibtex field key and homogeneize alternative forms.
+        """ Clean a bibtex field key and homogenize alternative forms.
 
         :param key: a key
         :type key: string
         :returns: string -- value
         """
         key = self._clean_key(key)
-        if self.homogenise_fields:
+        if self.homogenize_fields:
             if key in list(self.alt_dict.keys()):
                 key = self.alt_dict[key]
         return key
@@ -273,7 +273,7 @@ class BibTexParser(object):
         :type entry_type: string
         :param entry_id: the entry bibid
         :type entry_id: string
-        :param fields: the fileds and values
+        :param fields: the fields and values
         :type fields: dictionary
         :returns: string -- value
         """
diff --git a/bibtexparser/customization.py b/bibtexparser/customization.py
index 1ae93c4..7cbb3c4 100644
--- a/bibtexparser/customization.py
+++ b/bibtexparser/customization.py
@@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
 
 __all__ = ['getnames', 'author', 'editor', 'journal', 'keyword', 'link',
            'page_double_hyphen', 'doi', 'type', 'convert_to_unicode',
-           'homogeneize_latex_encoding']
+           'homogenize_latex_encoding']
 
 
 def getnames(names):
@@ -230,9 +230,9 @@ def convert_to_unicode(record):
     return record
 
 
-def homogeneize_latex_encoding(record):
+def homogenize_latex_encoding(record):
     """
-    Homogeneize the latex enconding style for bibtex
+    Homogenize the latex enconding style for bibtex
 
     This function is experimental.
 
diff --git a/docs/source/tutorial.rst b/docs/source/tutorial.rst
index 3cc9552..c50d1fa 100644
--- a/docs/source/tutorial.rst
+++ b/docs/source/tutorial.rst
@@ -263,11 +263,11 @@ They are sometimes coded like this ``\'{e}`` but this is not the correct way, ``
 
     import bibtexparser
     from bibtexparser.bparser import BibTexParser
-    from bibtexparser.customization import homogeneize_latex_encoding
+    from bibtexparser.customization import homogenize_latex_encoding
 
     with open('bibtex.bib') as bibtex_file:
         parser = BibTexParser()
-        parser.customization = homogeneize_latex_encoding
+        parser.customization = homogenize_latex_encoding
         bib_database = bibtexparser.load(bibtex_file, parser=parser)
         print(bib_database.entries)
 


Test patch:
diff --git a/bibtexparser/tests/test_bparser.py b/bibtexparser/tests/test_bparser.py
index c3e47af..8918df5 100644
--- a/bibtexparser/tests/test_bparser.py
+++ b/bibtexparser/tests/test_bparser.py
@@ -38,7 +38,7 @@ def customizations_latex(record):
     :returns: -- customized record
     """
 
-    record = homogeneize_latex_encoding(record)
+    record = homogenize_latex_encoding(record)
     record = type(record)
     record = author(record)
     record = editor(record)
@@ -176,14 +176,14 @@ class TestBibtexParserList(unittest.TestCase):
     def test_article_cust_order(self):
         def cust(record):
             record = customization.page_double_hyphen(record)
-            record = customization.homogeneize_latex_encoding(record)
+            record = customization.homogenize_latex_encoding(record)
             record = customization.author(record)
             return record
 
         def cust2(record):
             record = customization.author(record)
             record = customization.page_double_hyphen(record)
-            record = customization.homogeneize_latex_encoding(record)
+            record = customization.homogenize_latex_encoding(record)
             return record
 
         with open('bibtexparser/tests/data/multiple_entries.bib', 'r') as bibfile:
@@ -398,7 +398,7 @@ class TestBibtexParserList(unittest.TestCase):
         with codecs.open('bibtexparser/tests/data/traps.bib', 'r', 'utf-8') as bibfile:
             bib = BibTexParser(bibfile.read())
             res = bib.get_entry_list()
-            expected = [{'keyword': 'keyword1, keyword2',
+            expected = [{'keywords': 'keyword1, keyword2',
                          'ENTRYTYPE': 'article',
                          'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french érudit word',
                          'year': '2013',
@@ -463,37 +463,37 @@ class TestBibtexParserList(unittest.TestCase):
         with codecs.open('bibtexparser/tests/data/encoding.bib', 'r', 'utf-8') as bibfile:
             bib = BibTexParser(bibfile.read())
             res = bib.get_entry_list()
-            expected = [{'keyword': 'keyword1, keyword2',
-                              'ENTRYTYPE': 'article',
-                              'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french érudit word',
-                              'year': '2013',
-                              'journal': 'Elémentaire',
-                              'ID': 'Cesar_2013',
-                              'pages': '12-23',
-                              'title': 'An amazing title: à',
-                              'comments': 'A comment',
-                              'author': 'Jean César',
-                              'volume': '12',
-                              'month': 'jan'
+            expected = [{'keywords': 'keyword1, keyword2',
+                         'ENTRYTYPE': 'article',
+                         'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french érudit word',
+                         'year': '2013',
+                         'journal': 'Elémentaire',
+                         'ID': 'Cesar_2013',
+                         'pages': '12-23',
+                         'title': 'An amazing title: à',
+                         'comments': 'A comment',
+                         'author': 'Jean César',
+                         'volume': '12',
+                         'month': 'jan'
                          }]
         self.assertEqual(res, expected)
 
-    def test_encoding_with_homogeneize(self):
+    def test_encoding_with_homogenize(self):
         with codecs.open('bibtexparser/tests/data/encoding.bib', 'r', 'utf-8') as bibfile:
-            bib = BibTexParser(bibfile.read(), customization=homogeneize_latex_encoding)
+            bib = BibTexParser(bibfile.read(), customization=homogenize_latex_encoding)
             res = bib.get_entry_list()
-            expected = [{'keyword': 'keyword1, keyword2',
-                              'ENTRYTYPE': 'article',
-                              'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french {\\\'e}rudit word',
-                              'year': '2013',
-                              'journal': 'El{\\\'e}mentaire',
-                              'ID': 'Cesar_2013',
-                              'pages': '12-23',
-                              'title': '{A}n amazing title: {\\`a}',
-                              'comments': 'A comment',
-                              'author': 'Jean C{\\\'e}sar',
-                              'volume': '12',
-                              'month': 'jan'
+            expected = [{'keywords': 'keyword1, keyword2',
+                         'ENTRYTYPE': 'article',
+                         'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french {\\\'e}rudit word',
+                         'year': '2013',
+                         'journal': 'El{\\\'e}mentaire',
+                         'ID': 'Cesar_2013',
+                         'pages': '12-23',
+                         'title': '{A}n amazing title: {\\`a}',
+                         'comments': 'A comment',
+                         'author': 'Jean C{\\\'e}sar',
+                         'volume': '12',
+                         'month': 'jan'
                          }]
         self.assertEqual(res, expected)
 
diff --git a/bibtexparser/tests/test_customization.py b/bibtexparser/tests/test_customization.py
index b0c4752..7587d5e 100644
--- a/bibtexparser/tests/test_customization.py
+++ b/bibtexparser/tests/test_customization.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import unittest
 
-from bibtexparser.customization import getnames, convert_to_unicode, homogeneize_latex_encoding, page_double_hyphen, keyword
+from bibtexparser.customization import getnames, convert_to_unicode, homogenize_latex_encoding, page_double_hyphen, keyword
 
 
 class TestBibtexParserMethod(unittest.TestCase):
@@ -88,11 +88,11 @@ class TestBibtexParserMethod(unittest.TestCase):
         self.assertEqual(result, expected)
 
     ###########
-    # homogeneize
+    # homogenize
     ###########
-    def test_homogeneize(self):
+    def test_homogenize(self):
         record = {'toto': 'à {\`a} \`{a}'}
-        result = homogeneize_latex_encoding(record)
+        result = homogenize_latex_encoding(record)
         expected = {'toto': '{\`a} {\`a} {\`a}'}
         self.assertEqual(result, expected)
 
diff --git a/bibtexparser/tests/test_homogenise_fields.py b/bibtexparser/tests/test_homogenise_fields.py
index 4d0bbbb..5edcdd5 100644
--- a/bibtexparser/tests/test_homogenise_fields.py
+++ b/bibtexparser/tests/test_homogenise_fields.py
@@ -2,24 +2,24 @@ import unittest
 from bibtexparser.bparser import BibTexParser
 
 
-class TestHomogeniseFields(unittest.TestCase):
-    def test_homogenise_default(self):
+class TestHomogenizeFields(unittest.TestCase):
+    def test_homogenize_default(self):
         with open('bibtexparser/tests/data/website.bib', 'r') as bibfile:
             bib = BibTexParser(bibfile.read())
             entries = bib.get_entry_list()
-            self.assertIn('link', entries[0])
-            self.assertNotIn('url', entries[0])
+            self.assertNotIn('link', entries[0])
+            self.assertIn('url', entries[0])
 
-    def test_homogenise_on(self):
+    def test_homogenize_on(self):
         with open('bibtexparser/tests/data/website.bib', 'r') as bibfile:
-            bib = BibTexParser(bibfile.read(), homogenise_fields=True)
+            bib = BibTexParser(bibfile.read(), homogenize_fields=True)
             entries = bib.get_entry_list()
             self.assertIn('link', entries[0])
             self.assertNotIn('url', entries[0])
 
-    def test_homogenise_off(self):
+    def test_homogenize_off(self):
         with open('bibtexparser/tests/data/website.bib', 'r') as bibfile:
-            bib = BibTexParser(bibfile.read(), homogenise_fields=False)
+            bib = BibTexParser(bibfile.read(), homogenize_fields=False)
             entries = bib.get_entry_list()
             self.assertNotIn('link', entries[0])
             self.assertIn('url', entries[0])