|
|
|
@ -5,12 +5,12 @@ import os
|
|
|
|
|
import testenv
|
|
|
|
|
import fake_env
|
|
|
|
|
|
|
|
|
|
from papers import papers_cmd
|
|
|
|
|
from papers import color, content, filebroker, uis, beets_ui, p3
|
|
|
|
|
from pubs import pubs_cmd
|
|
|
|
|
from pubs import color, content, filebroker, uis, beets_ui, p3
|
|
|
|
|
|
|
|
|
|
import str_fixtures
|
|
|
|
|
|
|
|
|
|
from papers.commands import init_cmd, import_cmd
|
|
|
|
|
from pubs.commands import init_cmd, import_cmd
|
|
|
|
|
|
|
|
|
|
# code for fake fs
|
|
|
|
|
|
|
|
|
@ -65,7 +65,7 @@ class CommandTestCase(unittest.TestCase):
|
|
|
|
|
input = fake_env.FakeInput(cmd[1], [content, uis, beets_ui, p3])
|
|
|
|
|
input.as_global()
|
|
|
|
|
|
|
|
|
|
_, stdout, stderr = fake_env.redirect(papers_cmd.execute)(cmd[0].split())
|
|
|
|
|
_, stdout, stderr = fake_env.redirect(pubs_cmd.execute)(cmd[0].split())
|
|
|
|
|
if len(cmd) == 3:
|
|
|
|
|
actual_out = color.undye(stdout.getvalue())
|
|
|
|
|
correct_out = color.undye(cmd[2])
|
|
|
|
@ -73,7 +73,7 @@ class CommandTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
assert type(cmd) == str
|
|
|
|
|
_, stdout, stderr = fake_env.redirect(papers_cmd.execute)(cmd.split())
|
|
|
|
|
_, stdout, stderr = fake_env.redirect(pubs_cmd.execute)(cmd.split())
|
|
|
|
|
|
|
|
|
|
assert(stderr.getvalue() == '')
|
|
|
|
|
outs.append(color.undye(stdout.getvalue()))
|
|
|
|
@ -97,28 +97,28 @@ class DataCommandTestCase(CommandTestCase):
|
|
|
|
|
class TestInit(CommandTestCase):
|
|
|
|
|
|
|
|
|
|
def test_init(self):
|
|
|
|
|
pubsdir = os.path.expanduser('~/papers_test2')
|
|
|
|
|
papers_cmd.execute('papers init -p {}'.format(pubsdir).split())
|
|
|
|
|
pubsdir = os.path.expanduser('~/pubs_test2')
|
|
|
|
|
pubs_cmd.execute('pubs init -p {}'.format(pubsdir).split())
|
|
|
|
|
self.assertEqual(set(self.fs['os'].listdir(pubsdir)),
|
|
|
|
|
{'bib', 'doc', 'meta', 'notes'})
|
|
|
|
|
|
|
|
|
|
def test_init2(self):
|
|
|
|
|
pubsdir = os.path.expanduser('~/.papers')
|
|
|
|
|
papers_cmd.execute('papers init'.split())
|
|
|
|
|
pubsdir = os.path.expanduser('~/.pubs')
|
|
|
|
|
pubs_cmd.execute('pubs init'.split())
|
|
|
|
|
self.assertEqual(set(self.fs['os'].listdir(pubsdir)),
|
|
|
|
|
{'bib', 'doc', 'meta', 'notes'})
|
|
|
|
|
|
|
|
|
|
class TestAdd(DataCommandTestCase):
|
|
|
|
|
|
|
|
|
|
def test_add(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers add -b /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add -b /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_add2(self):
|
|
|
|
|
cmds = ['papers init -p /not_default',
|
|
|
|
|
'papers add -b /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
cmds = ['pubs init -p /not_default',
|
|
|
|
|
'pubs add -b /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
self.assertEqual(set(self.fs['os'].listdir('/not_default/doc')), {'Page99.pdf'})
|
|
|
|
@ -127,37 +127,37 @@ class TestAdd(DataCommandTestCase):
|
|
|
|
|
class TestList(DataCommandTestCase):
|
|
|
|
|
|
|
|
|
|
def test_list(self):
|
|
|
|
|
cmds = ['papers init -p /not_default2',
|
|
|
|
|
'papers list',
|
|
|
|
|
'papers add -b /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
'papers list',
|
|
|
|
|
cmds = ['pubs init -p /not_default2',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs add -b /data/pagerank.bib -d /data/pagerank.pdf',
|
|
|
|
|
'pubs list',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_list_smart_case(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers list',
|
|
|
|
|
'papers import data/',
|
|
|
|
|
'papers list title:language author:Saunders',
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs import data/',
|
|
|
|
|
'pubs list title:language author:Saunders',
|
|
|
|
|
]
|
|
|
|
|
outs = self.execute_cmds(cmds)
|
|
|
|
|
print outs[-1]
|
|
|
|
|
self.assertEquals(1, len(outs[-1].split('/n')))
|
|
|
|
|
|
|
|
|
|
def test_list_ignore_case(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers list',
|
|
|
|
|
'papers import data/',
|
|
|
|
|
'papers list --ignore-case title:lAnguAge author:saunders',
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs import data/',
|
|
|
|
|
'pubs list --ignore-case title:lAnguAge author:saunders',
|
|
|
|
|
]
|
|
|
|
|
outs = self.execute_cmds(cmds)
|
|
|
|
|
self.assertEquals(1, len(outs[-1].split('/n')))
|
|
|
|
|
|
|
|
|
|
def test_list_force_case(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers list',
|
|
|
|
|
'papers import data/',
|
|
|
|
|
'papers list --force-case title:Language author:saunders',
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs import data/',
|
|
|
|
|
'pubs list --force-case title:Language author:saunders',
|
|
|
|
|
]
|
|
|
|
|
outs = self.execute_cmds(cmds)
|
|
|
|
|
self.assertEquals(0 + 1, len(outs[-1].split('/n')))
|
|
|
|
@ -167,7 +167,7 @@ class TestList(DataCommandTestCase):
|
|
|
|
|
class TestUsecase(DataCommandTestCase):
|
|
|
|
|
|
|
|
|
|
def test_first(self):
|
|
|
|
|
correct = ['Initializing papers in /paper_first.\n',
|
|
|
|
|
correct = ['Initializing pubs in /paper_first.\n',
|
|
|
|
|
'',
|
|
|
|
|
'[Page99] L. Page et al. "The PageRank Citation Ranking Bringing Order to the Web" (1999) \n',
|
|
|
|
|
'',
|
|
|
|
@ -176,55 +176,55 @@ class TestUsecase(DataCommandTestCase):
|
|
|
|
|
'[Page99] L. Page et al. "The PageRank Citation Ranking Bringing Order to the Web" (1999) search network\n'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
cmds = ['papers init -p paper_first/',
|
|
|
|
|
'papers add -d data/pagerank.pdf -b data/pagerank.bib',
|
|
|
|
|
'papers list',
|
|
|
|
|
'papers tag',
|
|
|
|
|
'papers tag Page99 network+search',
|
|
|
|
|
'papers tag Page99',
|
|
|
|
|
'papers tag search',
|
|
|
|
|
cmds = ['pubs init -p paper_first/',
|
|
|
|
|
'pubs add -d data/pagerank.pdf -b data/pagerank.bib',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs tag',
|
|
|
|
|
'pubs tag Page99 network+search',
|
|
|
|
|
'pubs tag Page99',
|
|
|
|
|
'pubs tag search',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
self.assertEqual(correct, self.execute_cmds(cmds))
|
|
|
|
|
|
|
|
|
|
def test_second(self):
|
|
|
|
|
cmds = ['papers init -p paper_second/',
|
|
|
|
|
'papers add -b data/pagerank.bib',
|
|
|
|
|
'papers add -d data/turing-mind-1950.pdf -b data/turing1950.bib',
|
|
|
|
|
'papers add -b data/martius.bib',
|
|
|
|
|
'papers add -b data/10.1371%2Fjournal.pone.0038236.bib',
|
|
|
|
|
'papers list',
|
|
|
|
|
'papers attach Page99 data/pagerank.pdf'
|
|
|
|
|
cmds = ['pubs init -p paper_second/',
|
|
|
|
|
'pubs add -b data/pagerank.bib',
|
|
|
|
|
'pubs add -d data/turing-mind-1950.pdf -b data/turing1950.bib',
|
|
|
|
|
'pubs add -b data/martius.bib',
|
|
|
|
|
'pubs add -b data/10.1371%2Fjournal.pone.0038236.bib',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs attach Page99 data/pagerank.pdf'
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_third(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers add -b data/pagerank.bib',
|
|
|
|
|
'papers add -d data/turing-mind-1950.pdf -b data/turing1950.bib',
|
|
|
|
|
'papers add -b data/martius.bib',
|
|
|
|
|
'papers add -b data/10.1371%2Fjournal.pone.0038236.bib',
|
|
|
|
|
'papers list',
|
|
|
|
|
'papers attach Page99 data/pagerank.pdf',
|
|
|
|
|
('papers remove Page99', ['y']),
|
|
|
|
|
'papers remove -f turing1950computing',
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add -b data/pagerank.bib',
|
|
|
|
|
'pubs add -d data/turing-mind-1950.pdf -b data/turing1950.bib',
|
|
|
|
|
'pubs add -b data/martius.bib',
|
|
|
|
|
'pubs add -b data/10.1371%2Fjournal.pone.0038236.bib',
|
|
|
|
|
'pubs list',
|
|
|
|
|
'pubs attach Page99 data/pagerank.pdf',
|
|
|
|
|
('pubs remove Page99', ['y']),
|
|
|
|
|
'pubs remove -f turing1950computing',
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_editor_abort(self):
|
|
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
('papers add', ['abc', 'n']),
|
|
|
|
|
('papers add', ['abc', 'y', 'abc', 'n']),
|
|
|
|
|
'papers add -b data/pagerank.bib',
|
|
|
|
|
('papers edit Page99', ['', 'a']),
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
('pubs add', ['abc', 'n']),
|
|
|
|
|
('pubs add', ['abc', 'y', 'abc', 'n']),
|
|
|
|
|
'pubs add -b data/pagerank.bib',
|
|
|
|
|
('pubs edit Page99', ['', 'a']),
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_editor_success(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
('papers add', [str_fixtures.bibtex_external0]),
|
|
|
|
|
('papers remove Page99', ['y']),
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
('pubs add', [str_fixtures.bibtex_external0]),
|
|
|
|
|
('pubs remove Page99', ['y']),
|
|
|
|
|
]
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
@ -239,64 +239,64 @@ class TestUsecase(DataCommandTestCase):
|
|
|
|
|
line2 = re.sub('L. Page', 'L. Ridge', line1)
|
|
|
|
|
line3 = re.sub('Page99', 'Ridge07', line2)
|
|
|
|
|
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers add -b data/pagerank.bib',
|
|
|
|
|
('papers list', [], line),
|
|
|
|
|
('papers edit Page99', [bib1]),
|
|
|
|
|
('papers list', [], line1),
|
|
|
|
|
('papers edit Page99', [bib2]),
|
|
|
|
|
('papers list', [], line2),
|
|
|
|
|
('papers edit Page99', [bib3]),
|
|
|
|
|
('papers list', [], line3),
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add -b data/pagerank.bib',
|
|
|
|
|
('pubs list', [], line),
|
|
|
|
|
('pubs edit Page99', [bib1]),
|
|
|
|
|
('pubs list', [], line1),
|
|
|
|
|
('pubs edit Page99', [bib2]),
|
|
|
|
|
('pubs list', [], line2),
|
|
|
|
|
('pubs edit Page99', [bib3]),
|
|
|
|
|
('pubs list', [], line3),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_export(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
('papers add', [str_fixtures.bibtex_external0]),
|
|
|
|
|
'papers export Page99',
|
|
|
|
|
('papers export Page99 -f bibtex', [], str_fixtures.bibtex_raw0),
|
|
|
|
|
'papers export Page99 -f bibyaml',
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
('pubs add', [str_fixtures.bibtex_external0]),
|
|
|
|
|
'pubs export Page99',
|
|
|
|
|
('pubs export Page99 -f bibtex', [], str_fixtures.bibtex_raw0),
|
|
|
|
|
'pubs export Page99 -f bibyaml',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_import(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers import data/',
|
|
|
|
|
'papers list'
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs import data/',
|
|
|
|
|
'pubs list'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
outs = self.execute_cmds(cmds)
|
|
|
|
|
self.assertEqual(4 + 1, len(outs[-1].split('\n')))
|
|
|
|
|
|
|
|
|
|
def test_import_one(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers import data/ Page99',
|
|
|
|
|
'papers list'
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs import data/ Page99',
|
|
|
|
|
'pubs list'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
outs = self.execute_cmds(cmds)
|
|
|
|
|
self.assertEqual(1 + 1, len(outs[-1].split('\n')))
|
|
|
|
|
|
|
|
|
|
def test_open(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers add -b data/pagerank.bib',
|
|
|
|
|
'papers open Page99'
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add -b data/pagerank.bib',
|
|
|
|
|
'pubs open Page99'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
|
cmds[-1] == 'papers open Page8'
|
|
|
|
|
cmds[-1] == 'pubs open Page8'
|
|
|
|
|
self.execute_cmds(cmds)
|
|
|
|
|
|
|
|
|
|
def test_update(self):
|
|
|
|
|
cmds = ['papers init',
|
|
|
|
|
'papers add -b data/pagerank.bib',
|
|
|
|
|
'papers update'
|
|
|
|
|
cmds = ['pubs init',
|
|
|
|
|
'pubs add -b data/pagerank.bib',
|
|
|
|
|
'pubs update'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
|