Yuan1z0825/nature-skills / skills/nature-academic-search
nature-academic-search
FlaggedSearch literature across sources, verify or manage citations, and build MeSH strategies or citation-impact audits. Use for 文献检索、引文核对、参考文献管理、严格他引 and evidence-backed citer profiles; not for translating a paper or drafting manuscript prose.
mcp-server/tests/test_script_converters.py
View on GitHub"""Regression tests for the stand-alone converter scripts (no network access)."""
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
from unittest.mock import MagicMock, patch
SCRIPTS = Path(__file__).resolve().parents[2] / "scripts"
def _load(name: str, filename: str):
if str(SCRIPTS) not in sys.path:
sys.path.insert(0, str(SCRIPTS))
spec = importlib.util.spec_from_file_location(name, SCRIPTS / filename)
assert spec and spec.loader
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)
return module
converters = _load("nature_search_converters", "converters.py")
format_converter = _load("nature_search_format_converter", "format-converter.py")
def test_format_converter_imports_urlopen_for_real_downloads():
response = MagicMock()
response.__enter__.return_value.read.return_value = b"PMID- 1\n"
with patch.object(format_converter, "urlopen", return_value=response) as opened:
assert format_converter.efetch_medline("1") == "PMID- 1\n"
opened.assert_called_once()
def test_ris_escape_keeps_comparison_operators():
assert converters.ris_escape("Effect at p<0.05 and p>0.01") == "Effect at p<0.05 and p>0.01"
def test_ris_escape_still_strips_markup():
assert converters.ris_escape("Role of <i>E. coli</i> in <b>disease</b>") == "Role of E. coli in disease"
assert converters.ris_escape("line<br/>break") == "line break"
def test_medline_bibtex_authors_are_surname_comma_initials():
fields = {"PMID": ["1"], "AU": ["Smith J", "Doe AB", "Van Der Berg JJ"], "TI": ["T"]}
bib = converters.medline_to_bib(fields)
assert "author = { Smith, J and Doe, AB and Van Der Berg, JJ }" in bib
def test_medline_bibtex_leaves_collective_names_alone():
bib = converters.medline_to_bib({"PMID": ["1"], "AU": ["World Health Organization"], "TI": ["T"]})
assert "author = { World Health Organization }" in bib
def test_zero_retries_still_makes_one_attempt(tmp_path):
import json
payload = {"message": {"title": ["A Title"], "author": [{"family": "Smith", "given": "J"}], "issued": {"date-parts": [[2020]]}}}
response = MagicMock()
response.__enter__.return_value.read.return_value = json.dumps(payload).encode()
with patch.object(format_converter, "urlopen", return_value=response), patch.object(format_converter, "DELAY", 0):
ok, name = format_converter.download_crossref("10.1/x", str(tmp_path), "ris", retries=0)
assert ok, name
assert (tmp_path / name).exists()
def test_zero_retries_reports_failure_instead_of_crashing(tmp_path):
with patch.object(format_converter, "urlopen", side_effect=OSError("boom")), patch.object(format_converter, "DELAY", 0):
ok, message = format_converter.download_crossref("10.1/x", str(tmp_path), "ris", retries=0)
assert not ok
assert "boom" in message
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |