Repository: pubs/pubs (language: python)

Issue:
Support field name "type"
Biblatex has an entry type `thesis` where you "use the `type` field to specify the type of thesis."

Pubs removes that field when specified, leaving an invalid entry because `type` is a required field for `thesis`. I think
https://github.com/pubs/pubs/blob/89429a8c24d0aef444de614f2a102feeb14b615f/pubs/bibstruct.py#L10
should use `'ENTRYTYPE'` instead, just like bibtexparser. See https://github.com/sciunto-org/python-bibtexparser/pull/42 and https://github.com/sciunto-org/python-bibtexparser/pull/53.


Discussion / hints:
Thanks @dotlambda  for reporting this. `type` is indeed a valid field name. (I am not sure `thesis` is a correct entry type, as far as I know `phdthesis` and `mastersthesis` were the sandard ones, but that does not matter here.)

Fix patch:
diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py
index a8312b0..d3e6614 100644
--- a/pubs/bibstruct.py
+++ b/pubs/bibstruct.py
@@ -7,7 +7,7 @@
 
 # Citekey stuff
 
-TYPE_KEY = 'type'
+TYPE_KEY = 'ENTRYTYPE'
 
 CONTROL_CHARS = ''.join(map(uchr, list(range(0, 32)) + list(range(127, 160))))
 CITEKEY_FORBIDDEN_CHARS = '@\'\\,#}{~%/ '  # '/' is OK for bibtex but forbidden


Test patch:
diff --git a/tests/test_endecoder.py b/tests/test_endecoder.py
index d9ade7f..858213f 100644
--- a/tests/test_endecoder.py
+++ b/tests/test_endecoder.py
@@ -57,6 +57,12 @@ def test_endecode_bibtex(self):
 
         self.assertEqual(bibraw1, bibraw2)
 
+    def test_decode_bibtex_preserves_type_field(self):
+        """Test that multiple encode/decode step preserve data"""
+        decoder = endecoder.EnDecoder()
+        entry = decoder.decode_bibdata(bibtex_raw0)
+        self.assertEqual(entry['Page99']['type'], "technical report")
+
     def test_endecode_bibtex_BOM(self):
         """Test that bibtexparser if fine with BOM-prefixed data"""
         decoder = endecoder.EnDecoder()