Skip to content

Commit 006f463

Browse files
authored
🔧 using common strings is now the default (#311)
1 parent fddcab1 commit 006f463

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

bibtexparser/bparser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, data=None,
7474
ignore_nonstandard_types=True,
7575
homogenize_fields=False,
7676
interpolate_strings=True,
77-
common_strings=False,
77+
common_strings=True,
7878
add_missing_from_crossref=False):
7979
"""
8080
Creates a parser for reading BibTeX files
@@ -85,7 +85,7 @@ def __init__(self, data=None,
8585
self.bib_database = BibDatabase()
8686

8787
#: Load common strings such as months abbreviation
88-
#: Default: `False`.
88+
#: Default: `True` (new in 1.4.0 - was previously `False`)
8989
self.common_strings = common_strings
9090
if self.common_strings:
9191
self.bib_database.load_common_strings()

bibtexparser/tests/test_bibtex_strings.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,28 @@
1212
class TestStringParse(unittest.TestCase):
1313

1414
def test_single_string_parse_count(self):
15+
parser = BibTexParser(common_strings=False)
1516
bibtex_str = '@string{name1 = "value1"}\n\n'
16-
bib_database = bibtexparser.loads(bibtex_str)
17+
bib_database = bibtexparser.loads(bibtex_str, parser)
1718
self.assertEqual(len(bib_database.strings), 1)
1819

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

2426
def test_single_string_parse(self):
27+
parser = BibTexParser(common_strings=False)
2528
bibtex_str = '@string{name1 = "value1"}\n\n'
26-
bib_database = bibtexparser.loads(bibtex_str)
29+
bib_database = bibtexparser.loads(bibtex_str, parser)
2730
expected = {'name1': 'value1'}
2831
self.assertEqual(bib_database.strings, expected)
2932

3033
def test_multiple_string_parse(self):
34+
parser = BibTexParser(common_strings=False)
3135
bibtex_str = '@string{name1 = "value1"}\n\n@string{name2 = "value2"}\n\n'
32-
bib_database = bibtexparser.loads(bibtex_str)
36+
bib_database = bibtexparser.loads(bibtex_str, parser)
3337
expected = OrderedDict()
3438
expected['name1'] = 'value1'
3539
expected['name2'] = 'value2'
@@ -50,8 +54,9 @@ def test_string_braces(self):
5054
self.assertEqual(res, expected)
5155

5256
def test_string_parse_accept_chars(self):
57+
parser = BibTexParser(common_strings=False)
5358
bibtex_str = '@string{pub-ieee-std = {IEEE}}\n\n@string{pub-ieee-std:adr = {New York, NY, USA}}'
54-
bib_database = bibtexparser.loads(bibtex_str)
59+
bib_database = bibtexparser.loads(bibtex_str, parser)
5560
self.assertEqual(len(bib_database.strings), 2)
5661
expected = OrderedDict()
5762
expected['pub-ieee-std'] = 'IEEE'

bibtexparser/tests/test_bparser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def customizations_latex(record):
5656
class TestBibtexParserList(unittest.TestCase):
5757

5858
def test_empty_string(self):
59-
bib = BibTexParser("")
59+
bib = BibTexParser("", common_strings=False)
6060
self.assertEqual(bib.entries, [])
6161
self.assertEqual(bib.comments, [])
6262
self.assertEqual(bib.preambles, [])
@@ -633,7 +633,7 @@ def test_does_not_fail_on_non_bibtex_with_partial(self):
633633
like = a = bibtex file but
634634
, is not a real one!
635635
'''
636-
parser = BibTexParser()
636+
parser = BibTexParser(common_strings=False)
637637
bib = parser.parse(bibraw, partial=False)
638638
self.assertEqual(bib.entries, [])
639639
self.assertEqual(bib.preambles, [])
@@ -644,7 +644,7 @@ def test_does_not_fail_on_non_bibtex_with_partial(self):
644644
' , is not a real one!'])
645645

646646
def test_no_citekey_parsed_as_comment(self):
647-
bib = BibTexParser('@BOOK{, title = "bla"}')
647+
bib = BibTexParser('@BOOK{, title = "bla"}', common_strings=False)
648648
self.assertEqual(bib.entries, [])
649649
self.assertEqual(bib.preambles, [])
650650
self.assertEqual(bib.strings, {})

bibtexparser/tests/test_comments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_43(self):
131131
"This is a comment\n" \
132132
"This is a second comment."
133133
expected = "This is a comment\nThis is a second comment."
134-
bib = BibTexParser(comment)
134+
bib = BibTexParser(comment, common_strings=False)
135135
self.assertEqual(bib.comments, [expected])
136136
self.assertEqual(bib.strings, {'foo': 'bar'})
137137

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

0 commit comments

Comments
 (0)