Skip to content

Commit

Permalink
Merge pull request #52 from IMMM-SFA/feature/ci
Browse files Browse the repository at this point in the history
add github workflow actions for running tests; fixes #50
  • Loading branch information
thurber authored Jul 13, 2021
2 parents a550a84 + e6bc54f commit 99c8459
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 18 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: linux

on: [push]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]

env:
OS: ${{ matrix.os }}
PYTHON: '3.7'

steps:

- uses: actions/checkout@v1

- name: Set up Python
uses: actions/setup-python@master
with:
python-version: 3.7

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Test and generate coverage report
run: |
pip install pytest
pip install pytest-cov
python -m pytest tests/ --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
fail_ci_if_error: true
34 changes: 34 additions & 0 deletions .github/workflows/build_osx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: osx

on: [pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest]

env:
OS: ${{ matrix.os }}
PYTHON: '3.7'

steps:

- uses: actions/checkout@v1

- name: Set up Python
uses: actions/setup-python@master
with:
python-version: 3.7

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Test
run: |
pip install pytest
python -m pytest tests/
34 changes: 34 additions & 0 deletions .github/workflows/build_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: windows

on: [pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [windows-latest]

env:
OS: ${{ matrix.os }}
PYTHON: '3.7'

steps:

- uses: actions/checkout@v1

- name: Set up Python
uses: actions/setup-python@master
with:
python-version: 3.7

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Test
run: |
pip install pytest
python -m pytest tests/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ diyepw/data/tmy_epw_files/*
*.egg-info

# Python cache files
venv*
__pycache__

# Files generated by unit testing
Expand Down
4 changes: 2 additions & 2 deletions diyepw/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if not os.path.exists(log_dir): # pragma: no cover
os.mkdir(log_dir)

_log_path = os.path.join(log_dir, str(datetime.now()).replace(' ', '_') +'.log')
_log_path = os.path.join(log_dir, str(datetime.now()).replace(' ', '_').replace(':', '_') +'.log')
_file_handler = logging.FileHandler(_log_path)
_file_handler.setFormatter(logging.Formatter("%(asctime)s [diyepw.%(levelname)s] %(message)s"))
_file_handler.setLevel(_LOG_LEVEL)
Expand All @@ -21,4 +21,4 @@

_logger = logging.Logger('diyepw')
_logger.addHandler(_stdout_handler)
_logger.addHandler(_file_handler)
_logger.addHandler(_file_handler)
2 changes: 1 addition & 1 deletion diyepw/get_noaa_isd_lite_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _get_noaa_isd_lite_file_catalog(year:int, *, catalog_dir=None, allow_downloa
for line in html.splitlines():
# Regex: Match hrefs pointing to files in the form #-#-#.gz, where the first # starts with a 7.
# Capture groups: The big capture group gets the file name, and the small one gets the WMO
for match in re.finditer(f'href="((7\d+)-.*\.gz)"', line):
for match in re.finditer(r'href="((7\d+)-.*\.gz)"', line):
file_name, wmo_index = match.groups()
catalog = catalog.append({'wmo_index': int(wmo_index), 'file_name': file_name}, ignore_index=True)

Expand Down
2 changes: 1 addition & 1 deletion diyepw/get_tmy_epw_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_tmy_epw_file(wmo_index:int, output_dir:str = None, allow_downloads:bool

# Move the EPW file from the temporary directory into which we extracted
# the ZIP file into the directory storing our EPWs
os.rename(os.path.join(tmp_dir, epw_file_name), epw_file_path)
shutil.move(os.path.join(tmp_dir, epw_file_name), epw_file_path)

# Delete the temporary files created in this call
os.unlink(tmp_file_path)
Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
xarray~=0.16.2
numpy~=1.19.2
numpy~=1.19.2
pvlib~=0.8.1
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ def readme():
author='Amanda Smith',
author_email='[email protected]',
packages=setuptools.find_packages(),
package_data={ 'diyepw': ['data/**/*', 'test/files/**/*'] },
package_data={'diyepw': ['data/**/*', 'test/files/**/*']},
license='BSD 2-Clause',
python_requires='~=3.7',
install_requires=[
'xarray~=0.16.2',
'numpy~=1.19.2'
'numpy~=1.19.2',
'pvlib~=0.8.1',
],
extras_require={
'dev': [
'pvlib~=0.8.1',
'recommonmark~=0.7.1',
'sphinx~=3.5.1',
'sphinx-rtd-theme~=0.5.1'
Expand Down
21 changes: 11 additions & 10 deletions tests/test_meteorology.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ def test_write_epw(self):
Confirm that an EPW file generated by the Meteorology.write_epw() method is a valid EPW file
:return:
"""
with tempfile.NamedTemporaryFile('w+') as tmp_file:
self._meteorology.write_epw(tmp_file.name)
with open(tmp_file.name, "r") as m:
try:
parsed_epw, col_names = pvlib.iotools.parse_epw(m)
except Exception as e:
raise Exception(f"Encountered an error trying to parse the produce of Meteorology.write_epw() as an EPW file: {e}")

# Make sure that parse_epw() actually succeeded in creating a DataFrame instance
self.assertIsInstance(parsed_epw, pd.DataFrame)
tmp_file = os.path.join(tempfile.gettempdir(), os.urandom(24).hex())
self._meteorology.write_epw(tmp_file)
with open(tmp_file, "r") as m:
try:
parsed_epw, col_names = pvlib.iotools.parse_epw(m)
except Exception as e:
raise Exception(f"Encountered an error trying to parse the produce of Meteorology.write_epw() as an EPW file: {e}")

# Make sure that parse_epw() actually succeeded in creating a DataFrame instance
self.assertIsInstance(parsed_epw, pd.DataFrame)
os.unlink(tmp_file)


def test_property_setters_and_getters__good_values(self):
Expand Down

0 comments on commit 99c8459

Please sign in to comment.