Skip to content

Commit

Permalink
Merge pull request #9 from matteobachetti/add_tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
matteobachetti authored Dec 17, 2022
2 parents 656ece3 + afdd831 commit d5c61e6
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ell1fit/ell1fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ def assign_logpriors(


def order_of_magnitude(value):
return 10 ** np.int(np.log10(np.abs(value)) - 1)
return 10 ** int(np.log10(np.abs(value)) - 1)


def get_factors(parnames, model, observation_length):
Expand Down
Binary file added ell1fit/tests/data/events0.nc
Binary file not shown.
27 changes: 27 additions & 0 deletions ell1fit/tests/data/events0.par
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Created: 2022-05-03T20:36:51.557233
# PINT_version: 0.8.5
# User: meo
# Host: portabile3.home-life.hub
# OS: macOS-10.16-x86_64-i386-64bit
# Format: pint
PSR Dummy
EPHEM DE421
RAJ 9:55:51.04010000
DECJ 69:40:45.49010000
PMRA 0.0
PMDEC 0.0
F0 7.5 0.000000000001
F1 0.0
PEPOCH 56357
PLANET_SHAPIRO N
BINARY ELL1
PB 2.532971 0.000001
PBDOT 0
A1 22.215 0.001
TASC 56682.0669000000000000 0.00000001
EPS1 0.0
EPS2 0.0
TZRMJD 56699.5093620635053249
TZRSITE ssb
TZRFRQ inf

Binary file added ell1fit/tests/data/events1.nc
Binary file not shown.
27 changes: 27 additions & 0 deletions ell1fit/tests/data/events1.par
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Created: 2022-05-03T20:36:51.557233
# PINT_version: 0.8.5
# User: meo
# Host: portabile3.home-life.hub
# OS: macOS-10.16-x86_64-i386-64bit
# Format: pint
PSR Dummy
EPHEM DE421
RAJ 9:55:51.04010000
DECJ 69:40:45.49010000
PMRA 0.0
PMDEC 0.0
F0 7.5 0.000000000001
F1 0.0
PEPOCH 56357
PLANET_SHAPIRO N
BINARY ELL1
PB 2.532971 0.000001
PBDOT 0
A1 22.215 0.001
TASC 56682.0669000000000000 0.00000001
EPS1 0.0
EPS2 0.0
TZRMJD 56699.5093620635053249
TZRSITE ssb
TZRFRQ inf

42 changes: 42 additions & 0 deletions ell1fit/tests/test_execution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import glob
from ell1fit.ell1fit import main as main_ell1fit
from ell1fit.create_parfile import main as main_ell1par


curdir = os.path.abspath(os.path.dirname(__file__))
datadir = os.path.join(curdir, "data")


class TestExecution():
@classmethod
def setup_class(cls):
cls.event_files = sorted(glob.glob(os.path.join(datadir, "events[01].nc")))
cls.param_files = sorted(glob.glob(os.path.join(datadir, "events[01].par")))

def test_ell1fit_and_ell1par(self):
cmdlines = self.event_files + ["-p"] + self.param_files + ["-P", "F0,PB,A1,TASC"]

cmdline1 = cmdlines + ["--nsteps", "100"]
cmdline2 = cmdlines + ["--nsteps", "200"]

# Get to 100, then continue up to 200
main_ell1fit(cmdline1)
main_ell1fit(cmdline2)

outputs = sorted(glob.glob(os.path.join(datadir, "events[01]_A1_F0_PB_TASC_results.ecsv")))
for out in outputs:
assert os.path.exists(out)

main_ell1par(f"{outputs[0]} -p {self.param_files[0]}".split())
main_ell1par(f"{outputs[1]} -p {self.param_files[1]}".split())

out_param = sorted(glob.glob(os.path.join(datadir, "events[01]_A1_F0_PB_TASC_results.par")))
for out in out_param:
assert os.path.exists(out)

@classmethod
def teardown_class(cls):
outs = glob.glob(os.path.join(datadir, '*A1_*TASC*'))
for out in outs:
os.remove(out)
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ install_requires =
stingray
hendrics
colorama
netcdf4
h5py
pyyaml


[options.extras_require]
Expand All @@ -37,6 +40,7 @@ docs =

[options.package_data]
ell1fit = data/*
ell1fit.tests = data/*

[tool:pytest]
testpaths = "ell1fit" "docs"
Expand Down

0 comments on commit d5c61e6

Please sign in to comment.