Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elanaku committed Sep 30, 2024
1 parent 0983171 commit d9ef3d4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/auxtel/test_latiss_take_twilight_flats.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import unittest
import unittest.mock as mock
import warnings

import pytest
from lsst.ts import externalscripts, salobj, standardscripts
from lsst.ts.externalscripts.auxtel.latiss_take_twilight_flats import (
TakeTwilightFlatsLatiss,
)

try:
from lsst.summit.utils import ConsDbClient

CONSDB_AVAILABLE = True
except ImportError:
CONSDB_AVAILABLE = False
warnings.warn("Cannot import summit utils. Most tests will be skipped.")


class TestTakeTwilightFlatsLatiss(
standardscripts.BaseScriptTestCase, unittest.IsolatedAsyncioTestCase
Expand All @@ -33,6 +42,18 @@ def mock_camera(self):
self.script.latiss.assert_all_enabled = mock.AsyncMock()
self.script.latiss.take_focus = mock.AsyncMock(return_value=[1234])

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_consdb.",
)
async def test_consdb(self):

self.client = ConsDbClient()

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_configure.",
)
async def test_configure(self):

config = {
Expand All @@ -52,6 +73,10 @@ async def test_configure(self):
assert self.script.config.dither == 10.0
assert self.script.config.max_exp_time == 300

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_invalid_configuration.",
)
async def test_invalid_configuration(self):
bad_configs = [
{
Expand All @@ -66,6 +91,10 @@ async def test_invalid_configuration(self):
with pytest.raises(salobj.ExpectedError):
await self.configure_script(**bad_config)

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_take_twilight_flats.",
)
async def test_take_twilight_flats(self):
config = {
"filter": "SDSSr_65mm",
Expand All @@ -82,5 +111,5 @@ async def test_take_twilight_flats(self):

async def test_executable(self):
scripts_dir = externalscripts.get_scripts_dir()
script_path = scripts_dir / "auxtel" / "take_twilight_flats_latiss.py"
script_path = scripts_dir / "auxtel" / "latiss_take_twilight_flats.py"
await self.check_executable(script_path)
29 changes: 29 additions & 0 deletions tests/maintel/test_take_twilight_flats_comcam.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import unittest
import unittest.mock as mock
import warnings

import pytest
from lsst.ts import externalscripts, salobj, standardscripts
from lsst.ts.externalscripts.maintel.take_twilight_flats_comcam import (
TakeTwilightFlatsComCam,
)

try:
from lsst.summit.utils import ConsDbClient

CONSDB_AVAILABLE = True
except ImportError:
CONSDB_AVAILABLE = False
warnings.warn("Cannot import summit utils. Most tests will be skipped.")


class TestTakeTwilightFlatsComCam(
standardscripts.BaseScriptTestCase, unittest.IsolatedAsyncioTestCase
Expand All @@ -33,6 +42,18 @@ def mock_camera(self):
self.script.comcam.assert_all_enabled = mock.AsyncMock()
self.script.comcam.take_imgtype = mock.AsyncMock(return_value=[1234])

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_consdb.",
)
async def test_consdb(self):

self.client = ConsDbClient()

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_configure.",
)
async def test_configure(self):

config = {
Expand All @@ -50,6 +71,10 @@ async def test_configure(self):
assert self.script.config.dither == 10
assert self.script.config.max_exp_time == 300

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_invalid_configuration.",
)
async def test_invalid_configuration(self):
bad_configs = [
{
Expand All @@ -63,6 +88,10 @@ async def test_invalid_configuration(self):
with pytest.raises(salobj.ExpectedError):
await self.configure_script(**bad_config)

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_take_twilight_flats.",
)
async def test_take_twilight_flats(self):
config = {
"filter": "r_03",
Expand Down
29 changes: 29 additions & 0 deletions tests/maintel/test_take_twilight_flats_lsstcam.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import unittest
import unittest.mock as mock
import warnings

import pytest
from lsst.ts import externalscripts, salobj, standardscripts
from lsst.ts.externalscripts.maintel.take_twilight_flats_lsstcam import (
TakeTwilightFlatsLSSTCam,
)

try:
from lsst.summit.utils import ConsDbClient

CONSDB_AVAILABLE = True
except ImportError:
CONSDB_AVAILABLE = False
warnings.warn("Cannot import summit utils. Most tests will be skipped.")


class TestTakeTwilightFlatsLSSTCam(
standardscripts.BaseScriptTestCase, unittest.IsolatedAsyncioTestCase
Expand All @@ -33,6 +42,18 @@ def mock_camera(self):
self.script.lsstcam.assert_all_enabled = mock.AsyncMock()
self.script.lsstcam.take_focus = mock.AsyncMock(return_value=[1234])

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_consdb.",
)
async def test_consdb(self):

self.client = ConsDbClient()

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_configure.",
)
async def test_configure(self):

config = {
Expand All @@ -50,6 +71,10 @@ async def test_configure(self):
assert self.script.config.dither == 10
assert self.script.config.max_exp_time == 300

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_invalid_configuration.",
)
async def test_invalid_configuration(self):
bad_configs = [
{
Expand All @@ -63,6 +88,10 @@ async def test_invalid_configuration(self):
with pytest.raises(salobj.ExpectedError):
await self.configure_script(**bad_config)

@unittest.skipIf(
CONSDB_AVAILABLE is False,
f"ConsDB package availibility is {CONSDB_AVAILABLE}. Skipping test_take_twilight_flats.",
)
async def test_take_twilight_flats(self):
config = {
"filter": "r_03",
Expand Down

0 comments on commit d9ef3d4

Please sign in to comment.