Repository: astrochun/chun_codes

Issue:
Use GitHub Actions for CI
Because of the change in pricing model by Travis CI for open-source software, it becomes cost prohibitive to use Travis CI moving forward.

Thus, we should migrate to using GitHub actions for CI and build tests.

This doc page and the GitHub Action YAML is a starting point:
https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-python

We can start with this but not include python 2.7.
Will need to include other dependencies such as chun_codes and pytest-cov.

This might be useful for testing purposes before committing the github actions:
https://github.com/nektos/act

We should require a skip if "ci skip" or "skip ci"
﻿
Action items:
- [x] Create a `python-package` GitHub Actions workflow
- [x] Add option to prevent skip CI with "ci skip" or "skip ci. See [this](https://github.com/ualibraries/ReQUIAM/runs/1487466435?check_suite_focus=true)
- [x] Disable certain files
- [x] GitHub Actions badge in README.md
- [x] Include tests for `cardelli` module

<!--Branch info-->
**Implemented in**: `feature/gh_actions_build_test`

Discussion:

Patch:
diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..38985f9
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,1 @@
+[run]
diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml
new file mode 100644
index 0000000..c726337
--- /dev/null
+++ b/.github/workflows/python-package.yml
@@ -0,0 +1,42 @@
+# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
+# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
+
+name: Python package
+
+on:
+  push:
+    paths-ignore:
+      - '**.md'
+      - 'LICENSE'
+  pull_request:
+    paths-ignore:
+      - '**.md'
+      - 'LICENSE'
+
+jobs:
+  build:
+
+    runs-on: ubuntu-latest
+    # See: https://github.com/marketplace/actions/skip-based-on-commit-message
+    if: "!contains(github.event.head_commit.message, 'ci skip') || !contains(github.event.head_commit.message, 'skip ci')"
+    strategy:
+      matrix:
+        python-version: ['3.7', '3.8']
+
+    steps:
+    - name: Checkout chun_codes
+      uses: actions/checkout@v2
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+    - name: Install dependencies
+      run: |
+        python -m pip install --upgrade pip
+        python -m pip install pytest pytest-cov
+    - name: Install chun_codes
+      run: |
+        python setup.py install
+    - name: Test with pytest
+      run: |
+        pytest --cov-report term-missing --cov-config=.coveragerc --cov=chun_codes tests
diff --git a/README.md b/README.md
index 10cb2fa..c153fdc 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 # chun_codes
 Set of Python 2.7 and 3.xx codes used in astrochun's codes
 
