|
| 1 | +"""Run fpbasepy's test suite against our live server with seeded test data.""" |
| 2 | + |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +from proteins.factories import ( |
| 9 | + CameraFactory, |
| 10 | + DyeStateFactory, |
| 11 | + FilterFactory, |
| 12 | + LightFactory, |
| 13 | + MicroscopeFactory, |
| 14 | + OpticalConfigFactory, |
| 15 | + ProteinFactory, |
| 16 | + create_egfp, |
| 17 | +) |
| 18 | +from proteins.models import Filter |
| 19 | + |
| 20 | +FPBASEPY_REPO = "https://github.com/tlambert03/fpbasepy" |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture |
| 24 | +def seed_fpbasepy_data(db): |
| 25 | + """Seed database with data expected by fpbasepy tests.""" |
| 26 | + # Proteins expected by tests |
| 27 | + create_egfp() |
| 28 | + ProteinFactory( |
| 29 | + name="mScarlet-I", |
| 30 | + default_state__name="default", |
| 31 | + default_state__ex_max=569, |
| 32 | + default_state__em_max=593, |
| 33 | + default_state__ext_coeff=104000, |
| 34 | + default_state__qy=0.54, |
| 35 | + ) |
| 36 | + ProteinFactory( |
| 37 | + name="mEos3.2", |
| 38 | + default_state__name="default", |
| 39 | + default_state__ex_max=507, |
| 40 | + default_state__em_max=516, |
| 41 | + default_state__ext_coeff=63400, |
| 42 | + default_state__qy=0.84, |
| 43 | + ) |
| 44 | + # Additional proteins for pdb test |
| 45 | + ProteinFactory(name="Clover1.5") |
| 46 | + ProteinFactory(name="6C") |
| 47 | + ProteinFactory(name="dClover2 A206K") |
| 48 | + |
| 49 | + # Dye expected by tests |
| 50 | + DyeStateFactory(dye__name="Alexa Fluor 488", name="default") |
| 51 | + |
| 52 | + # Filters expected by tests |
| 53 | + FilterFactory(name="Chroma ET525/50m", subtype=Filter.BPM) |
| 54 | + FilterFactory(name="Semrock FF01-520/35", subtype=Filter.BP) |
| 55 | + |
| 56 | + # Camera and light source |
| 57 | + CameraFactory(name="Andor Zyla 5.5") |
| 58 | + LightFactory(name="Lumencor Celesta UV") |
| 59 | + |
| 60 | + # Microscope with optical configs |
| 61 | + scope = MicroscopeFactory(name="Example Simple Widefield", id="wKqWbgApvguSNDSRZNSfpN") |
| 62 | + ex_filter = FilterFactory(name="Chroma ET470/40x", subtype=Filter.BPX) |
| 63 | + bs_filter = FilterFactory(name="Chroma T495lpxr", subtype=Filter.LP) |
| 64 | + em_filter = FilterFactory(name="Chroma ET525/50m-2", subtype=Filter.BPM) |
| 65 | + oc = OpticalConfigFactory(name="Widefield Green", microscope=scope) |
| 66 | + oc.filters.add(ex_filter, through_defaults={"path": "EX"}) |
| 67 | + oc.filters.add(bs_filter, through_defaults={"path": "BS"}) |
| 68 | + oc.filters.add(em_filter, through_defaults={"path": "EM"}) |
| 69 | + |
| 70 | + |
| 71 | +@pytest.mark.django_db(transaction=True) |
| 72 | +def test_fpbasepy_upstream_suite(live_server, tmp_path, seed_fpbasepy_data): |
| 73 | + """Clone and run fpbasepy's test suite against our GraphQL API.""" |
| 74 | + repo = tmp_path / "fpbasepy" |
| 75 | + |
| 76 | + # Clone and install |
| 77 | + subprocess.run(["git", "clone", "--depth=1", FPBASEPY_REPO, str(repo)], check=True) |
| 78 | + env = {k: v for k, v in os.environ.items() if k != "UV_FROZEN"} |
| 79 | + subprocess.run(["uv", "sync", "--extra", "test", "-q"], cwd=repo, env=env, check=True) |
| 80 | + |
| 81 | + # Patch URL to point at live server |
| 82 | + (repo / "tests" / "conftest.py").write_text(f"""\ |
| 83 | +import fpbase._fetch |
| 84 | +fpbase._fetch.FPbaseClient._FPbaseClient__instance = fpbase._fetch.FPbaseClient( |
| 85 | + base_url="{live_server.url}/graphql/" |
| 86 | +) |
| 87 | +""") |
| 88 | + |
| 89 | + # Run tests (exclude test_get_missing_protein - it tests fpbasepy's fuzzy matching) |
| 90 | + env = {k: v for k, v in os.environ.items() if not k.startswith(("VIRTUAL_ENV", "DJANGO"))} |
| 91 | + result = subprocess.run( |
| 92 | + ["uv", "run", "pytest", "tests", "-v", "-s", "-k", "not test_get_missing"], |
| 93 | + cwd=repo, |
| 94 | + env=env, |
| 95 | + ) |
| 96 | + assert result.returncode == 0, "fpbasepy test suite failed" |
0 commit comments