From ad85fe9df87a512465bcd500896ff972433c3356 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Tue, 5 May 2020 00:50:37 +0900 Subject: [PATCH] add usecase test for n_authors --- tests/test_usecase.py | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 5004919..faa4bbe 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -25,8 +25,8 @@ import fixtures # makes the tests very noisy -PRINT_OUTPUT = False -CAPTURE_OUTPUT = True +PRINT_OUTPUT = True +CAPTURE_OUTPUT = False class FakeSystemExit(Exception): @@ -161,11 +161,19 @@ class CommandTestCase(fake_env.TestFakeFs): def tearDown(self): pass + def update_config(self, config_update, path=None): + """Allow to set the config parameters. Must have done a `pubs init` beforehand.""" + if path is None: + path = self.default_conf_path + cfg = conf.load_conf(path=path) + for section, section_update in config_update.items(): + cfg[section].update(section_update) + conf.save_conf(cfg, path=path) + + class DataCommandTestCase(CommandTestCase): - """Abstract TestCase intializing the fake filesystem and - copying fake data. - """ + """Abstract TestCase intializing the fake filesystem and copying fake data.""" def setUp(self, nsec_stat=True): super(DataCommandTestCase, self).setUp(nsec_stat=nsec_stat) @@ -182,8 +190,7 @@ class DataCommandTestCase(CommandTestCase): class URLContentTestCase(DataCommandTestCase): - """Mocks access to online files by using files in data directory. - """ + """Mocks access to online files by using files in data directory.""" def setUp(self): super(URLContentTestCase, self).setUp() @@ -209,6 +216,8 @@ class URLContentTestCase(DataCommandTestCase): content.url_exists = self._original_url_exist + + # Actual tests class TestAlone(CommandTestCase): @@ -1146,5 +1155,23 @@ class TestCache(DataCommandTestCase): self.assertEqual(line1, out[4]) +class TestConfigChange(DataCommandTestCase): + + def test_n_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}}) + 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}}) + self.execute_cmds([('pubs list', None, line_full, None)]) + + + if __name__ == '__main__': unittest.main(verbosity=2)