FIX bug in color when color not activated.
_nodye does not support being called with arg instead of kwarg. Also improves pretty print and adds related tests.
This commit is contained in:
parent
3e8b780e84
commit
b71b602a50
@ -29,7 +29,7 @@ def dye(s, color=end, bold=False):
|
|||||||
return color + s + end
|
return color + s + end
|
||||||
|
|
||||||
_dye = dye
|
_dye = dye
|
||||||
def _nodye(s, **kwargs):
|
def _nodye(s, *args, **kwargs):
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def setup(enable = True):
|
def setup(enable = True):
|
||||||
|
@ -27,9 +27,9 @@ def bib_oneliner(bibentry):
|
|||||||
authors = short_authors(bibentry)
|
authors = short_authors(bibentry)
|
||||||
journal = ''
|
journal = ''
|
||||||
if 'journal' in bibentry:
|
if 'journal' in bibentry:
|
||||||
journal = bibentry['journal']['name']
|
journal = ' ' + bibentry['journal']['name']
|
||||||
elif bibentry['type'] == 'inproceedings':
|
elif bibentry['type'] == 'inproceedings':
|
||||||
journal = bibentry.get('booktitle', '')
|
journal = ' ' + bibentry.get('booktitle', '')
|
||||||
|
|
||||||
return u'{authors} \"{title}\"{journal}{year}'.format(
|
return u'{authors} \"{title}\"{journal}{year}'.format(
|
||||||
authors=color.dye(authors, color.cyan),
|
authors=color.dye(authors, color.cyan),
|
||||||
|
@ -5,17 +5,28 @@ import os
|
|||||||
import dotdot
|
import dotdot
|
||||||
import fake_env
|
import fake_env
|
||||||
|
|
||||||
from pubs import endecoder, pretty
|
from pubs import endecoder, pretty, color
|
||||||
|
|
||||||
from str_fixtures import bibtex_raw0
|
from str_fixtures import bibtex_raw0
|
||||||
|
|
||||||
|
|
||||||
class TestPretty(unittest.TestCase):
|
class TestPretty(unittest.TestCase):
|
||||||
|
|
||||||
def test_oneliner(self):
|
def setUp(self):
|
||||||
|
color.setup(enable=False)
|
||||||
|
|
||||||
|
def test_oneliner(self):
|
||||||
decoder = endecoder.EnDecoder()
|
decoder = endecoder.EnDecoder()
|
||||||
bibdata = decoder.decode_bibdata(bibtex_raw0)
|
bibdata = decoder.decode_bibdata(bibtex_raw0)
|
||||||
pretty.bib_oneliner(bibdata['Page99'])
|
line = u'Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999)'
|
||||||
|
self.assertEqual(pretty.bib_oneliner(bibdata['Page99']), line)
|
||||||
|
|
||||||
|
def test_oneliner_no_year(self):
|
||||||
|
decoder = endecoder.EnDecoder()
|
||||||
|
bibdata = decoder.decode_bibdata(bibtex_raw0)
|
||||||
|
bibdata['Page99'].pop('year')
|
||||||
|
line = u'Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web."'
|
||||||
|
self.assertEqual(pretty.bib_oneliner(bibdata['Page99']), line)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user