diff --git a/.github/workflows/ci_run_tests.yml b/.github/workflows/ci_run_tests.yml new file mode 100644 index 0000000..f5468dd --- /dev/null +++ b/.github/workflows/ci_run_tests.yml @@ -0,0 +1,50 @@ +name: test + +on: + push: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: +# name: test (Python ${{ matrix.python-version }}, ${{ matrix.os }}) + name: test (env file ${{ matrix.environment-files }}, ${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ "ubuntu-latest"] +# python-version: [ "3.10" , "3.11" ] + environment-files: ["environment-3.9.yml", "environment-3.9-pinned.yml", "environment-3.10.yml", "environment-3.11.yml", "environment-3.10-pinned.yml", "environment-3.10-astropy.yml"] + fail-fast: false + env: + PYTHONUNBUFFERED: 1 + defaults: + run: + shell: micromamba-shell {0} + steps: + - uses: actions/checkout@v4 + + - uses: mamba-org/setup-micromamba@v1 + with: +# environment-name: pystrometry-${{ runner.os }}-py${{ matrix.python-version }} + environment-name: pystrometry-${{ runner.os }}-${{ matrix.environment-files }} + environment-file: ${{ matrix.environment-files }} +# create-args: >- +# python=${{ matrix.python-version }} + init-shell: none + generate-run-shell: true + +# - run: pip install -e .[test] pytest-xdist + + - run: pip list + - run: pip install pytest + + - run: micromamba env export + +# - run: python -c "import pystrometry; print('Version ' + pystrometry.__version__); print('Path ' + pystrometry.__path__[0])" + + - run: pytest --durations=0 -vs -o log_cli=true --log-level=INFO pystrometry/tests + - run: pytest --durations=0 -vs -o log_cli=true --log-level=INFO pystrometry/utils/tests \ No newline at end of file diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml deleted file mode 100644 index 5d0df30..0000000 --- a/.github/workflows/python-package-conda.yml +++ /dev/null @@ -1,94 +0,0 @@ -name: Python Package using Conda - -on: [push] - -jobs: - build-linux-python-3p10: - runs-on: ubuntu-latest - strategy: - max-parallel: 5 - - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: '3.10' - - name: Add conda to system path - run: | - echo $CONDA/bin >> $GITHUB_PATH - - name: Install dependencies - run: | - conda env update --file environment-3.10.yml --name base - - name: Lint with flake8 - run: | - conda install flake8 - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - continue-on-error: true - - name: Test with pytest - run: | - conda config --set solver classic - conda install pytest - pytest pystrometry/tests - pytest pystrometry/utils/tests - - build-linux-python-3p10-pinned: - runs-on: ubuntu-latest - strategy: - max-parallel: 5 - - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: '3.10' - - name: Add conda to system path - run: | - echo $CONDA/bin >> $GITHUB_PATH - - name: Install dependencies - run: | - conda env update --file environment-3.10-pinned.yml --name base - - name: Lint with flake8 - run: | - conda install flake8 - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - continue-on-error: true - - name: Test with pytest - run: | - conda config --set solver classic - conda install pytest - pytest pystrometry/tests - pytest pystrometry/utils/tests - - build-linux-python-3p9: - runs-on: ubuntu-latest - strategy: - max-parallel: 5 - - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.9 - uses: actions/setup-python@v3 - with: - python-version: '3.9' - - name: Add conda to system path - run: | - echo $CONDA/bin >> $GITHUB_PATH - - name: Install dependencies - run: | - conda env update --file environment-3.9.yml --name base - - name: Lint with flake8 - run: | - conda install flake8 - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - continue-on-error: true - - name: Test with pytest - run: | - conda install pytest - pytest pystrometry/tests - pytest pystrometry/utils/tests - diff --git a/environment-3.10-astropy.yml b/environment-3.10-astropy.yml new file mode 100644 index 0000000..93f6c52 --- /dev/null +++ b/environment-3.10-astropy.yml @@ -0,0 +1,18 @@ +name: pystrometry-environment-3p10-astropy +channels: + - conda-forge +dependencies: + - python == 3.10 + - numpy + - pip + - kepmodel + - pandas + - pyarrow + - matplotlib + - astroquery + - astropy == 6.0 + - sympy + - scipy + - uncertainties + - pip: + - linearfit diff --git a/pystrometry/pystrometry.py b/pystrometry/pystrometry.py index aedd017..8e7a628 100644 --- a/pystrometry/pystrometry.py +++ b/pystrometry/pystrometry.py @@ -4857,6 +4857,11 @@ def get_ephemeris(center='g@399', target='0', start_time=None, stop_time=None, s with open(out_file, 'wb') as ephemeris: ephemeris.write(content) + logging.info(f"Reading {horizons_file_seed} from {ephemeris_dir}") + files = os.listdir(ephemeris_dir) + for file in files: + logging.info(f"File in ephemeris_dir: {file}") + xyzdata = read_ephemeris(horizons_file_seed, overwrite=overwrite, ephemeris_path=ephemeris_dir) return xyzdata diff --git a/pystrometry/tests/test_get_ephemeris.py b/pystrometry/tests/test_get_ephemeris.py new file mode 100644 index 0000000..5ea6176 --- /dev/null +++ b/pystrometry/tests/test_get_ephemeris.py @@ -0,0 +1,33 @@ +import logging +import os + +from astropy.table import Table +from astropy.time import Time + +from ..pystrometry import get_ephemeris +from ..pystrometry import ephemeris_dir + +logging.basicConfig(level=logging.INFO) + +def test_get_ephemeris_valid_input(): + # Define valid test inputs + center = 'g@399' + target = '0' + start_time = Time('2023-01-01T00:00:00') + stop_time = Time('2024-01-10T00:00:00') + step_size = '1d' + + logging.info(f"\nephemeris_dir={ephemeris_dir}\n") + horizons_file_seed = '{}_{}_{}_{}_{}'.format(center, target, start_time, stop_time, step_size) + out_file = os.path.join(ephemeris_dir, horizons_file_seed + '.txt') + + # Call the function + result = get_ephemeris(center=center, target=target, start_time=start_time, stop_time=stop_time, step_size=step_size) + assert os.path.isfile(out_file), f"Expected output file {out_file} does not exist." + + # Validate the result + assert isinstance(result, Table), "Result should be an Astropy Table" + assert len(result) > 0, "Result table should not be empty" + assert 'X' in result.colnames, "Result table should contain 'X' column" + assert 'Y' in result.colnames, "Result table should contain 'Y' column" + assert 'Z' in result.colnames, "Result table should contain 'Z' column"