|
|
|
@ -24,7 +24,7 @@ from pubs.commands import init_cmd, import_cmd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# makes the tests very noisy
|
|
|
|
|
PRINT_OUTPUT = False
|
|
|
|
|
PRINT_OUTPUT = False
|
|
|
|
|
CAPTURE_OUTPUT = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -145,8 +145,11 @@ class DataCommandTestCase(CommandTestCase):
|
|
|
|
|
|
|
|
|
|
def setUp(self, nsec_stat=True):
|
|
|
|
|
super(DataCommandTestCase, self).setUp(nsec_stat=nsec_stat)
|
|
|
|
|
fake_env.copy_dir(self.fs, os.path.join(os.path.dirname(__file__), 'data'), 'data')
|
|
|
|
|
fake_env.copy_dir(self.fs, os.path.join(os.path.dirname(__file__), 'bibexamples'), 'bibexamples')
|
|
|
|
|
self.fs.add_real_directory(os.path.join(self.rootpath, 'data'), read_only=False)
|
|
|
|
|
self.fs.add_real_directory(os.path.join(self.rootpath, 'bibexamples'), read_only=False)
|
|
|
|
|
|
|
|
|
|
# fake_env.copy_dir(self.fs, os.path.join(os.path.dirname(__file__), 'data'), 'data')
|
|
|
|
|
# fake_env.copy_dir(self.fs, os.path.join(os.path.dirname(__file__), 'bibexamples'), 'bibexamples')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Actual tests
|
|
|
|
@ -181,7 +184,7 @@ class TestAdd(DataCommandTestCase):
|
|
|
|
|
|
|
|
|
|
def test_add(self):
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
'pubs add data/pagerank.bib -d data/pagerank.pdf',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
bib_dir = os.path.join(self.default_pubs_dir, 'bib')
|
|
|
|
@ -193,7 +196,7 @@ class TestAdd(DataCommandTestCase):
|
|
|
|
|
|
|
|
|
|
def test_add_bibutils(self):
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add /bibexamples/bibutils.bib',
|
|
|
|
|
'pubs add bibexamples/bibutils.bib',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
bib_dir = os.path.join(self.default_pubs_dir, 'bib')
|
|
|
|
@ -201,14 +204,14 @@ class TestAdd(DataCommandTestCase):
|
|
|
|
|
|
|
|
|
|
def test_add2(self):
|
|
|
|
|
cmds = ['pubs init -p /not_default',
|
|
|
|
|
'pubs add /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
'pubs add data/pagerank.bib -d data/pagerank.pdf',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
self.assertEqual(set(os.listdir('/not_default/doc')), {'Page99.pdf'})
|
|
|
|
|
|
|
|
|
|
def test_add_citekey(self):
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add -k CustomCitekey /data/pagerank.bib',
|
|
|
|
|
'pubs add -k CustomCitekey data/pagerank.bib',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
bib_dir = os.path.join(self.default_pubs_dir, 'bib')
|
|
|
|
@ -219,14 +222,14 @@ class TestAdd(DataCommandTestCase):
|
|
|
|
|
"utf-8 citekeys are not supported yet.\n"
|
|
|
|
|
"See https://github.com/pubs/pubs/issues/28 for details.") # actually not checked
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
('pubs add /bibexamples/utf8.bib', [], '', err),
|
|
|
|
|
('pubs add bibexamples/utf8.bib', [], '', err),
|
|
|
|
|
]
|
|
|
|
|
with self.assertRaises(FakeSystemExit):
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_add_doc_nocopy_does_not_copy(self):
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add /data/pagerank.bib --link -d /data/pagerank.pdf',
|
|
|
|
|
'pubs add data/pagerank.bib --link -d data/pagerank.pdf',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
self.assertEqual(os.listdir(
|
|
|
|
@ -235,15 +238,15 @@ class TestAdd(DataCommandTestCase):
|
|
|
|
|
|
|
|
|
|
def test_add_move_removes_doc(self):
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add /data/pagerank.bib --move -d /data/pagerank.pdf',
|
|
|
|
|
'pubs add data/pagerank.bib --move -d data/pagerank.pdf',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
self.assertFalse(os.path.exists('/data/pagerank.pdf'))
|
|
|
|
|
self.assertFalse(os.path.exists('data/pagerank.pdf'))
|
|
|
|
|
|
|
|
|
|
def test_add_twice_fails(self):
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add /data/pagerank.bib',
|
|
|
|
|
'pubs add -k Page99 /data/turing1950.bib',
|
|
|
|
|
'pubs add data/pagerank.bib',
|
|
|
|
|
'pubs add -k Page99 data/turing1950.bib',
|
|
|
|
|
]
|
|
|
|
|
with self.assertRaises(FakeSystemExit):
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
@ -252,7 +255,7 @@ class TestAdd(DataCommandTestCase):
|
|
|
|
|
@unittest.expectedFailure
|
|
|
|
|
def test_leading_citekey_space(self):
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add /bibexamples/leadingspace.bib',
|
|
|
|
|
'pubs add bibexamples/leadingspace.bib',
|
|
|
|
|
'pubs rename LeadingSpace NoLeadingSpace',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
@ -263,22 +266,24 @@ class TestList(DataCommandTestCase):
|
|
|
|
|
def test_list(self):
|
|
|
|
|
cmds = ['pubs init -p /not_default2',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs add /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
'pubs add data/pagerank.bib -d data/pagerank.pdf',
|
|
|
|
|
'pubs list',
|
|
|
|
|
]
|
|
|
|
|
outs = self.execute_cmds(cmds)
|
|
|
|
|
self.assertEqual(0, len(outs[1].splitlines()))
|
|
|
|
|
self.assertEqual(1, len(outs[3].splitlines()))
|
|
|
|
|
|
|
|
|
|
@unittest.expectedFailure #FIXME pyfakefs's shutil.rmtree seems to have problems: submit an issue.
|
|
|
|
|
def test_list_several_no_date(self):
|
|
|
|
|
self.execute_cmds(['pubs init -p /testrepo'])
|
|
|
|
|
self.execute_cmds(['pubs init -p testrepo'])
|
|
|
|
|
shutil.rmtree('testrepo')
|
|
|
|
|
testrepo = os.path.join(os.path.dirname(__file__), 'testrepo')
|
|
|
|
|
fake_env.copy_dir(self.fs, testrepo, 'testrepo')
|
|
|
|
|
self.fs.add_real_directory(os.path.join(self.rootpath, 'testrepo'), read_only=False)
|
|
|
|
|
|
|
|
|
|
#fake_env.copy_dir(self.fs, testrepo, 'testrepo')
|
|
|
|
|
cmds = ['pubs list',
|
|
|
|
|
'pubs remove -f Page99',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs add /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
'pubs add data/pagerank.bib -d data/pagerank.pdf',
|
|
|
|
|
'pubs list',
|
|
|
|
|
]
|
|
|
|
|
outs = self.execute_cmds(cmds)
|
|
|
|
@ -400,7 +405,7 @@ class TestUsecase(DataCommandTestCase):
|
|
|
|
|
'[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',
|
|
|
|
|
'pubs add -d data/pagerank.pdf data/pagerank.bib',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs tag',
|
|
|
|
@ -566,7 +571,7 @@ class TestUsecase(DataCommandTestCase):
|
|
|
|
|
'doc',
|
|
|
|
|
'Page99.pdf')))
|
|
|
|
|
# Also test that do not remove original
|
|
|
|
|
self.assertTrue(os.path.exists('/data/pagerank.pdf'))
|
|
|
|
|
self.assertTrue(os.path.exists('data/pagerank.pdf'))
|
|
|
|
|
|
|
|
|
|
def test_doc_add_with_move(self):
|
|
|
|
|
cmds = ['pubs init -p paper_second/',
|
|
|
|
@ -574,7 +579,7 @@ class TestUsecase(DataCommandTestCase):
|
|
|
|
|
'pubs doc add --move data/pagerank.pdf Page99'
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
self.assertFalse(os.path.exists('/data/pagerank.pdf'))
|
|
|
|
|
self.assertFalse(os.path.exists('data/pagerank.pdf'))
|
|
|
|
|
|
|
|
|
|
def test_doc_remove(self):
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|