Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step 3: Add tests #71

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ htmlcov/
.coverage
.coverage.*
.cache
coverage/
nosetests.xml
coverage.xml
*,cover
.hypothesis/
*.lock

# Translations
*.mo
Expand Down
82 changes: 71 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ build-backend = "setuptools.build_meta"
name = "firefly_client"
version = "3.3.0"
description = "Python API for Firefly: display astronomical data as tables, images, charts, and more!"
authors = [
{name = "IPAC LSST SUIT"}
]
authors = [{ name = "IPAC LSST SUIT" }]
readme = "README.md"
license = {file = "License.txt"}
license = { file = "License.txt" }
requires-python = ">=3.10"
dependencies = [
"websocket-client",
"requests"
]
dependencies = ["websocket-client", "requests"]
keywords = [
"jupyter",
"firefly",
Expand All @@ -25,7 +20,7 @@ keywords = [
"visualization",
"images",
"charts",
"tables"
"tables",
]
classifiers = [
"Intended Audience :: Developers",
Expand All @@ -35,7 +30,7 @@ classifiers = [
"Topic :: Scientific/Engineering :: Astronomy",
"Topic :: Scientific/Engineering :: Visualization",
"Programming Language :: Python",
"Programming Language :: Python :: 3"
"Programming Language :: Python :: 3",
]

[project.urls]
Expand All @@ -48,5 +43,70 @@ docs = [
"Sphinx~=7.1.0",
"sphinx-automodapi",
"pydata-sphinx-theme",
"myst-parser"
"myst-parser",
]
test = [
"pytest>=8.3.4",
"pytest-container>=0.4.3",
"pytest-cov>=6.0.0",
"pytest-doctestplus>=1.4.0",
"pytest-mock>=3.14.0",
"pytest-xdist>=3.6.1",
]
astropy = ["astropy>=6"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can go in test list defined above.


[tool.setuptools]
packages = ["firefly_client"]

[tool.pytest.ini_options]
testpaths = ["firefly_client", "docs", "test"]
doctest_plus = "enabled"
text_file_format = "rst"
addopts = [
"--doctest-rst",
"--numprocesses=4",
"--import-mode=importlib",
"--cov=firefly_client",
"--cov-append",
"--cov-report=term-missing",
"--cov-report=xml:coverage.xml",
"--cov-report=html:coverage",
"--doctest-modules",
]

[tool.coverage.run]
omit = [
"firefly_client/conftest.py",
"firefly_client/*setup_package*",
"firefly_client/tests/*",
"firefly_client/*/tests/*",
"firefly_client/extern/*",
"firefly_client/version*",
"*/firefly_client/conftest.py",
"*/firefly_client/*setup_package*",
"*/firefly_client/tests/*",
"*/firefly_client/*/tests/*",
"*/firefly_client/extern/*",
"*/firefly_client/version*",
]

[tool.coverage.report]
exclude_lines = [
# Have to re-enable the standard pragma
"pragma: no cover",
# Don't complain about packages we have installed
"except ImportError",
# Don't complain if tests don't hit assertions
"raise AssertionError",
"raise NotImplementedError",
# Don't complain about script hooks
"def main(.*):",
# Ignore branches that don't pertain to this version of Python
"pragma: py{ignore_python_version}",
# Don't complain about IPython completion helper
"def _ipython_key_completions_",
# typing.TYPE_CHECKING is False at runtime
"if TYPE_CHECKING:",
# Ignore typing overloads
"@overload",
]
Empty file added test/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from pytest_container import add_logging_level_options, set_logging_level_from_cli_args


def pytest_addoption(parser):
add_logging_level_options(parser)


def pytest_configure(config):
set_logging_level_from_cli_args(config)
19 changes: 19 additions & 0 deletions test/container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import random

from pytest_container.inspect import PortForwarding, NetworkProtocol
from pytest_container.container import Container, EntrypointSelection


FIREFLY_CONTAINER = Container(
url="docker.io/ipac/firefly:latest",
extra_launch_args=["--memory=4g"],
entry_point=EntrypointSelection.AUTO,
forwarded_ports=[
PortForwarding(
container_port=8080,
protocol=NetworkProtocol.TCP,
host_port=random.randint(8000, 65534),
bind_ip="127.0.0.1",
)
],
)
Comment on lines +7 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this! I wasn't aware if this was possible in pytests world. @bsipocz this should also help with CI pipeline in irsa-tutorials - we will have to do some mocking though.

218 changes: 218 additions & 0 deletions test/firefly_slate_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import astropy.utils.data


def download_from(url):
return astropy.utils.data.download_file(url, timeout=120, cache=True)


def load_moving_table(row, col, width, height, fc, cell_id=None):
moving_tbl_name = download_from(
"http://web.ipac.caltech.edu/staff/roby/demo/moving/MOST_results-sample.tbl"
)

r = fc.add_cell(row, col, width, height, "tables", cell_id)
meta_info = {
"datasetInfoConverterId": "SimpleMoving",
"positionCoordColumns": "ra_obj;dec_obj;EQ_J2000",
"datasource": "image_url",
}
tbl_name = fc.upload_file(moving_tbl_name)

if r["success"]:
fc.show_table(
tbl_name,
tbl_id="movingtbl",
title="A moving object table",
page_size=15,
meta=meta_info,
)


def add_simple_m31_image_table(fc):
tbl_name = download_from(
"http://web.ipac.caltech.edu/staff/roby/demo/test-table-m31.tbl"
)

meta_info = {
"positionCoordColumns": "ra_obj;dec_obj;EQ_J2000",
"datasource": "FITS",
}
fc.show_table(
fc.upload_file(tbl_name),
title="A table of m31 images",
page_size=15,
meta=meta_info,
)


def add_simple_image_table(fc):
tbl_name = download_from(
"http://web.ipac.caltech.edu/staff/roby/demo/test-table4.tbl"
)

meta_info = {"datasource": "FITS"}
fc.show_table(
fc.upload_file(tbl_name),
title="A table of simple images",
page_size=15,
meta=meta_info,
)


def add_table_for_chart(fc):
tbl_name = download_from(
"http://web.ipac.caltech.edu/staff/roby/demo/WiseDemoTable.tbl"
)

fc.show_table(
fc.upload_file(tbl_name),
tbl_id="tbl_chart",
title="table for xyplot and histogram",
page_size=15,
)


def load_image(row, col, width, height, fc, cell_id=None):
r = fc.add_cell(row, col, width, height, "images", cell_id)

image_name = download_from(
"http://irsa.ipac.caltech.edu/ibe/data/wise/allsky/4band_p1bm_frm/6a/02206a"
+ "/149/02206a149-w1-int-1b.fits?center=70,20&size=200pix"
)

if r["success"]:
fc.show_fits(
file_on_server=fc.upload_file(image_name),
viewer_id=r["cell_id"],
title="WISE Cutout",
)


def load_image_metadata(row, col, width, height, fc, cell_id=None):
r = fc.add_cell(row, col, width, height, "tableImageMeta", cell_id)

if r["success"]:
fc.show_image_metadata(viewer_id=r["cell_id"])


def load_coverage_image(row, col, width, height, fc, cell_id=None):
r = fc.add_cell(row, col, width, height, "coverageImage", cell_id)

if r["success"]:
fc.show_coverage(viewer_id=r["cell_id"])


def load_moving(row, col, width, height, fc, cell_id=None):
r = fc.add_cell(row, col, width, height, "images", cell_id)

if r["success"]:
v_id = r["cell_id"]
fc.show_fits(
plot_id="m49025b_143_2",
viewer_id=v_id,
OverlayPosition="330.347003;-2.774482;EQ_J2000",
ZoomType="TO_WIDTH_HEIGHT",
Title="49025b143-w2",
plotGroupId="movingGroup",
URL="http://web.ipac.caltech.edu/staff/roby/demo/moving/49025b143-w2-int-1b.fits",
)
fc.show_fits(
plot_id="m49273b_134_2",
viewer_id=v_id,
OverlayPosition="333.539702;-0.779310;EQ_J2000",
ZoomType="TO_WIDTH_HEIGHT",
Title="49273b134-w2",
plotGroupId="movingGroup",
URL="http://web.ipac.caltech.edu/staff/roby/demo/moving/49273b134-w2-int-1b.fits",
)
fc.show_fits(
plot_id="m49277b_135_1",
viewer_id=v_id,
OverlayPosition="333.589054;-0.747251;EQ_J2000",
ZoomType="TO_WIDTH_HEIGHT",
Title="49277b135-w1",
plotGroupId="movingGroup",
URL="http://web.ipac.caltech.edu/staff/roby/demo/moving/49277b135-w1-int-1b.fits",
)
fc.show_fits(
plot_id="m49289b_134_2",
viewer_id=v_id,
OverlayPosition="333.736578;-0.651222;EQ_J2000",
ZoomType="TO_WIDTH_HEIGHT",
Title="49289b134-w2",
plotGroupId="movingGroup",
URL="http://web.ipac.caltech.edu/staff/roby/demo/moving/49289b134-w2-int-1b.fits",
)


def load_xy(row, col, width, height, fc, cell_id=None):
r = fc.add_cell(row, col, width, height, "xyPlots", cell_id)

if r["success"]:
trace1 = {
"tbl_id": "tbl_chart",
"x": "tables::ra1",
"y": "tables::dec1",
"mode": "markers",
"type": "scatter",
"marker": {"size": 4},
}
trace_data = [trace1]

layout_s = {
"title": "Coordinates",
"xaxis": {"title": "ra1 (deg)"},
"yaxis": {"title": "dec1 (deg)"},
}
fc.show_chart(group_id=r["cell_id"], layout=layout_s, data=trace_data)


def load_histogram(row, col, width, height, fc, cell_id=None):
r = fc.add_cell(row, col, width, height, "xyPlots", cell_id)

if r["success"]:
histData = [
{
"type": "fireflyHistogram",
"name": "magzp",
"marker": {"color": "rgba(153, 51, 153, 0.8)"},
"firefly": {
"tbl_id": "tbl_chart",
"options": {
"algorithm": "fixedSizeBins",
"fixedBinSizeSelection": "numBins",
"numBins": 30,
"columnOrExpr": "magzp",
},
},
}
]

layout_hist = {
"title": "Magnitude Zeropoints",
"xaxis": {"title": "magzp"},
"yaxis": {"title": ""},
}
result = fc.show_chart(group_id=r["cell_id"], layout=layout_hist, data=histData)


def load_first_image_in_random(fc):
img_name = download_from(
"http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band2.fits"
)

fc.show_fits(file_on_server=fc.upload_file(img_name))


def load_second_image_in_random(fc):
fc.show_fits(
plot_id="xxq",
Service="TWOMASS",
Title="2mass from service",
ZoomType="LEVEL",
initZoomLevel=2,
SurveyKey="asky",
SurveyKeyBand="k",
WorldPt="10.68479;41.26906;EQ_J2000",
SizeInDeg=".12",
)
Loading