@ -161,11 +161,19 @@ class CommandTestCase(fake_env.TestFakeFs):
def tearDown ( self ) :
def tearDown ( self ) :
pass
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 ) :
class DataCommandTestCase ( CommandTestCase ) :
""" Abstract TestCase intializing the fake filesystem and
""" Abstract TestCase intializing the fake filesystem and copying fake data. """
copying fake data .
"""
def setUp ( self , nsec_stat = True ) :
def setUp ( self , nsec_stat = True ) :
super ( DataCommandTestCase , self ) . setUp ( nsec_stat = nsec_stat )
super ( DataCommandTestCase , self ) . setUp ( nsec_stat = nsec_stat )
@ -182,8 +190,7 @@ class DataCommandTestCase(CommandTestCase):
class URLContentTestCase ( DataCommandTestCase ) :
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 ) :
def setUp ( self ) :
super ( URLContentTestCase , self ) . setUp ( )
super ( URLContentTestCase , self ) . setUp ( )
@ -209,6 +216,8 @@ class URLContentTestCase(DataCommandTestCase):
content . url_exists = self . _original_url_exist
content . url_exists = self . _original_url_exist
# Actual tests
# Actual tests
class TestAlone ( CommandTestCase ) :
class TestAlone ( CommandTestCase ) :
@ -1079,7 +1088,8 @@ class TestUsecase(DataCommandTestCase):
' pubs add -d data/no-ext data/pagerank.bib ' ,
' pubs add -d data/no-ext data/pagerank.bib ' ,
' pubs list ' ,
' pubs list ' ,
]
]
self . assertEqual ( correct , self . execute_cmds ( cmds , capture_output = True ) )
actual = self . execute_cmds ( cmds , capture_output = True )
self . assertEqual ( correct , actual )
@mock.patch ( ' pubs.apis.requests.get ' , side_effect = mock_requests . mock_requests_get )
@mock.patch ( ' pubs.apis.requests.get ' , side_effect = mock_requests . mock_requests_get )
def test_readme ( self , reqget ) :
def test_readme ( self , reqget ) :
@ -1145,5 +1155,23 @@ class TestCache(DataCommandTestCase):
self . assertEqual ( line1 , out [ 4 ] )
self . assertEqual ( line1 , out [ 4 ] )
class TestConfigChange ( DataCommandTestCase ) :
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 max_authors in [ 1 , 2 , 3 ] :
self . update_config ( { ' main ' : { ' max_authors ' : max_authors } } )
self . execute_cmds ( [ ( ' pubs list ' , None , line_al , None ) ] )
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 ) ] )
if __name__ == ' __main__ ' :
if __name__ == ' __main__ ' :
unittest . main ( verbosity = 2 )
unittest . main ( verbosity = 2 )