updated tests

main
Fabien Benureau 12 years ago
parent c7a8ada751
commit 164816a910

@ -6,29 +6,25 @@ from p3 import configparser
MAIN_SECTION = 'papers'
DFT_CONFIG_PATH = os.path.expanduser('~/.papersrc')
DFT_PAPERS_DIR = os.path.expanduser('~/.papers')
DFT_OPEN_CMD = 'open'
try:
DFT_EDIT_CMD = os.environ['EDITOR']
except KeyError:
DFT_EDIT_CMD = 'vi'
DFT_IMPORT_COPY = 'yes'
DFT_IMPORT_MOVE = 'no'
DFT_COLOR = 'yes'
DFT_PLUGINS = 'texnote'
DFT_CONFIG = {'papers_dir' : DFT_PAPERS_DIR,
'doc_dir' : os.path.join(DFT_PAPERS_DIR, 'doc'),
'open_cmd' : DFT_OPEN_CMD,
DFT_CONFIG = {'papers_dir' : os.path.expanduser('~/.papers'),
'doc_dir' : 'doc',
'import_copy' : 'yes',
'import_move' : 'no',
'color' : 'yes',
'open_cmd' : 'open',
'edit_cmd' : DFT_EDIT_CMD,
'import_copy' : DFT_IMPORT_COPY,
'import_move' : DFT_IMPORT_MOVE,
'color' : DFT_COLOR,
'plugins' : DFT_PLUGINS
}
BOOLEANS = {'import-copy', 'import-move', 'color'}
BOOLEANS = {'import_copy', 'import_move', 'color'}
# package-shared config that can be accessed using :

@ -55,14 +55,17 @@ class Repository(object):
# load, save repo
def init_dirs(self):
def _init_dirs(self, autodoc = True):
"""Create, if necessary, the repository directories.
Can be called more than once.
Should only be called by load or save.
"""
self.bib_dir = files.clean_path(self.config.papers_dir, BIB_DIR)
self.meta_dir = files.clean_path(self.config.papers_dir, META_DIR)
self.doc_dir = files.clean_path(self.config.doc_dir)
if self.config.doc_dir == 'doc':
self.doc_dir = files.clean_path(self.config.papers_dir, DOC_DIR)
else:
self.doc_dir = files.clean_path(self.config.doc_dir)
self.cfg_path = files.clean_path(self.config.papers_dir, 'papers.yaml')
for d in [self.bib_dir, self.meta_dir, self.doc_dir]:
@ -71,13 +74,13 @@ class Repository(object):
def load(self):
"""Load the repository, creating dirs if necessary"""
self.init_dirs()
self._init_dirs()
repo_config = files.read_yamlfile(self.cfg_path)
self.citekeys = repo_config['citekeys']
def save(self):
"""Save the repo, creating dirs if necessary"""
self.init_dirs()
self._init_dirs()
repo_cfg = {'citekeys': self.citekeys}
files.write_yamlfile(self.cfg_path, repo_cfg)

@ -16,8 +16,9 @@ class TestConfig(unittest.TestCase):
def test_config_content(self):
a = configs.Config()
a.as_global()
self.assertEqual(config().papers_dir, configs.DFT_PAPERS_DIR)
self.assertEqual(config().color, configs.str2bool(configs.DFT_COLOR))
self.assertEqual(config().papers_dir, configs.DFT_CONFIG['papers_dir'])
self.assertEqual(config().color, configs.str2bool(configs.DFT_CONFIG['color']))
def test_set(self):
a = configs.Config()
@ -33,17 +34,19 @@ class TestConfig(unittest.TestCase):
def test_reload(self):
default_color = configs.DFT_CONFIG['color']
a = configs.Config()
a.as_global()
a.color = False
a.bla = 'foo'
config.color = not configs.str2bool(configs.DFT_COLOR)
self.assertEqual(config().color, not configs.str2bool(configs.DFT_COLOR))
config.color = not configs.str2bool(default_color)
self.assertEqual(config().color, not configs.str2bool(default_color))
b = configs.Config()
b.as_global()
self.assertEqual(b, config())
self.assertEqual(config().color, configs.str2bool(configs.DFT_COLOR))
self.assertEqual(config().color, configs.str2bool(default_color))
def test_exception(self):

@ -73,25 +73,25 @@ class TestSaveLoad(unittest.TestCase):
def test_save_fails_with_no_citekey(self):
p = Paper()
with self.assertRaises(ValueError):
p.save_to_disc(self.dest_bibfile, self.dest_metafile)
p.save(self.dest_bibfile, self.dest_metafile)
def test_save_creates_bib(self):
fixtures.turing1950.save_to_disc(self.dest_bibfile, self.dest_metafile)
fixtures.turing1950.save(self.dest_bibfile, self.dest_metafile)
self.assertTrue(os.path.exists(self.dest_bibfile))
def test_save_creates_meta(self):
fixtures.turing1950.save_to_disc(self.dest_bibfile, self.dest_metafile)
fixtures.turing1950.save(self.dest_bibfile, self.dest_metafile)
self.assertTrue(os.path.exists(self.dest_metafile))
def test_save_right_bib(self):
fixtures.turing1950.save_to_disc(self.dest_bibfile, self.dest_metafile)
fixtures.turing1950.save(self.dest_bibfile, self.dest_metafile)
with open(self.dest_bibfile, 'r') as f:
written = yaml.load(f)
ok = yaml.load(BIB)
self.assertEqual(written, ok)
def test_save_right_meta(self):
fixtures.turing1950.save_to_disc(self.dest_bibfile, self.dest_metafile)
fixtures.turing1950.save(self.dest_bibfile, self.dest_metafile)
with open(self.dest_metafile, 'r') as f:
written = yaml.load(f)
ok = yaml.load(META)

@ -32,7 +32,7 @@ class TestRepo(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.repo = Repository(configs.Config(papers_dir = self.tmpdir), load = False)
self.repo.init_dirs()
self.repo.save()
self.repo.add_paper(fixtures.turing1950)
def tearDown(self):

@ -102,7 +102,7 @@ class TestAdd(unittest.TestCase):
papers_cmd.execute('papers init -p /not_default'.split())
papers_cmd.execute('papers add -b /data/pagerank.bib -d /data/pagerank.pdf'.split())
self.assertEqual(set(fake_os.listdir('/not_default/doc')), {'Page99.pdf'})
self.assertEqual(set(fake_os.listdir('/not_default/doc')), {'pagerank.pdf'})
class TestList(unittest.TestCase):
@ -122,7 +122,7 @@ class TestUsecase(unittest.TestCase):
def test_first(self):
correct = ['Initializing papers in /paper_first/.\n',
correct = ['Initializing papers in /paper_first.\n',
'Added: Page99\n',
'0: [Page99] L. Page et al. "The PageRank Citation Ranking Bringing Order to the Web" (1999) \n',
'',

Loading…
Cancel
Save