Skip to content

Commit

Permalink
test: use importlib.resources.files instead of __file__
Browse files Browse the repository at this point in the history
This is more robust as __file__ is not guaranteed to be defined
  • Loading branch information
scivision committed Jan 9, 2025
1 parent 0ac46a6 commit ac5d259
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/georinex/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# need this blank file for importlib.resources.files
6 changes: 2 additions & 4 deletions src/georinex/tests/test_lzw.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
test for LZW .Z file
"""

from pathlib import Path
import importlib.resources as ir
import pytest

import georinex as gr

R = Path(__file__).parent / "data"


def test_obs2_lzw():
pytest.importorskip("ncompress")

fn = R / "ac660270.18o.Z"
fn = ir.files(f"{__package__}.data") / "ac660270.18o.Z"

obs = gr.load(fn)

Expand Down
29 changes: 15 additions & 14 deletions src/georinex/tests/test_nav2.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import importlib.resources as ir
import pytest
from pytest import approx
import xarray
from pathlib import Path
from datetime import datetime
import numpy as np
import georinex as gr

#
R = Path(__file__).parent / "data"


def test_time():
times = gr.gettime(R / "ab422100.18n")
fn = ir.files(f"{__package__}.data") / "ab422100.18n"
times = gr.gettime(fn)

assert times[0] == datetime(2018, 7, 29, 1, 59, 44)
assert times[-1] == datetime(2018, 7, 30)


def test_data():
nav = gr.load(R / "ab422100.18n")
fn = ir.files(f"{__package__}.data") / "ab422100.18n"
nav = gr.load(fn)

nav0 = nav.sel(time="2018-07-29T03:59:44").dropna(dim="sv", how="all")

Expand Down Expand Up @@ -62,7 +61,7 @@ def test_data():


def test_mangled():
fn = R / "14601736.18n"
fn = ir.files(f"{__package__}.data") / "14601736.18n"

nav = gr.load(fn)

Expand All @@ -72,7 +71,7 @@ def test_mangled():


def test_mangled2():
fn = R / "brdc2420.18n.gz"
fn = ir.files(f"{__package__}.data") / "brdc2420.18n.gz"

nav = gr.load(fn)

Expand All @@ -95,15 +94,17 @@ def test_mangled2():


def test_tlim_past_eof():
nav = gr.load(R / "p1462100.18g", tlim=("2018-07-29T23:45", "2018-07-30"))
nav = gr.load(
ir.files(f"{__package__}.data") / "p1462100.18g", tlim=("2018-07-29T23:45", "2018-07-30")
)

times = gr.to_datetime(nav.time)

assert times == datetime(2018, 7, 29, 23, 45)


def test_galileo():
nav = gr.load(R / "ceda2100.18e")
nav = gr.load(ir.files(f"{__package__}.data") / "ceda2100.18e")

E18 = nav.sel(sv="E18").dropna(dim="time", how="all")
assert gr.to_datetime(E18.time) == datetime(2018, 7, 29, 12, 40)
Expand Down Expand Up @@ -142,7 +143,7 @@ def test_galileo():


def test_gps():
nav = gr.load(R / "brdc2800.15n")
nav = gr.load(ir.files(f"{__package__}.data") / "brdc2800.15n")

times = gr.to_datetime(nav.time)
assert times[1] == datetime(2015, 10, 7, 1, 59, 28)
Expand Down Expand Up @@ -187,14 +188,14 @@ def test_gps():
def test_small():
pytest.importorskip("netCDF4")

truth = xarray.open_dataset(R / "r2all.nc", group="NAV")
nav = gr.load(R / "demo.10n")
truth = xarray.open_dataset(ir.files(f"{__package__}.data") / "r2all.nc", group="NAV")
nav = gr.load(ir.files(f"{__package__}.data") / "demo.10n")

assert nav.equals(truth)


def test_ionospheric_correction():
nav = gr.load(R / "14601736.18n")
nav = gr.load(ir.files(f"{__package__}.data") / "14601736.18n")
assert nav.attrs["ionospheric_corr_GPS"] == approx(
[
0.4657e-08,
Expand Down
1 change: 1 addition & 0 deletions src/georinex/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy
import sys
import pandas

try:
import netCDF4
except ImportError:
Expand Down

0 comments on commit ac5d259

Please sign in to comment.