-[![Build Status](https://travis-ci.com/astrochun/chun_codes.svg?branch=master)](https://travis-ci.com/astrochun/chun_codes)
+[![GitHub build](https://github.com/astrochun/chun_codes/workflows/Python%20package/badge.svg?branch=master)](https://github.com/astrochun/chun_codes/actions?query=workflow%3A%22Python+package%22)
 ![GitHub top language](https://img.shields.io/github/languages/top/astrochun/chun_codes)
 ![GitHub release (latest by date)](https://img.shields.io/github/v/release/astrochun/chun_codes)
 [![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)
diff --git a/chun_codes/__init__.py b/chun_codes/__init__.py
index f059530..56ba287 100644
--- a/chun_codes/__init__.py
+++ b/chun_codes/__init__.py
@@ -15,7 +15,7 @@ py_vers = sys.version_info.major
 if py_vers == 2:
     import pdfmerge
 
-__version__ = "0.6.0"
+__version__ = "0.7.0"
 
 
 def systime():
diff --git a/chun_codes/cardelli.py b/chun_codes/cardelli.py
index c13503a..18a5509 100644
--- a/chun_codes/cardelli.py
+++ b/chun_codes/cardelli.py
@@ -2,6 +2,7 @@ import numpy as np
 
 from astropy import units as u
 
+
 def uv_func_mw(x, R):
   
     Fa = -0.04473*(x-5.9)**2 - 0.009779*(x-5.9)**3
@@ -16,21 +17,21 @@ def uv_func_mw(x, R):
     b = -3.090 + 1.825 * x + 1.206/((x-4.62)**2+0.263) + Fb
 
     return a + b/R
-#enddef
+
 
 def fuv_func_mw(x, R):
 
     a = -1.073 - 0.628 * (x-8) + 0.137*(x-8)**2 - 0.070*(x-8)**3
     b = 13.670 + 4.257*(x-8) - 0.420*(x-8)**2 + 0.374*(x-8)**3
     return a + b/R
-#enddef
+
 
 def ir_func_mw(x, R):
 
     a = 0.574 * x**1.61
     b = -0.527 * x**1.61
     return a + b/R
-#enddef
+
 
 def opt_func_mw(x, R):
     y = x - 1.82
@@ -40,10 +41,10 @@ def opt_func_mw(x, R):
     b = 1.41338 * y + 2.28305 * y**2 + 1.07233 * y**3 - 5.38434 * y**4 - \
         0.62251 * y**5 + 5.30260 * y**6 - 2.09002 * y**7
     return a + b/R
-#enddef
 
-def cardelli(lambda0, R=3.1): #, extrapolate=False):
-    '''
+
+def cardelli(lambda0, R=3.1):
+    """
     NAME:
        cardelli
 
@@ -83,36 +84,41 @@ def cardelli(lambda0, R=3.1): #, extrapolate=False):
 
     REVISON HISTORY:
        Created by Chun Ly, 28 June 2016
-    '''
+    """
     # Specify units of lambda0 so that code can convert
     # Default is R=3.1
 
     t_lam = lambda0.to(u.nm).value
 
-    ## Handles individual values, x
-    if type(t_lam) == 'list':
+    # Handles individual values, x
+    if isinstance(t_lam, float):
+        t_lam = np.array([t_lam])
+    if isinstance(t_lam, list):
         t_lam = np.array(t_lam)
-    else:
-        if isinstance(t_lam, (np.ndarray, np.generic)) == False:
-            t_lam = np.array([t_lam])
+    if not isinstance(t_lam, (np.ndarray, np.generic)):
+        t_lam = np.array([t_lam])
 
-    x = 1.0/(t_lam/1000.0) #in micron^-1
+    x = 1.0/(t_lam/1000.0)  # in micron^-1
 
     k = np.zeros(np.size(t_lam), dtype=np.float64)
 
     mark = np.where((x <= 1.10) & (x >= 0.30))[0]
-    if len(mark) > 0: k[mark] = ir_func_mw(x[mark], R)
+    if len(mark) > 0:
+        k[mark] = ir_func_mw(x[mark], R)
 
     mark = np.where((x <= 3.30) & (x > 1.10))[0]
-    if len(mark) > 0: k[mark] = opt_func_mw(x[mark], R)
+    if len(mark) > 0:
+        k[mark] = opt_func_mw(x[mark], R)
 
     mark = np.where((x <= 8.00) & (x > 3.3))[0]
-    if len(mark) > 0: k[mark] = uv_func_mw(x[mark], R)
+    if len(mark) > 0:
+        k[mark] = uv_func_mw(x[mark], R)
 
     mark = np.where((x <= 10.00) & (x > 8.0))[0]
-    if len(mark) > 0: k[mark] = fuv_func_mw(x[mark], R)
+    if len(mark) > 0:
+        k[mark] = fuv_func_mw(x[mark], R)
 
     k = k * R
-    if np.size(x) == 1: k = k[0]
+    if np.size(x) == 1:
+        k = k[0]
     return k 
-#enddef
diff --git a/setup.py b/setup.py
index ffed3ee..4ef46ae 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
 
 setup(
     name='chun_codes',
-    version='0.6.0',
+    version='0.7.0',
     packages=['chun_codes'],
     url='https://github.com/astrochun/chun_codes',
     license='MIT License',


Test patch:
diff --git a/tests/test_cardelli.py b/tests/test_cardelli.py
new file mode 100644
index 0000000..89f4cb7
--- /dev/null
+++ b/tests/test_cardelli.py
@@ -0,0 +1,20 @@
+import astropy.units as u
+import numpy as np
+
+from chun_codes import cardelli
+
+
+def test_cardelli():
+
+    line_Ha = 6562.8
+    lambda0 = line_Ha * u.Angstrom
+    result1 = cardelli.cardelli(lambda0)
+    assert isinstance(result1, float)
+
+    result2 = cardelli.cardelli([line_Ha] * u.Angstrom)
+    assert isinstance(result2, float)
+
+    lambda0 = [500, 900, 1100, 1500, 2500, 5500, 15000] * u.Angstrom
+    result3 = cardelli.cardelli(lambda0)
+    assert isinstance(result3, (np.ndarray, np.generic))
+    assert len(result3) == len(lambda0)