Skip to content

Commit

Permalink
Merge pull request #150 from pllim/rc-testing
Browse files Browse the repository at this point in the history
TST: Add RC testing workflow and update exiting
  • Loading branch information
pllim committed Dec 8, 2022
2 parents 18aeeb5 + 0d6b8b2 commit 5580e6c
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 12 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:

# TODO: Uncomment when you ready to fix PEP 8 warnings.
Expand All @@ -24,7 +27,7 @@ jobs:
# with:
# fetch-depth: 0
# - name: Set up Python
# uses: actions/setup-python@v3
# uses: actions/setup-python@v4
# with:
# python-version: '3.x'
# - name: Lint with flake8
Expand All @@ -40,7 +43,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.x'
# Make sure that packaging will work
Expand All @@ -62,7 +65,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install and build
Expand All @@ -81,9 +84,9 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'
- name: Install and build
run: |
python -m pip install --upgrade pip wheel setuptools
Expand All @@ -101,7 +104,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install and build
Expand All @@ -119,7 +122,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install and build
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/predeps_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: rc-testing

on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
# TODO: Add more OS when we are sure this package can run on those.
#os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install and build
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install numpy astropy --pre
python -m pip install -e .[test]
- name: Run tests
run: pytest
62 changes: 62 additions & 0 deletions lib/stsci/tools/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Licensed under a 3-clause BSD style license - see PYFITS.rst

import os
import shutil
import stat
import tempfile
import time

from astropy.io import fits


# This was copied from astropy 5.0.x branch because the version in
# astropy 5.2.x is no longer compatible with tests in this package.
class FitsTestCase:
def setup_method(self):
self.data_dir = os.path.join(os.path.dirname(__file__), "data")
self.temp_dir = tempfile.mkdtemp(prefix="fits-test-")

# Restore global settings to defaults
# TODO: Replace this when there's a better way to in the config API to
# force config values to their defaults
fits.conf.enable_record_valued_keyword_cards = True
fits.conf.extension_name_case_sensitive = False
fits.conf.strip_header_whitespace = True
fits.conf.use_memmap = True

def teardown_method(self):
if hasattr(self, "temp_dir") and os.path.exists(self.temp_dir):
tries = 3
while tries:
try:
shutil.rmtree(self.temp_dir)
break
except OSError:
# Probably couldn't delete the file because for whatever
# reason a handle to it is still open/hasn't been
# garbage-collected
time.sleep(0.5)
tries -= 1

fits.conf.reset("enable_record_valued_keyword_cards")
fits.conf.reset("extension_name_case_sensitive")
fits.conf.reset("strip_header_whitespace")
fits.conf.reset("use_memmap")

def copy_file(self, filename):
"""Copies a backup of a test data file to the temp dir and sets its
mode to writeable.
"""

shutil.copy(self.data(filename), self.temp(filename))
os.chmod(self.temp(filename), stat.S_IREAD | stat.S_IWRITE)

def data(self, filename):
"""Returns the path to a test data file."""

return os.path.join(self.data_dir, filename)

def temp(self, filename):
"""Returns the full path to a file in the test temp dir."""

return os.path.join(self.temp_dir, filename)
5 changes: 3 additions & 2 deletions lib/stsci/tools/tests/test_isfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import tempfile

import pytest
from astropy.io.fits.tests import FitsTestCase

from stsci.tools import fileutil as F
from stsci.tools import stpyfits

from . import FitsTestCase


class TestIsFits(FitsTestCase):
def setup(self):
def setup_method(self):
self.data_dir = os.path.join(os.path.dirname(__file__), 'data')
self.temp_dir = tempfile.mkdtemp(prefix='isfits-test-')

Expand Down
2 changes: 1 addition & 1 deletion lib/stsci/tools/tests/test_minmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_missing_key_returns_none(mmd):


def test_getall(mmd):
return mmd.getall('t')
assert mmd.getall('t') == [1, 2, 10]


def test_getall_returns_expected_values(mmd):
Expand Down
5 changes: 3 additions & 2 deletions lib/stsci/tools/tests/test_stpyfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import numpy as np
import pytest
from astropy.io import fits
from astropy.io.fits.tests import FitsTestCase

from stsci.tools import stpyfits

from . import FitsTestCase


class TestStpyfitsFunctions(FitsTestCase):
def setup(self):
def setup_method(self):
self.data_dir = os.path.join(os.path.dirname(__file__), 'data')
self.temp_dir = tempfile.mkdtemp(prefix='stpyfits-test-')
self.writekwargs = {'overwrite': True}
Expand Down

0 comments on commit 5580e6c

Please sign in to comment.