Skip to content

Commit

Permalink
Add some basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timbeccue committed Dec 11, 2024
1 parent 2f49e8f commit 0e27f8b
Show file tree
Hide file tree
Showing 4 changed files with 471 additions and 1 deletion.
31 changes: 30 additions & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,39 @@ on:
- 'README.md'

jobs:
deploy:
test:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE
- name: Check out repository
uses: actions/checkout@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.SLS_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SLS_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

# Install Python dependencies
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Run tests
- name: Run tests
run: python -m pytest

deploy:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- name: Set up Node
Expand Down
305 changes: 305 additions & 0 deletions test_data/sample_observation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
{
"site": "mrc",
"enclosure": "enc1",
"telescope": "0m35",
"observation_type": "NORMAL",
"state": "PENDING",
"id": 583116837,
"request_group_id": 1885213,
"created": "2024-11-01T14:04:10.425775Z",
"modified": "2024-11-01T14:04:10.425770Z",
"start": "2024-11-02T07:22:14Z",
"end": "2024-11-02T07:26:56Z",
"name": "Full Detailed Observation",
"submitter": "tbeccue",
"proposal": "LCOSchedulerTest",
"ipp_value": 1.05,
"priority": 10,
"request": {
"id": 3445199,
"modified": "2024-10-29T14:57:32.128148Z",
"state": "PENDING",
"duration": 282,
"acceptability_threshold": 90.0,
"optimization_type": "TIME",
"observation_note": "",
"extra_params": {},
"configuration_repeats": 2,
"configurations": [
{
"id": 10840779,
"configuration_status": 750648588,
"instrument_name": "q461",
"instrument_type": "0M35-QHY461",
"priority": 1,
"repeat_duration": null,
"state": "PENDING",
"summary": {},
"type": "EXPOSE",
"target": {
"dec": -7.6528696608383,
"epoch": 2000.0,
"extra_params": {},
"hour_angle": null,
"name": "40 Eridani",
"parallax": 199.608,
"proper_motion_dec": -3421.809,
"proper_motion_ra": -2240.085,
"ra": 63.8179984124771,
"type": "ICRS"
},
"instrument_configs": [
{
"exposure_count": 1,
"exposure_time": 15.0,
"extra_params": {
"offset_dec": 1,
"offset_ra": 2,
"rotator_angle": 5
},
"mode": "Full",
"optical_elements": {
"filter": "mrc-L"
},
"rois": [],
"rotator_mode": "RPA"
},
{
"exposure_count": 2,
"exposure_time": 10.0,
"extra_params": {
"offset_dec": 0,
"offset_ra": 0,
"rotator_angle": 0
},
"mode": "Full",
"optical_elements": {
"filter": "mrc-R"
},
"rois": [],
"rotator_mode": "RPA"
}
],
"acquisition_config": {
"extra_params": {},
"mode": "OFF"
},
"constraints": {
"extra_params": {},
"max_airmass": 1.6,
"max_lunar_phase": 1.0,
"min_lunar_distance": 30.0
},
"extra_params": {
"dither_pattern": "custom"
},
"guide_camera_name": "mrc-qhy461",
"guiding_config": {
"exposure_time": null,
"extra_params": {},
"mode": "ON",
"optical_elements": {},
"optional": true
}
},
{
"acquisition_config": {
"extra_params": {},
"mode": "OFF"
},
"configuration_status": 750648589,
"constraints": {
"extra_params": {},
"max_airmass": 1.6,
"max_lunar_phase": 1.0,
"min_lunar_distance": 30.0
},
"extra_params": {
"dither_pattern": "custom"
},
"guide_camera_name": "mrc-qhy461",
"guiding_config": {
"exposure_time": null,
"extra_params": {},
"mode": "ON",
"optical_elements": {},
"optional": true
},
"id": 10840780,
"instrument_configs": [
{
"exposure_count": 1,
"exposure_time": 15.0,
"extra_params": {
"offset_dec": 1,
"offset_ra": 2,
"rotator_angle": 5
},
"mode": "Full",
"optical_elements": {
"filter": "mrc-L"
},
"rois": [],
"rotator_mode": "RPA"
}
],
"instrument_name": "q461",
"instrument_type": "0M35-QHY461",
"priority": 2,
"repeat_duration": null,
"state": "PENDING",
"summary": {},
"target": {
"dec": 41.26875,
"epoch": 2000.0,
"extra_params": {},
"hour_angle": null,
"name": "m31",
"parallax": 0.0,
"proper_motion_dec": 0.0,
"proper_motion_ra": 0.0,
"ra": 10.684708,
"type": "ICRS"
},
"type": "EXPOSE"
},
{
"acquisition_config": {
"extra_params": {},
"mode": "OFF"
},
"configuration_status": 750648590,
"constraints": {
"extra_params": {},
"max_airmass": 1.6,
"max_lunar_phase": 1.0,
"min_lunar_distance": 30.0
},
"extra_params": {
"dither_pattern": "custom"
},
"guide_camera_name": "mrc-qhy461",
"guiding_config": {
"exposure_time": null,
"extra_params": {},
"mode": "ON",
"optical_elements": {},
"optional": true
},
"id": 10840779,
"instrument_configs": [
{
"exposure_count": 1,
"exposure_time": 15.0,
"extra_params": {
"offset_dec": 1,
"offset_ra": 2,
"rotator_angle": 5
},
"mode": "Full",
"optical_elements": {
"filter": "mrc-L"
},
"rois": [],
"rotator_mode": "RPA"
},
{
"exposure_count": 2,
"exposure_time": 10.0,
"extra_params": {
"offset_dec": 0,
"offset_ra": 0,
"rotator_angle": 0
},
"mode": "Full",
"optical_elements": {
"filter": "mrc-R"
},
"rois": [],
"rotator_mode": "RPA"
}
],
"instrument_name": "q461",
"instrument_type": "0M35-QHY461",
"priority": 3,
"repeat_duration": null,
"state": "PENDING",
"summary": {},
"target": {
"dec": -7.6528696608383,
"epoch": 2000.0,
"extra_params": {},
"hour_angle": null,
"name": "40 Eridani",
"parallax": 199.608,
"proper_motion_dec": -3421.809,
"proper_motion_ra": -2240.085,
"ra": 63.8179984124771,
"type": "ICRS"
},
"type": "EXPOSE"
},
{
"acquisition_config": {
"extra_params": {},
"mode": "OFF"
},
"configuration_status": 750648591,
"constraints": {
"extra_params": {},
"max_airmass": 1.6,
"max_lunar_phase": 1.0,
"min_lunar_distance": 30.0
},
"extra_params": {
"dither_pattern": "custom"
},
"guide_camera_name": "mrc-qhy461",
"guiding_config": {
"exposure_time": null,
"extra_params": {},
"mode": "ON",
"optical_elements": {},
"optional": true
},
"id": 10840780,
"instrument_configs": [
{
"exposure_count": 1,
"exposure_time": 15.0,
"extra_params": {
"offset_dec": 1,
"offset_ra": 2,
"rotator_angle": 5
},
"mode": "Full",
"optical_elements": {
"filter": "mrc-L"
},
"rois": [],
"rotator_mode": "RPA"
}
],
"instrument_name": "q461",
"instrument_type": "0M35-QHY461",
"priority": 4,
"repeat_duration": null,
"state": "PENDING",
"summary": {},
"target": {
"dec": 41.26875,
"epoch": 2000.0,
"extra_params": {},
"hour_angle": null,
"name": "m31",
"parallax": 0.0,
"proper_motion_dec": 0.0,
"proper_motion_ra": 0.0,
"ra": 10.684708,
"type": "ICRS"
},
"type": "EXPOSE"
}
]
}
}
24 changes: 24 additions & 0 deletions tests/test_import_schedules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
from import_schedules import Observation

with open('./test_data/sample_observation.json', 'r') as file:
sample_observation = json.load(file)

def test_observation_validation():
o = Observation(sample_observation)
assert Observation.validate_observation_format(sample_observation)
assert Observation.validate_observation_format(o.observation)

def test_observation_create_calendar():
o = Observation(sample_observation)
assert not hasattr(o, "calendar_event")
o._translate_to_calendar()
assert hasattr(o, "calendar_event")

def test_observation_create_project():
o = Observation(sample_observation)
assert not hasattr(o, "project")
o._translate_to_project()
assert hasattr(o, "project")


Loading

0 comments on commit 0e27f8b

Please sign in to comment.