@ -29,7 +29,7 @@ class TestFakeInput(unittest.TestCase):
input = fake_env . FakeInput ( [ ' yes ' , ' no ' ] )
input = fake_env . FakeInput ( [ ' yes ' , ' no ' ] )
self . assertEqual ( input ( ) , ' yes ' )
self . assertEqual ( input ( ) , ' yes ' )
self . assertEqual ( input ( ) , ' no ' )
self . assertEqual ( input ( ) , ' no ' )
with self . assertRaises ( IndexError ) :
with self . assertRaises ( fake_env . FakeInput . UnexpectedInput ) :
input ( )
input ( )
def test_input2 ( self ) :
def test_input2 ( self ) :
@ -37,7 +37,7 @@ class TestFakeInput(unittest.TestCase):
other_input . as_global ( )
other_input . as_global ( )
self . assertEqual ( color . input ( ) , ' yes ' )
self . assertEqual ( color . input ( ) , ' yes ' )
self . assertEqual ( color . input ( ) , ' no ' )
self . assertEqual ( color . input ( ) , ' no ' )
with self . assertRaises ( IndexError ) :
with self . assertRaises ( fake_env . FakeInput . UnexpectedInput ) :
color . input ( )
color . input ( )
def test_editor_input ( self ) :
def test_editor_input ( self ) :
@ -46,7 +46,7 @@ class TestFakeInput(unittest.TestCase):
other_input . as_global ( )
other_input . as_global ( )
self . assertEqual ( content . editor_input ( ) , ' yes ' )
self . assertEqual ( content . editor_input ( ) , ' yes ' )
self . assertEqual ( content . editor_input ( ) , ' no ' )
self . assertEqual ( content . editor_input ( ) , ' no ' )
with self . assertRaises ( IndexError ) :
with self . assertRaises ( fake_env . FakeInput . UnexpectedInput ) :
color . input ( )
color . input ( )
@ -66,35 +66,41 @@ class CommandTestCase(unittest.TestCase):
In the latter case , the command is :
In the latter case , the command is :
1. a string reprensenting the command to execute
1. a string reprensenting the command to execute
2. the user inputs to feed to the command during execution
2. the user inputs to feed to the command during execution
3. the output expected , verified with assertEqual
3. the output expected , verified with assertEqual . Always captures
output in this case .
"""
"""
outs = [ ]
outs = [ ]
for cmd in cmds :
for cmd in cmds :
inputs = [ ]
output = None
actual_cmd = cmd
current_capture_output = capture_output
if not isinstance ( cmd , p3 . ustr ) :
if not isinstance ( cmd , p3 . ustr ) :
if len ( cmd ) == 2 :
actual_cmd = cmd [ 0 ]
input = fake_env . FakeInput ( cmd [ 1 ] , [ content , uis , p3 ] )
if len ( cmd ) == 2 : # Inputs provided
inputs = cmd [ 1 ]
if len ( cmd ) == 3 : # Expected output provided
current_capture_output = True
output = cmd [ 2 ]
# Always set fake input: test should not ask unexpected user input
input = fake_env . FakeInput ( inputs , [ content , uis , p3 ] )
input . as_global ( )
input . as_global ( )
try :
if capture_output :
if current_capture_output :
_ , stdout , stderr = fake_env . redirect ( pubs_cmd . execute ) ( cmd [ 0 ] . split ( ) )
_ , stdout , stderr = fake_env . redirect ( pubs_cmd . execute ) (
if len ( cmd ) == 3 and capture_output :
actual_cmd . split ( ) )
self . assertEqual ( stderr , ' ' )
actual_out = color . undye ( stdout )
actual_out = color . undye ( stdout )
correct_out = color . undye ( cmd [ 2 ] )
if output is not None :
correct_out = color . undye ( output )
self . assertEqual ( actual_out , correct_out )
self . assertEqual ( actual_out , correct_out )
outs . append ( color . undye ( actual_out ) )
else :
else :
pubs_cmd . execute ( cmd . split ( ) )
pubs_cmd . execute ( cmd . split ( ) )
except fake_env . FakeInput . UnexpectedInput :
else :
self . fail ( ' Unexpected input asked by command: {} . ' . format (
if capture_output :
actual_cmd ) )
assert p3 . isbasestr ( cmd )
_ , stdout , stderr = fake_env . redirect ( pubs_cmd . execute ) ( cmd . split ( ) )
else :
pubs_cmd . execute ( cmd . split ( ) )
if capture_output :
assert ( stderr == ' ' )
outs . append ( color . undye ( stdout ) )
if PRINT_OUTPUT :
if PRINT_OUTPUT :
print ( outs )
print ( outs )
return outs
return outs
@ -161,7 +167,7 @@ class TestAdd(DataCommandTestCase):
def test_add_doc_nocopy_does_not_copy ( self ) :
def test_add_doc_nocopy_does_not_copy ( self ) :
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,
' pubs add /data/pagerank.bib - C -d /data/pagerank.pdf' ,
' pubs add /data/pagerank.bib - -link -d /data/pagerank.pdf' ,
]
]
self . execute_cmds ( cmds )
self . execute_cmds ( cmds )
self . assertEqual ( self . fs [ ' os ' ] . listdir (
self . assertEqual ( self . fs [ ' os ' ] . listdir (
@ -186,10 +192,8 @@ class TestList(DataCommandTestCase):
' pubs list ' ,
' pubs list ' ,
]
]
outs = self . execute_cmds ( cmds )
outs = self . execute_cmds ( cmds )
print ( outs [ 1 ] . splitlines ( ) )
self . assertEqual ( 0 , len ( outs [ 1 ] . splitlines ( ) ) )
self . assertEquals ( 0 , len ( outs [ 1 ] . splitlines ( ) ) )
self . assertEqual ( 1 , len ( outs [ 3 ] . splitlines ( ) ) )
print ( outs [ 3 ] . splitlines ( ) )
self . assertEquals ( 1 , len ( outs [ 3 ] . splitlines ( ) ) )
def test_list_several_no_date ( self ) :
def test_list_several_no_date ( self ) :
self . execute_cmds ( [ ' pubs init -p /testrepo ' ] )
self . execute_cmds ( [ ' pubs init -p /testrepo ' ] )
@ -203,14 +207,11 @@ class TestList(DataCommandTestCase):
' pubs list ' ,
' pubs list ' ,
]
]
outs = self . execute_cmds ( cmds )
outs = self . execute_cmds ( cmds )
print ( outs [ 0 ] . splitlines ( ) )
self . assertEqual ( 4 , len ( outs [ 0 ] . splitlines ( ) ) )
self . assertEquals ( 4 , len ( outs [ 0 ] . splitlines ( ) ) )
self . assertEqual ( 3 , len ( outs [ 2 ] . splitlines ( ) ) )
print ( outs [ 2 ] . splitlines ( ) )
self . assertEqual ( 4 , len ( outs [ 4 ] . splitlines ( ) ) )
self . assertEquals ( 3 , len ( outs [ 2 ] . splitlines ( ) ) )
print ( outs [ 4 ] . splitlines ( ) )
self . assertEquals ( 4 , len ( outs [ 4 ] . splitlines ( ) ) )
# Last added should be last
# Last added should be last
self . assertEqual s ( ' [Page99] ' , outs [ 4 ] . splitlines ( ) [ - 1 ] [ : 8 ] )
self . assertEqual ( ' [Page99] ' , outs [ 4 ] . splitlines ( ) [ - 1 ] [ : 8 ] )
def test_list_smart_case ( self ) :
def test_list_smart_case ( self ) :
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,
@ -219,8 +220,7 @@ class TestList(DataCommandTestCase):
' pubs list title:language author:Saunders ' ,
' pubs list title:language author:Saunders ' ,
]
]
outs = self . execute_cmds ( cmds )
outs = self . execute_cmds ( cmds )
print ( outs [ - 1 ] )
self . assertEqual ( 1 , len ( outs [ - 1 ] . splitlines ( ) ) )
self . assertEquals ( 1 , len ( outs [ - 1 ] . splitlines ( ) ) )
def test_list_ignore_case ( self ) :
def test_list_ignore_case ( self ) :
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,
@ -229,8 +229,7 @@ class TestList(DataCommandTestCase):
' pubs list --ignore-case title:lAnguAge author:saunders ' ,
' pubs list --ignore-case title:lAnguAge author:saunders ' ,
]
]
outs = self . execute_cmds ( cmds )
outs = self . execute_cmds ( cmds )
print ( outs [ - 1 ] )
self . assertEqual ( 1 , len ( outs [ - 1 ] . splitlines ( ) ) )
self . assertEquals ( 1 , len ( outs [ - 1 ] . splitlines ( ) ) )
def test_list_force_case ( self ) :
def test_list_force_case ( self ) :
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,
@ -239,7 +238,7 @@ class TestList(DataCommandTestCase):
' pubs list --force-case title:Language author:saunders ' ,
' pubs list --force-case title:Language author:saunders ' ,
]
]
outs = self . execute_cmds ( cmds )
outs = self . execute_cmds ( cmds )
self . assertEqual s ( 0 + 1 , len ( outs [ - 1 ] . split ( ' \n ' ) ) )
self . assertEqual ( 0 + 1 , len ( outs [ - 1 ] . split ( ' \n ' ) ) )
@ -247,12 +246,12 @@ class TestUsecase(DataCommandTestCase):
def test_first ( self ) :
def test_first ( self ) :
correct = [ ' Initializing pubs in /paper_first \n ' ,
correct = [ ' Initializing pubs in /paper_first \n ' ,
' ',
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) \n was added to pubs. \n ',
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) \n ' ,
' [Page99] Page, Lawrence et al. " The PageRank Citation Ranking: Bringing Order to the Web. " (1999) \n ' ,
' \n ' ,
' \n ' ,
' ' ,
' ' ,
' network search \n ' ,
' network search \n ' ,
' [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 ' ,
]
]
cmds = [ ' pubs init -p paper_first/ ' ,
cmds = [ ' pubs init -p paper_first/ ' ,
@ -264,7 +263,7 @@ class TestUsecase(DataCommandTestCase):
' pubs tag search ' ,
' pubs tag search ' ,
]
]
self . assertEqual ( correct , self . execute_cmds ( cmds ))
self . assertEqual ( correct , self . execute_cmds ( cmds , capture_output = True ))
def test_second ( self ) :
def test_second ( self ) :
cmds = [ ' pubs init -p paper_second/ ' ,
cmds = [ ' pubs init -p paper_second/ ' ,
@ -290,7 +289,6 @@ class TestUsecase(DataCommandTestCase):
]
]
self . execute_cmds ( cmds )
self . execute_cmds ( cmds )
docdir = self . fs [ ' os ' ] . path . expanduser ( ' ~/.pubs/doc/ ' )
docdir = self . fs [ ' os ' ] . path . expanduser ( ' ~/.pubs/doc/ ' )
print ( self . fs [ ' os ' ] . listdir ( docdir ) )
self . assertNotIn ( ' turing-mind-1950.pdf ' , self . fs [ ' os ' ] . listdir ( docdir ) )
self . assertNotIn ( ' turing-mind-1950.pdf ' , self . fs [ ' os ' ] . listdir ( docdir ) )
@ -364,7 +362,7 @@ class TestUsecase(DataCommandTestCase):
]
]
outs = self . execute_cmds ( cmds )
outs = self . execute_cmds ( cmds )
self . assertEqual ( endecoder . EnDecoder ( ) . decode_bibdata ( outs [ 2 ] ) ,
self . assertEqual ( endecoder . EnDecoder ( ) . decode_bibdata ( outs [ 2 ] ) ,
fixtures . page_bib data )
fixtures . page_bib entry )
def test_import ( self ) :
def test_import ( self ) :
cmds = [ ' pubs init ' ,
cmds = [ ' pubs init ' ,