Spaces:
Running
on
Zero
Running
on
Zero
| import os | |
| from typing import TYPE_CHECKING | |
| from unittest.mock import patch | |
| import httpx | |
| import pytest | |
| from ether0.clients import fetch_forward_rxn, fetch_purchasable, fetch_solubility | |
| if TYPE_CHECKING: | |
| from fastapi.testclient import TestClient | |
| IN_GITHUB_ACTIONS: bool = os.getenv("GITHUB_ACTIONS") == "true" | |
| def test_fetch_purchasable( | |
| test_client: "TestClient", smiles: str, purchasable: bool | |
| ) -> None: | |
| with patch.object(httpx, "post", test_client.post): | |
| assert fetch_purchasable(smiles)[smiles] == purchasable | |
| def test_fetch_solubility( | |
| test_client: "TestClient", smiles: str, solubility: float | |
| ) -> None: | |
| with patch.object(httpx, "post", test_client.post): | |
| result = fetch_solubility(smiles) | |
| assert "solubility" in result | |
| assert pytest.approx(result["solubility"], abs=0.1) == solubility | |
| def test_fetch_forward_rxn( | |
| test_client: "TestClient", precursor: str, product: str | None, correct: bool | |
| ) -> None: | |
| with patch.object(httpx, "post", test_client.post): | |
| result = fetch_forward_rxn(precursor) | |
| if correct: | |
| assert ( | |
| result.get("product") == product | |
| ), f"Failed to get expected {product=} in {result=}." | |
| assert "error" not in result | |
| else: | |
| assert result.get( | |
| "error" | |
| ), f"Expected an error given {precursor=} and {correct=}" | |
| assert "syntax error" in result["error"].lower() | |
| assert "product" not in result | |