Skip to content

Commit

Permalink
fix(observers): Correct Offset namedtuple name. (#3)
Browse files Browse the repository at this point in the history
If we lie about the the name of the namedtuple, it isn't pickleable.

Also, the start of a test-suite
  • Loading branch information
ketiltrout authored Aug 16, 2024
1 parent ea10f69 commit 47569d2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ch_ephem-tests
on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
run-tests:

strategy:
matrix:
python-version: ["3.9", "3.12"]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install pip dependencies
run: pip install -e .[test]

- name: Run tests
run: pytest -v .
4 changes: 2 additions & 2 deletions ch_ephem/observers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
_observers = None

# tangent-space offset representation.
_offset = namedtuple("Offset", ["x", "y", "z"])
Offset = namedtuple("Offset", ["x", "y", "z"])


class Observer(CaputObserver):
Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(
super().__init__(lon, lat, alt, lsd_start, sf_wrapper)
self.rotation = rot
self.roll = roll
self.offset = _offset(*offset)
self.offset = Offset(*offset)


def all() -> dict[str, Observer]:
Expand Down
31 changes: 31 additions & 0 deletions tests/test_observers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Test ch_ephem.observers"""

import pickle

from ch_ephem import observers


def test_pickle_observers():
"""Observers should be picklable."""

# These are all small powers of two to
# avoid floating-point shennanigans
test = observers.Observer(lat=1, lon=2, alt=4, rot=8, roll=16, offset=(32, 64, 128))

pickled = pickle.dumps(test)
assert pickled is not None

result = pickle.loads(pickled)

assert result.latitude == 1
assert result.longitude == 2
assert result.altitude == 4
assert result.rotation == 8
assert result.roll == 16
assert result.offset.x == 32
assert result.offset.y == 64
assert result.offset.z == 128

repickled = pickle.dumps(result)

assert pickled == repickled

0 comments on commit 47569d2

Please sign in to comment.