Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bibtexparser/bparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, data=None,
ignore_nonstandard_types=True,
homogenize_fields=False,
interpolate_strings=True,
common_strings=False,
common_strings=True,
add_missing_from_crossref=False):
"""
Creates a parser for reading BibTeX files
Expand All @@ -85,7 +85,7 @@ def __init__(self, data=None,
self.bib_database = BibDatabase()

#: Load common strings such as months abbreviation
#: Default: `False`.
#: Default: `True` (new in 1.4.0 - was previously `False`)
self.common_strings = common_strings
if self.common_strings:
self.bib_database.load_common_strings()
Expand Down
15 changes: 10 additions & 5 deletions bibtexparser/tests/test_bibtex_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@
class TestStringParse(unittest.TestCase):

def test_single_string_parse_count(self):
parser = BibTexParser(common_strings=False)
bibtex_str = '@string{name1 = "value1"}\n\n'
bib_database = bibtexparser.loads(bibtex_str)
bib_database = bibtexparser.loads(bibtex_str, parser)
self.assertEqual(len(bib_database.strings), 1)

def test_multiple_string_parse_count(self):
parser = BibTexParser(common_strings=False)
bibtex_str = '@string{name1 = "value1"}\n\n@string{name2 = "value2"}\n\n'
bib_database = bibtexparser.loads(bibtex_str)
bib_database = bibtexparser.loads(bibtex_str, parser)
self.assertEqual(len(bib_database.strings), 2)

def test_single_string_parse(self):
parser = BibTexParser(common_strings=False)
bibtex_str = '@string{name1 = "value1"}\n\n'
bib_database = bibtexparser.loads(bibtex_str)
bib_database = bibtexparser.loads(bibtex_str, parser)
expected = {'name1': 'value1'}
self.assertEqual(bib_database.strings, expected)

def test_multiple_string_parse(self):
parser = BibTexParser(common_strings=False)
bibtex_str = '@string{name1 = "value1"}\n\n@string{name2 = "value2"}\n\n'
bib_database = bibtexparser.loads(bibtex_str)
bib_database = bibtexparser.loads(bibtex_str, parser)
expected = OrderedDict()
expected['name1'] = 'value1'
expected['name2'] = 'value2'
Expand All @@ -50,8 +54,9 @@ def test_string_braces(self):
self.assertEqual(res, expected)

def test_string_parse_accept_chars(self):
parser = BibTexParser(common_strings=False)
bibtex_str = '@string{pub-ieee-std = {IEEE}}\n\n@string{pub-ieee-std:adr = {New York, NY, USA}}'
bib_database = bibtexparser.loads(bibtex_str)
bib_database = bibtexparser.loads(bibtex_str, parser)
self.assertEqual(len(bib_database.strings), 2)
expected = OrderedDict()
expected['pub-ieee-std'] = 'IEEE'
Expand Down
6 changes: 3 additions & 3 deletions bibtexparser/tests/test_bparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def customizations_latex(record):
class TestBibtexParserList(unittest.TestCase):

def test_empty_string(self):
bib = BibTexParser("")
bib = BibTexParser("", common_strings=False)
self.assertEqual(bib.entries, [])
self.assertEqual(bib.comments, [])
self.assertEqual(bib.preambles, [])
Expand Down Expand Up @@ -633,7 +633,7 @@ def test_does_not_fail_on_non_bibtex_with_partial(self):
like = a = bibtex file but
, is not a real one!
'''
parser = BibTexParser()
parser = BibTexParser(common_strings=False)
bib = parser.parse(bibraw, partial=False)
self.assertEqual(bib.entries, [])
self.assertEqual(bib.preambles, [])
Expand All @@ -644,7 +644,7 @@ def test_does_not_fail_on_non_bibtex_with_partial(self):
' , is not a real one!'])

def test_no_citekey_parsed_as_comment(self):
bib = BibTexParser('@BOOK{, title = "bla"}')
bib = BibTexParser('@BOOK{, title = "bla"}', common_strings=False)
self.assertEqual(bib.entries, [])
self.assertEqual(bib.preambles, [])
self.assertEqual(bib.strings, {})
Expand Down
4 changes: 2 additions & 2 deletions bibtexparser/tests/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_43(self):
"This is a comment\n" \
"This is a second comment."
expected = "This is a comment\nThis is a second comment."
bib = BibTexParser(comment)
bib = BibTexParser(comment, common_strings=False)
self.assertEqual(bib.comments, [expected])
self.assertEqual(bib.strings, {'foo': 'bar'})

Expand All @@ -141,7 +141,7 @@ def test_43_bis(self):
"STRING{Baz = \"This should be interpreted as comment.\"}"
expected = "This is a comment\n" \
"STRING{Baz = \"This should be interpreted as comment.\"}"
bib = BibTexParser(comment)
bib = BibTexParser(comment, common_strings=False)
self.assertEqual(bib.comments, [expected])
self.assertEqual(bib.strings, {'foo': 'bar'})

Expand Down