|
2 | 2 | import pandas as pd |
3 | 3 | import pytest |
4 | 4 | from scholarly._proxy_generator import MaxTriesExceededException |
5 | | - |
| 5 | +import functools |
6 | 6 |
|
7 | 7 | from paperscraper.scholar import ( |
8 | 8 | get_and_dump_scholar_papers, |
|
13 | 13 | logging.disable(logging.INFO) |
14 | 14 |
|
15 | 15 |
|
16 | | -@pytest.fixture(autouse=True) |
17 | | -def handle_scholar_exceptions(caplog): |
18 | | - caplog.set_level(logging.INFO) |
19 | | - try: |
20 | | - yield |
21 | | - except MaxTriesExceededException as e: |
22 | | - logging.info(f"MaxTriesExceededException caught: {e}") |
23 | | - pytest.skip("Skipping test due to MaxTriesExceededException") |
| 16 | +def handle_scholar_exception(func): |
| 17 | + @functools.wraps(func) |
| 18 | + def wrapper(*args, **kwargs): |
| 19 | + try: |
| 20 | + return func(*args, **kwargs) |
| 21 | + except MaxTriesExceededException as e: |
| 22 | + logging.info(f"MaxTriesExceededException caught: {e}") |
| 23 | + pytest.skip("Skipping test due to MaxTriesExceededException") |
| 24 | + |
| 25 | + return wrapper |
24 | 26 |
|
25 | 27 |
|
26 | 28 | class TestScholar: |
27 | 29 |
|
| 30 | + @handle_scholar_exception |
28 | 31 | def test_citations(self): |
29 | 32 | num = get_citations_from_title("GT4SD") |
30 | 33 | assert isinstance(num, int) |
31 | 34 | assert num > 0 |
32 | 35 |
|
| 36 | + @handle_scholar_exception |
33 | 37 | def test_dump_search(self, tmpdir): |
34 | 38 | temp_dir = tmpdir.mkdir("scholar_papers") |
35 | 39 | output_filepath = temp_dir.join("results.jsonl") |
36 | 40 | get_and_dump_scholar_papers("GT4SD", str(output_filepath)) |
37 | 41 | assert output_filepath.check(file=1) |
38 | 42 |
|
| 43 | + @handle_scholar_exception |
39 | 44 | def test_basic_search(self): |
40 | 45 | results = get_scholar_papers("GT4SD") |
41 | 46 | assert len(results) > 0 # Ensure we get some results |
|
0 commit comments