-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from radionets-project/add_tests
Add first tests
- Loading branch information
Showing
6 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- '**' | ||
pull_request: | ||
|
||
env: | ||
MPLBACKEND: Agg | ||
PYTEST_ADDOPTS: --color=yes | ||
GITHUB_PR_NUMBER: ${{ github.event.number }} | ||
|
||
jobs: | ||
tests: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
include: | ||
- os: ubuntu-latest | ||
python-version: "3.10" | ||
install-method: mamba | ||
|
||
- os: ubuntu-latest | ||
python-version: "3.11" | ||
install-method: mamba | ||
|
||
- os: ubuntu-latest | ||
python-version: "3.11" | ||
install-method: pip | ||
|
||
# macos 13 image is x86-based | ||
- os: macos-13 | ||
python-version: "3.10" | ||
install-method: pip | ||
|
||
# macos 14 image is arm64 based | ||
- os: macos-14 | ||
python-version: "3.11" | ||
install-method: mamba | ||
|
||
defaults: | ||
run: | ||
# We need login shells (-l) for micromamba to work. | ||
shell: bash -leo pipefail {0} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Prepare mamba installation | ||
if: matrix.install-method == 'mamba' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false | ||
env: | ||
PYTHON_VERSION: ${{ matrix.python-version }} | ||
run: | | ||
# setup correct python version | ||
sed -i -e "s/- python.*/- python=$PYTHON_VERSION/g" environment.yml | ||
- name: mamba setup | ||
if: matrix.install-method == 'mamba' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false | ||
uses: mamba-org/setup-micromamba@v1 | ||
with: | ||
environment-file: environment.yml | ||
cache-downloads: true | ||
|
||
- name: Python setup | ||
if: matrix.install-method == 'pip' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
check-latest: true | ||
|
||
- if: matrix.install-method == 'pip' && runner.os == 'macOS' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false | ||
name: Fix Python PATH on macOS | ||
# See https://github.com/actions/setup-python/issues/132 and | ||
# https://github.com/actions/setup-python/issues/132#issuecomment-779406058 | ||
# Login shells on macOS prepend system paths, so we need to | ||
# prepend the python path from actions/setup-python. | ||
# Micromamba sets up ~/.bash_profile, where we need to set the path now. | ||
run: | | ||
tee -a ~/.bash_profile <<<'export PATH="$pythonLocation/bin:$PATH"' | ||
- name: Install dependencies | ||
env: | ||
PYTHON_VERSION: ${{ matrix.python-version }} | ||
run: | | ||
python --version | ||
pip install pytest-cov restructuredtext-lint pytest-xdist 'coverage!=6.3.0' | ||
pip install -e .[all] | ||
pip freeze | ||
pip list | ||
- name: List installed package versions (conda) | ||
if: matrix.environment-type == 'mamba' | ||
run: micromamba list | ||
|
||
- name: Tests | ||
run: | | ||
pytest --cov | ||
docs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install doc dependencies | ||
run: | | ||
sudo apt update --yes && sudo apt install --yes git | ||
pip install -U pip towncrier | ||
- name: Produce Changelog | ||
run: | | ||
towncrier build --yes --version==0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Add simple tests for ``radiotools.visibility.SourceVisibility`` class and ``radiotools.layouts.Layout`` class | ||
- Add CI for tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: radiotools-dev | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- python=3.11 | ||
- pip | ||
- astropy >=6.1.0 | ||
- matplotlib ~=3.0 | ||
- numpy ~=1.16 | ||
- pandas >=2.0 | ||
- rich >=13.0 | ||
- requests | ||
- bs4 | ||
- towncrier | ||
- pip: | ||
- casatools ~=6.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def test_layouts(): | ||
from radiotools.layouts import Layout | ||
|
||
BASE_URL = "https://raw.githubusercontent.com/radionets-project/" | ||
BASE_URL += "pyvisgen/refs/heads/main/pyvisgen/layouts/" | ||
|
||
layout = Layout.from_url(BASE_URL + "eht.txt") | ||
|
||
assert len(layout.names) == 8 | ||
|
||
names = ["ALMA50", "SMTO", "LMT", "Hawaii8", "PV", "PdBI", "SPT", "GLT"] | ||
assert set(layout.names) == set(names) | ||
|
||
assert layout.x.dtype == "float64" | ||
assert layout.y.dtype == "float64" | ||
assert layout.z.dtype == "float64" | ||
|
||
x = [2225037.1851, -1828796.2, -768713.9637] | ||
y = [-5441199.162, -5054406.8, -5988541.7982] | ||
z = [-2479303.4629, 3427865.2, 2063275.9472] | ||
dish_dia = [84.700000, 10.000000, 50.000000] | ||
el_low = [15.000000, 15.000000, 15.000000] | ||
el_high = [85.000000, 85.000000, 85.000000] | ||
sefd = [110.0, 11900.0, 560.0] | ||
altitude = [5030.0, 3185.0, 4640.0] | ||
|
||
assert set(layout.x[:3]) == set(x) | ||
assert set(layout.y[:3]) == set(y) | ||
assert set(layout.z[:3]) == set(z) | ||
assert set(layout.dish_dia[:3]) == set(dish_dia) | ||
assert set(layout.el_low[:3]) == set(el_low) | ||
assert set(layout.el_high[:3]) == set(el_high) | ||
assert set(layout.sefd[:3]) == set(sefd) | ||
assert set(layout.altitude[:3]) == set(altitude) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from contextlib import contextmanager | ||
|
||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
|
||
|
||
@contextmanager | ||
def assert_num_figures(): | ||
n_fig_prev = plt.gcf().number | ||
yield | ||
n_fig_after = plt.gcf().number | ||
assert n_fig_prev < n_fig_after | ||
|
||
|
||
def test_source_visibility(): | ||
from radiotools.visibility import SourceVisibility | ||
|
||
sv = SourceVisibility( | ||
target="M87", | ||
date="2024-10-03", | ||
location="vlba", | ||
obs_length=4.0, | ||
frame="icrs", | ||
print_optimal_date=False, | ||
) | ||
|
||
with assert_num_figures(): | ||
sv.plot() | ||
|
||
dates = sv.get_optimal_date() | ||
|
||
expected_dates = [ | ||
pd.Timestamp("2024-10-03 17:05:56"), | ||
pd.Timestamp("2024-10-03 19:05:56"), | ||
pd.Timestamp("2024-10-03 21:05:56"), | ||
] | ||
|
||
assert dates == expected_dates |