diff --git a/pubs/color.py b/pubs/color.py index d645b81..98d50c5 100644 --- a/pubs/color.py +++ b/pubs/color.py @@ -29,7 +29,7 @@ def dye(s, color=end, bold=False): return color + s + end _dye = dye -def _nodye(s, **kwargs): +def _nodye(s, *args, **kwargs): return s def setup(enable = True): @@ -44,4 +44,4 @@ undye_re = re.compile('\x1b\[[;\d]*[A-Za-z]') def undye(s): """Purge string s of color""" - return undye_re.sub('', s) \ No newline at end of file + return undye_re.sub('', s) diff --git a/pubs/pretty.py b/pubs/pretty.py index f7f7b9a..6d0a2c7 100644 --- a/pubs/pretty.py +++ b/pubs/pretty.py @@ -27,15 +27,15 @@ def bib_oneliner(bibentry): authors = short_authors(bibentry) journal = '' if 'journal' in bibentry: - journal = bibentry['journal']['name'] + journal = ' ' + bibentry['journal']['name'] 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), title=bibentry['title'], journal=color.dye(journal, color.yellow), - year='({})'.format(bibentry['year']) if 'year' in bibentry else '', + year=' ({})'.format(bibentry['year']) if 'year' in bibentry else '', ) diff --git a/tests/test_pretty.py b/tests/test_pretty.py index 0437358..b0ef690 100644 --- a/tests/test_pretty.py +++ b/tests/test_pretty.py @@ -5,17 +5,28 @@ import os import dotdot import fake_env -from pubs import endecoder, pretty +from pubs import endecoder, pretty, color from str_fixtures import bibtex_raw0 + class TestPretty(unittest.TestCase): + def setUp(self): + color.setup(enable=False) + def test_oneliner(self): + decoder = endecoder.EnDecoder() + bibdata = decoder.decode_bibdata(bibtex_raw0) + 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) - pretty.bib_oneliner(bibdata['Page99']) + 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__': unittest.main() diff --git a/tests/test_usecase.py b/tests/test_usecase.py index d1a14ea..b84d117 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -181,11 +181,11 @@ class TestUsecase(DataCommandTestCase): def test_first(self): correct = ['Initializing pubs in /paper_first.\n', '', - '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n', + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n', '', '', 'search network\n', - '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) search network\n' + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) search network\n' ] cmds = ['pubs init -p paper_first/', @@ -246,7 +246,7 @@ class TestUsecase(DataCommandTestCase): bib2 = re.sub('Lawrence Page', 'Lawrence Ridge', bib1) bib3 = re.sub('Page99', 'Ridge07', bib2) - line = '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' + line = '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' line1 = re.sub('1999', '2007', line) line2 = re.sub('Page,', 'Ridge,', line1) line3 = re.sub('Page99', 'Ridge07', line2)