Adds more checks and better error message against empty citekeys.
This commit is contained in:
parent
599b124b7c
commit
328f2a6d5e
@ -22,6 +22,8 @@ def str2citekey(s):
|
|||||||
return key
|
return key
|
||||||
|
|
||||||
def check_citekey(citekey):
|
def check_citekey(citekey):
|
||||||
|
if citekey is None or not citekey.strip():
|
||||||
|
raise ValueError(u"Empty citekeys are not valid")
|
||||||
# TODO This is not the right way to test that (17/12/2012)
|
# TODO This is not the right way to test that (17/12/2012)
|
||||||
if ustr(citekey) != str2citekey(citekey):
|
if ustr(citekey) != str2citekey(citekey):
|
||||||
raise ValueError(u"Invalid `{}` citekey; ".format(citekey) +
|
raise ValueError(u"Invalid `{}` citekey; ".format(citekey) +
|
||||||
|
@ -58,6 +58,17 @@ tags: [AI, computer]
|
|||||||
added: '2013-11-14 13:14:20'
|
added: '2013-11-14 13:14:20'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Should not parse (see #113)
|
||||||
|
bibtex_no_citekey = """@Manual{,
|
||||||
|
title = {R: A Language and Environment for Statistical Computing},
|
||||||
|
author = {{R Core Team}},
|
||||||
|
organization = {R Foundation for Statistical Computing},
|
||||||
|
address = {Vienna, Austria},
|
||||||
|
year = {2017},
|
||||||
|
url = {https://www.R-project.org/},
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
sample_conf = """
|
sample_conf = """
|
||||||
[main]
|
[main]
|
||||||
|
@ -42,6 +42,10 @@ class TestAttributes(unittest.TestCase):
|
|||||||
self.assertEqual(self.p.tags, set())
|
self.assertEqual(self.p.tags, set())
|
||||||
self.p.remove_tag('ranking')
|
self.p.remove_tag('ranking')
|
||||||
|
|
||||||
|
def test_fails_with_empty_citekey(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
Paper(" ", fixtures.doe_bibdata)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -331,6 +331,14 @@ class TestAdd(URLContentTestCase):
|
|||||||
]
|
]
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
|
def test_add_no_citekey_fails(self):
|
||||||
|
# See #113
|
||||||
|
cmds = ['pubs init',
|
||||||
|
('pubs add', [str_fixtures.bibtex_no_citekey]),
|
||||||
|
]
|
||||||
|
with self.assertRaises(FakeSystemExit):
|
||||||
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
|
|
||||||
class TestList(DataCommandTestCase):
|
class TestList(DataCommandTestCase):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user