Skip to content

Commit 739dc97

Browse files
authored
✅ Fix file encoding in tests (#302)
Currently, the tests depend on the system they are run on, in terms of assumed file encoding. This leads to tests that pass on the CI, but fail locally. This PR makes the encodings in the test files explicit.
1 parent 4b86f4c commit 739dc97

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

bibtexparser/tests/test_bibtexparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_parse_str(self):
3232

3333
def test_parse_bom_str(self):
3434
parser = BibTexParser()
35-
with open(self.input_bom_file_path) as bibtex_file:
35+
with open(self.input_bom_file_path, encoding="utf-8") as bibtex_file:
3636
bibtex_str = bibtex_file.read()
3737
bibtex_database = parser.parse(bibtex_str)
3838
self.assertEqual(bibtex_database.entries, self.entries_expected)

bibtexparser/tests/test_bibtexwriter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def test_unicode_problems(self):
252252
}
253253
"""
254254
bibdb = bibtexparser.loads(bibtex)
255-
with tempfile.TemporaryFile(mode='w+') as bibtex_file:
255+
with tempfile.TemporaryFile(mode='w+', encoding="utf-8") as bibtex_file:
256256
bibtexparser.dump(bibdb, bibtex_file)
257257
# No exception should be raised
258258

bibtexparser/tests/test_bparser.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ def test_article_comma_first(self):
320320
self.assertEqual(res, expected)
321321

322322
def test_article_no_braces(self):
323-
with open('bibtexparser/tests/data/article_no_braces.bib', 'r') as bibfile:
323+
with open('bibtexparser/tests/data/article_no_braces.bib', 'r',
324+
encoding="utf-8") as bibfile:
324325
bib = BibTexParser(bibfile.read())
325326
res = bib.get_entry_list()
326327
expected = [{'ENTRYTYPE': 'article',
@@ -340,7 +341,8 @@ def test_article_no_braces(self):
340341
self.assertEqual(res, expected)
341342

342343
def test_article_special_characters(self):
343-
with open('bibtexparser/tests/data/article_with_special_characters.bib', 'r') as bibfile:
344+
with open('bibtexparser/tests/data/article_with_special_characters.bib', 'r',
345+
encoding="utf-8") as bibfile:
344346
bib = BibTexParser(bibfile.read())
345347
res = bib.get_entry_list()
346348
expected = [{'ENTRYTYPE': 'article',
@@ -360,7 +362,8 @@ def test_article_special_characters(self):
360362
self.assertEqual(res, expected)
361363

362364
def test_article_protection_braces(self):
363-
with open('bibtexparser/tests/data/article_with_protection_braces.bib', 'r') as bibfile:
365+
with open('bibtexparser/tests/data/article_with_protection_braces.bib', 'r',
366+
encoding="utf-8") as bibfile:
364367
bib = BibTexParser(bibfile.read())
365368
res = bib.get_entry_list()
366369
expected = [{'ENTRYTYPE': 'article',
@@ -532,7 +535,8 @@ def test_encoding_with_homogenize(self):
532535
self.assertEqual(res, expected)
533536

534537
def test_field_name_with_dash_underscore(self):
535-
with open('bibtexparser/tests/data/article_field_name_with_underscore.bib', 'r') as bibfile:
538+
with open('bibtexparser/tests/data/article_field_name_with_underscore.bib', 'r',
539+
encoding="utf-8") as bibfile:
536540
bib = BibTexParser(bibfile.read())
537541
res = bib.get_entry_list()
538542
expected = [{
@@ -552,7 +556,8 @@ def test_field_name_with_dash_underscore(self):
552556
self.assertEqual(res, expected)
553557

554558
def test_string_definitions(self):
555-
with open('bibtexparser/tests/data/article_with_strings.bib', 'r') as bibfile:
559+
with open('bibtexparser/tests/data/article_with_strings.bib', 'r',
560+
encoding="utf-8") as bibfile:
556561
bib = BibTexParser(bibfile.read(), common_strings=True)
557562
res = dict(bib.strings)
558563
expected = COMMON_STRINGS.copy()
@@ -564,7 +569,8 @@ def test_string_definitions(self):
564569
self.assertEqual(res, expected)
565570

566571
def test_string_is_interpolated(self):
567-
with open('bibtexparser/tests/data/article_with_strings.bib', 'r') as bibfile:
572+
with open('bibtexparser/tests/data/article_with_strings.bib', 'r',
573+
encoding="utf-8") as bibfile:
568574
bib = BibTexParser(bibfile.read(), common_strings=True,
569575
interpolate_strings=True)
570576
res = bib.get_entry_list()
@@ -584,7 +590,8 @@ def test_string_is_interpolated(self):
584590
self.assertEqual(res, expected)
585591

586592
def test_string_is_not_interpolated(self):
587-
with open('bibtexparser/tests/data/article_with_strings.bib', 'r') as bibfile:
593+
with open('bibtexparser/tests/data/article_with_strings.bib', 'r',
594+
encoding="utf-8") as bibfile:
588595
bib = BibTexParser(bibfile.read(), common_strings=True,
589596
interpolate_strings=False)
590597
res = bib.get_entry_list()[0]

0 commit comments

Comments
 (0)