diff --git a/dev_requirements.txt b/dev_requirements.txt index 1891f81..f6555a6 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -20,6 +20,8 @@ six # those are the additional packages required to run the tests pyfakefs certifi -ddt +# FIXME: remove strict version when https://github.com/datadriventests/ddt/issues/83 is fixed. +# (also remove in setup.py) +ddt==1.3.1 mock pytest # optional (python setup.py test works without it), but possible nonetheless diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index 74e5a46..9e9dd0d 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -147,7 +147,7 @@ def command(conf, args): doc_add = conf['main']['doc_add'] rp.push_paper(p) - ui.message('added to pubs:\n{}'.format(pretty.paper_oneliner(p, n_authors=conf['main']['n_authors']))) + ui.message('added to pubs:\n{}'.format(pretty.paper_oneliner(p, max_authors=conf['main']['max_authors']))) if docfile is not None: rp.push_doc(p.citekey, docfile, copy=(doc_add in ('copy', 'move'))) if doc_add == 'move' and content.content_type(docfile) != 'url': diff --git a/pubs/commands/list_cmd.py b/pubs/commands/list_cmd.py index a382544..24e533b 100644 --- a/pubs/commands/list_cmd.py +++ b/pubs/commands/list_cmd.py @@ -54,7 +54,7 @@ def command(conf, args): papers = sorted(papers, key=date_added) if len(papers) > 0: ui.message('\n'.join( - pretty.paper_oneliner(p, citekey_only=args.citekeys, n_authors=conf['main']['n_authors']) + pretty.paper_oneliner(p, citekey_only=args.citekeys, max_authors=conf['main']['max_authors']) for p in papers)) rp.close() diff --git a/pubs/commands/tag_cmd.py b/pubs/commands/tag_cmd.py index 90d6d9c..78357c3 100644 --- a/pubs/commands/tag_cmd.py +++ b/pubs/commands/tag_cmd.py @@ -117,7 +117,7 @@ def command(conf, args): len(p.tags.intersection(excluded)) == 0): papers_list.append(p) - ui.message('\n'.join(pretty.paper_oneliner(p, n_authors=conf['main']['n_authors']) + ui.message('\n'.join(pretty.paper_oneliner(p, max_authors=conf['main']['max_authors']) for p in papers_list)) rp.close() diff --git a/pubs/config/spec.py b/pubs/config/spec.py index 4aba92b..6921bae 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -29,7 +29,7 @@ note_extension = string(default='txt') # How many authors to display when displaying a citation. If there are more # authors, only the first author is diplayed followed by 'et al.'. -n_authors = integer(default=3) +max_authors = integer(default=3) # If true debug mode is on which means exceptions are not catched and # the full python stack is printed. diff --git a/pubs/pretty.py b/pubs/pretty.py index 369c3e4..6b12fb6 100644 --- a/pubs/pretty.py +++ b/pubs/pretty.py @@ -23,30 +23,24 @@ def person_repr(p): ' '.join(p.lineage(abbr=True))] if s) -def short_authors(bibdata, n_authors=3): +def short_authors(bibdata, max_authors=3): """ - :param n_authors: number of authors to display completely. Additional authors will be + :param max_authors: number of authors to display completely. Additional authors will be represented by 'et al.'. """ try: authors = [p for p in bibdata['author']] - if 0 < n_authors < len(authors): + if 0 < max_authors < len(authors): authors_str = '{} et al.'.format(authors[0]) else: authors_str = ' and '.join(authors) - - # if n_authors > 0: - # authors = authors[:n_authors] - # authors_str = ' and '.join(authors) - # if 0 < n_authors < len(bibdata['author']): - # authors_str += ' et al.' return authors_str except KeyError: # When no author is defined return '' -def bib_oneliner(bibdata, n_authors=3): - authors = short_authors(bibdata, n_authors=n_authors) +def bib_oneliner(bibdata, max_authors=3): + authors = short_authors(bibdata, max_authors=max_authors) journal = '' if 'journal' in bibdata: journal = ' ' + bibdata['journal'] @@ -71,11 +65,11 @@ def bib_desc(bib_data): return s -def paper_oneliner(p, citekey_only=False, n_authors=3): +def paper_oneliner(p, citekey_only=False, max_authors=3): if citekey_only: return p.citekey else: - bibdesc = bib_oneliner(p.get_unicode_bibdata(), n_authors=n_authors) + bibdesc = bib_oneliner(p.get_unicode_bibdata(), max_authors=max_authors) doc_str = '' if p.docpath is not None: doc_extension = os.path.splitext(p.docpath)[1] diff --git a/pubs/utils.py b/pubs/utils.py index a7aceb1..9b93aa3 100644 --- a/pubs/utils.py +++ b/pubs/utils.py @@ -33,7 +33,7 @@ def resolve_citekey(repo, citekey, ui=None, exit_on_fail=True): "citekeys:".format(citekey)) for c in citekeys: p = repo.pull_paper(c) - ui.message(' {}'.format(pretty.paper_oneliner(p, n_authors=conf['main']['n_authors']))) + ui.message(' {}'.format(pretty.paper_oneliner(p, max_authors=conf['main']['max_authors']))) if exit_on_fail: ui.exit() return citekey diff --git a/setup.py b/setup.py index d7fe2dd..a8eb7de 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,7 @@ setup( ], test_suite='tests', - tests_require=['pyfakefs>=3.4', 'mock', 'ddt', 'certifi'], + tests_require=['pyfakefs>=3.4', 'mock', 'ddt==1.3.1', 'certifi'], # in order to avoid 'zipimport.ZipImportError: bad local file header' zip_safe=False, diff --git a/tests/test_pretty.py b/tests/test_pretty.py index cc9f4f4..b73edfd 100644 --- a/tests/test_pretty.py +++ b/tests/test_pretty.py @@ -28,15 +28,15 @@ class TestPretty(unittest.TestCase): line = 'Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web."' self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'])), line) - def test_oneliner_n_authors(self): + def test_oneliner_max_authors(self): decoder = endecoder.EnDecoder() bibdata = decoder.decode_bibdata(bibtex_raw0) - for n_authors in [1, 2, 3]: + for max_authors in [1, 2, 3]: line = 'Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999)' - self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'], n_authors=n_authors)), line) - for n_authors in [-1, 0, 4, 5, 10]: + self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'], max_authors=max_authors)), line) + for max_authors in [-1, 0, 4, 5, 10]: line = 'Page, Lawrence and Brin, Sergey and Motwani, Rajeev and Winograd, Terry "The PageRank Citation Ranking: Bringing Order to the Web." (1999)' - self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'], n_authors=n_authors)), line) + self.assertEqual(color.undye(pretty.bib_oneliner(bibdata['Page99'], max_authors=max_authors)), line) if __name__ == '__main__': unittest.main() diff --git a/tests/test_usecase.py b/tests/test_usecase.py index f213d11..891d9cc 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -1173,18 +1173,18 @@ class TestCache(DataCommandTestCase): class TestConfigChange(DataCommandTestCase): - def test_n_authors_default(self): + def test_max_authors_default(self): line_al = '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' line_full = '[Page99] Page, Lawrence and Brin, Sergey and Motwani, Rajeev and Winograd, Terry "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' self.execute_cmds(['pubs init', 'pubs add data/pagerank.bib']) - for n_authors in [1, 2, 3]: - self.update_config({'main': {'n_authors': n_authors}}) + for max_authors in [1, 2, 3]: + self.update_config({'main': {'max_authors': max_authors}}) self.execute_cmds([('pubs list', None, line_al, None)]) - for n_authors in [-1, 0, 4, 5, 10]: - self.update_config({'main': {'n_authors': n_authors}}) + for max_authors in [-1, 0, 4, 5, 10]: + self.update_config({'main': {'max_authors': max_authors}}) self.execute_cmds([('pubs list', None, line_full, None)])