Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest
- name: Run tests
run: pytest
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-ra"
59 changes: 59 additions & 0 deletions tests/test_lightcurves.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import types
import sys, pathlib; sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
sys.modules.setdefault("TripleLensing", types.ModuleType("TripleLensing"))
module = types.ModuleType("TestML");
for name in ["get_crit_caus", "getphis_v3", "get_allimgs_with_mu", "testing"]:
setattr(module, name, lambda *args, **kwargs: None)
sys.modules["TestML"] = module
import numpy as np
import math
import VBMicrolensing
from GCMicrolensing import OneL1S, TwoLens1S


def test_onel1s_light_curve():
t0 = 0.0
tE = 1.0
rho = 0.01
u0 = 0.1
model = OneL1S(t0, tE, rho, [u0])

vb = VBMicrolensing.VBMicrolensing()
vb.RelTol = 1e-3
vb.Tol = 1e-3
vb.astrometry = True

expected = np.array([
vb.ESPLMag2(math.sqrt(u0 ** 2 + tau ** 2), rho)
for tau in model.tau
])
actual = np.array([
model.VBM.ESPLMag2(math.sqrt(u0 ** 2 + tau ** 2), rho)
for tau in model.tau
])

np.testing.assert_allclose(actual, expected, rtol=1e-6)


def test_twolens1s_light_curve():
t0 = 0.0
tE = 1.0
rho = 0.01
u0 = 0.1
q = 1.0
s = 1.5
alpha = 0.0

model = TwoLens1S(t0, tE, rho, [u0], q, s, alpha)
system = model.systems[0]

vb = VBMicrolensing.VBMicrolensing()
vb.RelTol = 1e-3
vb.Tol = 1e-3
vb.astrometry = True

params = [math.log(s), math.log(q), u0, math.radians(alpha), math.log(rho), math.log(tE), t0]
expected, *_ = vb.BinaryLightCurve(params, model.t)

np.testing.assert_allclose(system['mag'], expected, rtol=1e-6)

Loading