Skip to content

Commit

Permalink
Merge pull request #305 from nyx-space/249-python-strftime-time-scale
Browse files Browse the repository at this point in the history
Add Python regression test for #249
  • Loading branch information
ChristopherRabotin authored Jun 9, 2024
2 parents cb55ba9 + d2bc5c0 commit 3b5156e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 16 deletions.
70 changes: 56 additions & 14 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
target: [x86_64, x86, aarch64, armv7, ppc64le]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down Expand Up @@ -113,31 +113,73 @@ jobs:
pip install pytest
pytest
macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-latest
target: x86_64
- runner: macos-14
target: aarch64
macos-13: # last available x86_64 macos runner
runs-on: macos-13
steps:
- uses: actions/checkout@v4
with:
lfs: true

- uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: "3.11"

- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
target: x86_64
args: --release --out dist --find-interpreter -F python
sccache: 'true'

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels-macos-13
path: dist

- name: pytest
shell: bash
env:
RUST_BACKTRACE: 1
run: |
set -e
pip install hifitime --find-links dist --force-reinstall --no-index
pip install pytest
pytest
macos-14: # first available aarch64 macos runner
runs-on: macos-14
steps:
- uses: actions/checkout@v4
with:
lfs: true

- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: aarch64
args: --release --out dist --find-interpreter -F python
sccache: 'true'

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
name: wheels-macos-14
path: dist

- name: pytest
shell: bash
env:
RUST_BACKTRACE: 1
run: |
set -e
pip install hifitime --find-links dist --force-reinstall --no-index
pip install pytest
pytest
sdist:
runs-on: ubuntu-latest
Expand All @@ -158,7 +200,7 @@ jobs:
name: Release
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
needs: [linux, windows, macos, sdist]
needs: [linux, windows, macos-13, macos-14, sdist]
steps:
- uses: actions/download-artifact@v3
with:
Expand Down
13 changes: 13 additions & 0 deletions tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2031,3 +2031,16 @@ fn regression_test_gh_261() {
}
}
}

#[test]
fn regression_test_gh_209() {
let t = Epoch::from_time_of_week(1983, 0, TimeScale::GPST);

println!("{t}");
// Should print

assert_eq!(format!("{t}"), format!("2018-01-07T00:00:00 GPST"));

let t = Epoch::from_time_of_week(1982, 604800000000000 - 19000000000, TimeScale::GPST);
println!("{t}");
}
10 changes: 8 additions & 2 deletions tests/python/test_epoch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hifitime import Duration, Epoch, EpochError, ParsingError, TimeSeries, Unit
from hifitime import Duration, Epoch, EpochError, ParsingError, TimeScale, TimeSeries, Unit
from datetime import datetime
import pickle

Expand Down Expand Up @@ -81,4 +81,10 @@ def test_exceptions():
except EpochError as e:
print(f"caught {e}")
else:
raise AssertionError("failed to catch epoch error")
raise AssertionError("failed to catch epoch error")

def test_regression_gh249():
e = Epoch.init_from_gregorian(year=2022, month=3, day=1, hour=1, minute=1, second=59, nanos=1, time_scale=TimeScale.GPST)
assert e.strftime("%Y %m %d %H %M %S %f %T") == "2022 03 01 01 01 59 000000001 GPST"
e = Epoch.init_from_gregorian(year=2022, month=3, day=1, hour=1, minute=1, second=59, nanos=1, time_scale=TimeScale.UTC)
assert e.strftime("%Y %m %d %H %M %S %f %T") == "2022 03 01 01 01 59 000000001 UTC"

0 comments on commit 3b5156e

Please sign in to comment.