@ -7,8 +7,7 @@ import os
import dotdot
import fake_env
from pubs import pubs_cmd
from pubs import color , content , filebroker , uis , p3 , endecoder
from pubs import pubs_cmd , update , color , content , filebroker , uis , p3 , endecoder
from pubs . config import conf
import configobj
@ -58,7 +57,7 @@ class CommandTestCase(unittest.TestCase):
maxDiff = 1000000
def setUp ( self ) :
self . fs = fake_env . create_fake_fs ( [ content , filebroker , conf , init_cmd , import_cmd , configobj ])
self . fs = fake_env . create_fake_fs ( [ content , filebroker , conf , init_cmd , import_cmd , configobj , update ])
self . default_pubs_dir = self . fs [ ' os ' ] . path . expanduser ( ' ~/.pubs ' )
def execute_cmds ( self , cmds , capture_output = CAPTURE_OUTPUT ) :
@ -118,7 +117,7 @@ class DataCommandTestCase(CommandTestCase):
"""
def setUp ( self ) :
CommandTestCase. setUp ( self )
super ( Data CommandTestCase, self ) . setUp ( )
fake_env . copy_dir ( self . fs , os . path . join ( os . path . dirname ( __file__ ) , ' data ' ) , ' data ' )
@ -251,6 +250,76 @@ class TestList(DataCommandTestCase):
self . assertEqual ( 0 + 1 , len ( outs [ - 1 ] . split ( ' \n ' ) ) )
class TestTag ( DataCommandTestCase ) :
def setUp ( self ) :
super ( TestTag , self ) . setUp ( )
init = [ ' pubs init ' ,
' pubs add data/pagerank.bib ' ,
' pubs add -k Turing1950 data/turing1950.bib ' ,
]
self . execute_cmds ( init )
def test_add_tag ( self ) :
cmds = [ ' pubs tag Page99 search ' ,
' pubs tag Turing1950 ai ' ,
' pubs list ' ,
]
correct = [ ' ' ,
' ' ,
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) | search \n ' +
' [Turing1950] Turing, Alan M " Computing machinery and intelligence " Mind (1950) | ai \n ' ,
]
out = self . execute_cmds ( cmds )
self . assertEqual ( out , correct )
def test_add_tags ( self ) :
""" Adds several tags at once.
Also checks that tags printed in alphabetic order .
"""
cmds = [ ' pubs tag Page99 search+network ' ,
' pubs list ' ,
]
correct = [ ' ' ,
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) | network,search \n ' +
' [Turing1950] Turing, Alan M " Computing machinery and intelligence " Mind (1950) \n ' ,
]
out = self . execute_cmds ( cmds )
self . assertEqual ( out , correct )
def test_remove_tag ( self ) :
cmds = [ ' pubs tag Page99 search+network ' ,
' pubs tag Page99 :network ' ,
' pubs list ' ,
]
correct = [ ' ' ,
' ' ,
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) | search \n ' +
' [Turing1950] Turing, Alan M " Computing machinery and intelligence " Mind (1950) \n ' ,
]
out = self . execute_cmds ( cmds )
self . assertEqual ( out , correct )
def test_add_remove_tag ( self ) :
cmds = [ ' pubs tag Page99 a ' ,
' pubs tag Page99 b-a ' ,
' pubs list ' ,
]
correct = [ ' ' ,
' ' ,
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) | b \n ' +
' [Turing1950] Turing, Alan M " Computing machinery and intelligence " Mind (1950) \n ' ,
]
out = self . execute_cmds ( cmds )
self . assertEqual ( out , correct )
def test_wrong_citekey ( self ) :
cmds = [ ' pubs tag Page999 a ' ,
]
with self . assertRaises ( SystemExit ) :
self . execute_cmds ( cmds )
class TestUsecase ( DataCommandTestCase ) :
def test_first ( self ) :