@ -437,6 +437,18 @@ class TestAdd(URLContentTestCase):
self . execute_cmds ( cmds )
self . execute_cmds ( cmds )
self . assertEqual ( cm . exception . code , 1 )
self . assertEqual ( cm . exception . code , 1 )
def test_add_excludes_bibtex_fields ( self ) :
self . execute_cmds ( [ ' pubs init ' ] )
config = conf . load_conf ( )
config [ ' main ' ] [ ' exclude_bibtex_fields ' ] = [ ' abstract ' , ' publisher ' ]
conf . save_conf ( config )
self . execute_cmds ( [ ' pubs add data/pagerank.bib ' ] )
with FakeFileOpen ( self . fs ) ( self . default_pubs_dir + ' /bib/Page99.bib ' , ' r ' ) as buf :
out = endecoder . EnDecoder ( ) . decode_bibdata ( buf . read ( ) )
for bib in out . values ( ) :
self . assertFalse ( ' abstract ' in bib or ' publisher ' in bib )
self . assertTrue ( ' title ' in bib and ' author ' in bib )
class TestList ( DataCommandTestCase ) :
class TestList ( DataCommandTestCase ) :
@ -590,7 +602,7 @@ class TestTag(DataCommandTestCase):
' pubs list ' ,
' pubs list ' ,
]
]
correct = [ ' ' ,
correct = [ ' ' ,
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) | network, search\n ' +
' [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 ' ,
' [Turing1950] Turing, Alan M " Computing machinery and intelligence " Mind (1950) \n ' ,
]
]
out = self . execute_cmds ( cmds )
out = self . execute_cmds ( cmds )
@ -738,9 +750,9 @@ class TestUsecase(DataCommandTestCase):
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) [pdf] \n ' ,
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) [pdf] \n ' ,
' \n ' ,
' \n ' ,
' ' ,
' ' ,
' network search\n ' ,
' network , search\n ' ,
' info: Assuming search to be a tag. \n '
' info: Assuming search to be a tag. \n '
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) [pdf] | network, search\n ' ,
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) [pdf] | network, search\n ' ,
]
]
cmds = [ ' pubs init -p /paper_first ' ,
cmds = [ ' pubs init -p /paper_first ' ,
@ -785,7 +797,7 @@ class TestUsecase(DataCommandTestCase):
' ' ,
' ' ,
' ' ,
' ' ,
' ' ,
' ' ,
' search network\n ' ,
' search , network\n ' ,
]
]
cmds = [ ' pubs init -p paper_first/ ' ,
cmds = [ ' pubs init -p paper_first/ ' ,
@ -798,7 +810,7 @@ class TestUsecase(DataCommandTestCase):
out = self . execute_cmds ( cmds )
out = self . execute_cmds ( cmds )
def clean ( s ) :
def clean ( s ) :
return set ( s . strip ( ) . split ( ' ' ) )
return set ( s . strip ( ) . split ( ' , ' ) )
self . assertEqual ( clean ( correct [ 2 ] ) , clean ( out [ 2 ] ) )
self . assertEqual ( clean ( correct [ 2 ] ) , clean ( out [ 2 ] ) )
self . assertEqual ( clean ( correct [ 4 ] ) , clean ( out [ 4 ] ) )
self . assertEqual ( clean ( correct [ 4 ] ) , clean ( out [ 4 ] ) )
@ -829,6 +841,22 @@ class TestUsecase(DataCommandTestCase):
]
]
self . execute_cmds ( cmds )
self . execute_cmds ( cmds )
def test_editor_excludes_bibtex_field ( self ) :
cmds = [ ' pubs init ' ,
' pubs add data/pagerank.bib ' ,
]
self . execute_cmds ( cmds )
config = conf . load_conf ( )
config [ ' main ' ] [ ' exclude_bibtex_fields ' ] = [ ' author ' ]
conf . save_conf ( config )
cmds = [ ( ' pubs edit Page99 ' , [ ' @misc { Page99, title= " TTT " , author= " auth " } ' , ' n ' ] ) ]
self . execute_cmds ( cmds )
with FakeFileOpen ( self . fs ) ( self . default_pubs_dir + ' /bib/Page99.bib ' , ' r ' ) as buf :
out = endecoder . EnDecoder ( ) . decode_bibdata ( buf . read ( ) )
for bib in out . values ( ) :
self . assertFalse ( ' author ' in bib )
self . assertTrue ( ' title ' in bib )
def test_add_aborts ( self ) :
def test_add_aborts ( self ) :
with self . assertRaises ( FakeSystemExit ) :
with self . assertRaises ( FakeSystemExit ) :
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,
@ -879,7 +907,7 @@ class TestUsecase(DataCommandTestCase):
meta = str_fixtures . turing_meta
meta = str_fixtures . turing_meta
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 ( ' \n ' , ' | AI, computer\n ' , line )
line1 = re . sub ( ' \n ' , ' | AI, computer\n ' , line )
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,
' pubs add data/pagerank.bib ' ,
' pubs add data/pagerank.bib ' ,
@ -908,6 +936,19 @@ class TestUsecase(DataCommandTestCase):
fixtures . page_bibentry , ignore_fields = [ ' author ' , ' title ' ] )
fixtures . page_bibentry , ignore_fields = [ ' author ' , ' title ' ] )
self . assertEqual ( outs [ 2 ] , expected + os . linesep )
self . assertEqual ( outs [ 2 ] , expected + os . linesep )
def test_export_excludes_bibtex_field ( self ) :
cmds = [ ' pubs init ' ,
' pubs add data/pagerank.bib '
]
self . execute_cmds ( cmds )
config = conf . load_conf ( )
config [ ' main ' ] [ ' exclude_bibtex_fields ' ] = [ ' url ' ]
conf . save_conf ( config )
outs = self . execute_cmds ( [ ' pubs export Page99 ' ] )
for bib in endecoder . EnDecoder ( ) . decode_bibdata ( outs [ 0 ] ) . values ( ) :
self . assertFalse ( ' url ' in bib )
self . assertTrue ( ' title ' in bib and ' author ' in bib )
def test_import ( self ) :
def test_import ( self ) :
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,
' pubs import data/ ' ,
' pubs import data/ ' ,
@ -970,6 +1011,18 @@ class TestUsecase(DataCommandTestCase):
outs = self . execute_cmds ( cmds )
outs = self . execute_cmds ( cmds )
self . assertEqual ( 1 + 1 , len ( outs [ - 1 ] . split ( ' \n ' ) ) )
self . assertEqual ( 1 + 1 , len ( outs [ - 1 ] . split ( ' \n ' ) ) )
def test_import_excludes_bibtex_field ( self ) :
self . execute_cmds ( [ ' pubs init ' ] )
config = conf . load_conf ( )
config [ ' main ' ] [ ' exclude_bibtex_fields ' ] = [ ' abstract ' ]
conf . save_conf ( config )
self . execute_cmds ( [ ' pubs import data/ Page99 ' ] )
with FakeFileOpen ( self . fs ) ( self . default_pubs_dir + ' /bib/Page99.bib ' , ' r ' ) as buf :
out = endecoder . EnDecoder ( ) . decode_bibdata ( buf . read ( ) )
for bib in out . values ( ) :
self . assertFalse ( ' abstract ' in bib )
self . assertTrue ( ' title ' in bib and ' author ' in bib )
def test_update ( self ) :
def test_update ( self ) :
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,
' pubs add data/pagerank.bib ' ,
' pubs add data/pagerank.bib ' ,