Skip to content

Commit

Permalink
Refractor test_find_dois.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dli7319 committed Apr 11, 2024
1 parent 5c51937 commit 8833952
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions tests/test_find_dois.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
from DuBibtex import Parser


@pytest.mark.parametrize("filename,correct_doi", [
("signet.bib", "10.1109/ICCV48922.2021.01396"),
("qdiffusion.bib", "10.1109/ICCV51070.2023.01608"),
])
def test_iccv_doi(filename, correct_doi):
def search_and_check_doi(filename, correct_doi):
input_file = os.path.join("tests", "inputs", filename)

assert os.path.isfile(input_file), f"File {input_file} does not exist"
library = bibtexparser.parse_file(input_file)

with tempfile.NamedTemporaryFile() as fp:
p = Parser(output_file=fp.name)
p = Parser(output_file=fp.name, use_offline_doi=False)
for entry in library.entries:
p.copy_from_parsed_entry(entry)
p.write_current_item()
Expand All @@ -32,26 +28,17 @@ def test_iccv_doi(filename, correct_doi):
assert "doi" in entry
assert entry.fields_dict["doi"].value == correct_doi


@pytest.mark.parametrize("filename,correct_doi", [
("holocamera.bib", "10.1109/TVCG.2024.3372123"),
("signet.bib", "10.1109/ICCV48922.2021.01396"),
("qdiffusion.bib", "10.1109/ICCV51070.2023.01608"),
])
def test_tvcg_doi(filename, correct_doi):
input_file = os.path.join("tests", "inputs", filename)

assert os.path.isfile(input_file), f"File {input_file} does not exist"
library = bibtexparser.parse_file(input_file)
def test_iccv_doi(filename, correct_doi):
search_and_check_doi(filename, correct_doi)

with tempfile.NamedTemporaryFile() as fp:
p = Parser(output_file=fp.name)
for entry in library.entries:
p.copy_from_parsed_entry(entry)
p.write_current_item()
p.shut_down()

# Check the doi
generated_library = bibtexparser.parse_file(fp.name)
assert len(generated_library.entries) == len(
library.entries), "Number of entries should be the same"
for entry in generated_library.entries:
assert "doi" in entry
assert entry.fields_dict["doi"].value == correct_doi
@pytest.mark.parametrize("filename,correct_doi", [
("holocamera.bib", "10.1109/TVCG.2024.3372123"),
])
def test_tvcg_doi(filename, correct_doi):
search_and_check_doi(filename, correct_doi)

0 comments on commit 8833952

Please sign in to comment.