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

DM-38400: Add ability to check that altaz is defined in tests #67

Merged
merged 7 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -45,9 +45,9 @@ jobs:
run: pytest -r a -v -n 3 --open-files --cov=astro_metadata_translator --cov=tests --cov-report=xml --cov-report=term --cov-branch

- name: Upload coverage to codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
files: ./coverage.xml

- name: Install documenteer
run: pip install -r doc/requirements.txt
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.4.0
hooks:
- id: check-yaml
args:
- "--unsafe"
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
Expand All @@ -17,11 +17,11 @@ repos:
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.10
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
1 change: 0 additions & 1 deletion python/astro_metadata_translator/bin/translateheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def read_file(
md = {k: v for k, v in md.items()}

if output_mode in ("yaml", "fixed"):

if output_mode == "fixed":
fix_header(md, filename=file)

Expand Down
2 changes: 0 additions & 2 deletions python/astro_metadata_translator/cli/astrometadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def main(ctx: click.Context, log_level: int, traceback: bool, packages: Sequence
def translate(
ctx: click.Context, files: Sequence[str], quiet: bool, hdrnum: int, mode: str, regex: str
) -> None:

# For quiet mode we want to translate everything but report nothing.
if quiet:
mode = "none"
Expand Down Expand Up @@ -153,7 +152,6 @@ def translate(
@regex_option
@click.pass_context
def dump(ctx: click.Context, files: Sequence[str], hdrnum: int, mode: str, regex: str) -> None:

okay, failed = translate_header(files, regex, hdrnum, ctx.obj["TRACEBACK"], output_mode=mode)

if failed:
Expand Down
2 changes: 0 additions & 2 deletions python/astro_metadata_translator/observationInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def __init__(
required: Optional[Set[str]] = None,
subset: Optional[Set[str]] = None,
) -> None:

# Initialize the empty object
self._header: MutableMapping[str, Any] = {}
self.filename = filename
Expand Down Expand Up @@ -577,7 +576,6 @@ def from_simple(cls, simple: MutableMapping[str, Any]) -> ObservationInfo:

processed: Dict[str, Any] = {}
for k, v in simple.items():

if v is None:
continue

Expand Down
26 changes: 22 additions & 4 deletions python/astro_metadata_translator/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@


# For YAML >= 5.1 need a different Loader for the constructor
Loader: Type[yaml.Loader] | Type[yaml.FullLoader]
try:
Loader: Optional[Type] = yaml.FullLoader
Loader = yaml.FullLoader
except AttributeError:
Loader = yaml.Loader

Expand Down Expand Up @@ -107,7 +108,7 @@ def assertAlmostEqual( # noqa: N802
) -> None:
pass

def assertIsNotNone(self, a: Any) -> None: # noqa: N802
def assertIsNotNone(self, a: Any, msg: str | None = None) -> None: # noqa: N802
pass

def assertEqual(self, a: Any, b: Any, msg: Optional[str] = None) -> None: # noqa: N802
Expand Down Expand Up @@ -165,6 +166,7 @@ def assertObservationInfoFromYaml( # noqa: N802
dir: Optional[str] = None,
check_wcs: bool = True,
wcs_params: Optional[Dict[str, Any]] = None,
check_altaz: bool = False,
**kwargs: Any,
) -> None:
"""Check contents of an ObservationInfo.
Expand All @@ -179,6 +181,8 @@ def assertObservationInfoFromYaml( # noqa: N802
Check the consistency of the RA/Dec and AltAz values.
wcs_params : `dict`, optional
Parameters to pass to `assertCoordinatesConsistent`.
check_altaz : `bool`, optional
Check that an alt/az value has been calculated.
kwargs : `dict`
Keys matching `ObservationInfo` properties with values
to be tested.
Expand All @@ -202,17 +206,25 @@ def assertObservationInfoFromYaml( # noqa: N802
for hdr in (header, astropy_header):
try:
self.assertObservationInfo(
header, filename=file, check_wcs=check_wcs, wcs_params=wcs_params, **kwargs
header,
filename=file,
check_wcs=check_wcs,
wcs_params=wcs_params,
check_altaz=check_altaz,
**kwargs,
)
except AssertionError as e:
raise AssertionError(f"ObservationInfo derived from {type(hdr)} type is inconsistent.") from e
raise AssertionError(
f"ObservationInfo derived from {type(hdr)} type is inconsistent: {e}"
) from e

def assertObservationInfo( # noqa: N802
self,
header: MutableMapping[str, Any],
filename: Optional[str] = None,
check_wcs: bool = True,
wcs_params: Optional[Dict[str, Any]] = None,
check_altaz: bool = False,
**kwargs: Any,
) -> None:
"""Check contents of an ObservationInfo.
Expand All @@ -229,6 +241,8 @@ def assertObservationInfo( # noqa: N802
not appear to be "science".
wcs_params : `dict`, optional
Parameters to pass to `assertCoordinatesConsistent`.
check_altaz : `bool`, optional
Check that an alt/az value has been calculated.
kwargs : `dict`
Keys matching `ObservationInfo` properties with values
to be tested.
Expand Down Expand Up @@ -285,6 +299,10 @@ def _format_date_for_testing(date: Optional[Time]) -> Optional[Time]:
# Check that exposure time is not outside datetime_end
self.assertLessEqual(obsinfo.datetime_begin + obsinfo.exposure_time, obsinfo.datetime_end)

# Do we expect an AltAz value or not.
if check_altaz:
self.assertIsNotNone(obsinfo.altaz_begin, "altaz_begin is None but should have a value")

# Check the WCS consistency
if check_wcs and obsinfo.observation_type == "science":
if wcs_params is None:
Expand Down
1 change: 1 addition & 0 deletions tests/test_decam.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def test_decam_translator(self):
temperature=15.1 * u.deg_C,
visit_id=845291,
wcs_params=dict(max_sep=5.0),
check_altaz=True,
),
),
)
Expand Down
1 change: 0 additions & 1 deletion tests/test_shadowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def to_instrument(self):

class TranslatorShadowing(unittest.TestCase):
def test_shadowing(self):

with self.assertLogs("astro_metadata_translator", level="WARN") as cm:

class ShadowTranslator(StubTranslator):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_translate_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def test_translate_header_traceback(self):
)

lines = self._readlines(out)
self.assertEqual(len(lines), 22)
self.assertGreaterEqual(len(lines), 22, "\n".join(lines))
self.assertTrue(lines[0].startswith("Traceback"), f"Line '{lines[0]}'")

lines = self._readlines(err)
self.assertEqual(len(lines), 13)
self.assertGreaterEqual(len(lines), 13, "\n".join(lines))
self.assertTrue(lines[0].startswith("Analyzing"), f"Line: '{lines[0]}'")

self.assertEqual(len(okay), 10)
Expand Down
1 change: 0 additions & 1 deletion tests/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def setUp(self):
}

def test_manual_translation(self):

header = self.header
translator = FitsTranslator(header)

Expand Down