pubs/tests/test_bibstruct.py
Fabien C. Y. Benureau dc4e118c3c make utf8 citekeys possible in python 2.7. closes #28
This involved many changes, some side effects of the change include:
- remove of all `u"abc"` forms, in favor of
  `from __future__ import unicode_literals`. Their usage was
  inconsistent anyway, leading to problems when mixing with
  unicode content.
- improve the tests, to allow printing for usecase even when
  crashing. Should make future test easier. This is done with a
  rather hacky `StdIO` class in `p3`, but it works.
- for some reason, the skipped test for Python 2 seems to work
  now. While the previous point might seem related, it is not clear
  that this is actually the case.
2018-04-10 14:45:54 +09:00

39 lines
1023 B
Python

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import unittest
import copy
import dotdot
from pubs import bibstruct
import fixtures
class TestGenerateCitekey(unittest.TestCase):
def test_fails_on_empty_paper(self):
with self.assertRaises(ValueError):
bibstruct.generate_citekey(None)
def test_escapes_chars(self):
doe_bibentry = copy.deepcopy(fixtures.doe_bibentry)
citekey, bibdata = bibstruct.get_entry(doe_bibentry)
bibdata['author'] = ['Zôu\\@/ , John']
key = bibstruct.generate_citekey(doe_bibentry)
self.assertEqual(key, 'Zou2013')
def test_simple(self):
bibentry = copy.deepcopy(fixtures.doe_bibentry)
key = bibstruct.generate_citekey(bibentry)
self.assertEqual(key, 'Doe2013')
bibentry = copy.deepcopy(fixtures.franny_bibentry)
key = bibstruct.generate_citekey(bibentry)
self.assertEqual(key, 'Salinger1961')
if __name__ == '__main__':
unittest.main()