Skip to content

Commit

Permalink
Merge pull request pytroll#4 from adybbroe/add-unittests
Browse files Browse the repository at this point in the history
Added first very small unittest
  • Loading branch information
adybbroe committed May 7, 2021
2 parents af09f4d + 9851416 commit a0e7d6a
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 15 deletions.
14 changes: 14 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[run]
branch = True
source = pytroll-active-fire-runner
relative_files = True

[report]
exclude_lines =
if self.debug:
pragma: no cover
raise NotImplementedError
if __name__ == .__main__.:
ignore_errors = True
omit =
tests/*
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#### Code Sample, a minimal, complete, and verifiable piece of code

```python
# Your code here

```
#### Problem description

[this should also explain **why** the current behaviour is a problem and why the
expected output is a better solution.]

#### Expected Output

#### Actual Result, Traceback if applicable

#### Versions of Python, package at hand and relevant dependencies


Thank you for reporting an issue !
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Describe what your PR does, and why -->

- [ ] Closes #xxxx <!-- remove if there is no corresponding issue, which should only be the case for minor changes -->
- [ ] Tests added <!-- for all bug fixes or enhancements -->
- [ ] Tests passed: Passes ``pytest pyspectral`` <!-- for all non-documentation changes) -->
- [ ] Passes ``flake8`` <!-- remove if you did not edit any Python files -->
- [ ] Fully documented <!-- remove if this change should not be visible to users, e.g., if it is an internal clean-up, or if this is part of a larger project that will be documented later -->
81 changes: 81 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest", "macos-latest"]
python-version: ["3.8", "3.9"]
experimental: [false]
include:
- python-version: "3.9"
os: "ubuntu-latest"
experimental: true

env:
PYTHON_VERSION: ${{ matrix.python-version }}
OS: ${{ matrix.os }}
UNSTABLE: ${{ matrix.experimental }}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Setup Conda Environment
uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge,defaults
environment-file: continuous_integration/environment.yaml
activate-environment: test-environment

- name: Install unstable dependencies
if: matrix.experimental == true
shell: bash -l {0}
run: |
python -m pip install \
--no-deps --upgrade \
git+https://github.com/pytroll/posttroll \
git+https://github.com/pytroll/trollsift;
- name: Install pytroll-active-fire-runner
shell: bash -l {0}
run: |
pip install --no-deps -e .
- name: Run unit tests
shell: bash -l {0}
run: |
pytest --cov=viirs_active_fires viirs_active_fires/tests --cov-report=xml --cov-report=
- name: Upload unittest coverage to Codecov
uses: codecov/codecov-action@v1
with:
flags: unittests
file: ./coverage.xml
env_vars: OS,PYTHON_VERSION,UNSTABLE
fail_ci_if_error: false

- name: Coveralls Parallel
uses: AndreMiras/coveralls-python-action@develop
with:
flag-name: run-${{ matrix.test_number }}
parallel: true
if: runner.os == 'Linux'

coveralls:
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
25 changes: 25 additions & 0 deletions .github/workflows/deploy-sdist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Deploy sdist

on:
release:
types:
- published

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Create sdist
shell: bash -l {0}
run: python setup.py sdist

- name: Publish package to PyPI
if: github.event.action == 'published'
uses: pypa/gh-action-pypi-publish@v1.4.1
with:
user: __token__
password: ${{ secrets.pypi_password }}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# pytroll-active-fire-runner
pytroll-active-fire-runner
==========================

[![Build status](https://github.com/pytroll/pytroll-active-fire-runner/workflows/CI/badge.svg?branch=main)](https://github.com/pytroll/pytroll-active-fire-runner/workflows/CI/badge.svg?branch=main)
[![Coverage Status](https://coveralls.io/repos/github/pytroll/pytroll-active-fire-runner/badge.svg)](https://coveralls.io/github/pytroll/pytroll-active-fire-runner)


Using 3rd party software like CSPP to generate active fire products
7 changes: 5 additions & 2 deletions bin/viirs_af_runner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2019, 2020 Pytroll
# Copyright (c) 2019, 2020, 2021 Pytroll

# Author(s):

Expand Down Expand Up @@ -36,9 +36,12 @@
import six
import time

from viirs_active_fires.utils import (deliver_output_files, get_local_ips, cleanup_cspp_workdir,
from viirs_active_fires.utils import (deliver_output_files, cleanup_cspp_workdir,
get_edr_times, get_active_fire_result_files)

# from posttroll.adress_receiver import get_local_ips
# NOT used at the moment...

if six.PY2:
from urlparse import urlparse
from urlparse import urlunsplit
Expand Down
20 changes: 20 additions & 0 deletions continuous_integration/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test-environment
channels:
- conda-forge
dependencies:
- distributed
- toolz
- sphinx
- pyyaml
- pyproj
- coveralls
- coverage
- codecov
- behave
- mock
- pytest
- pytest-cov
- pip
- pip:
- trollsift
- posttroll
45 changes: 45 additions & 0 deletions viirs_active_fires/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2021 Adam.Dybbroe

# Author(s):

# Adam.Dybbroe <a000680@c21856.ad.smhi.se>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Unit testing the utility functions.
"""

import os.path
import pytest
from datetime import datetime
from unittest.mock import patch

from viirs_active_fires.utils import get_edr_times

TESTFILENAME = "AFIMG_npp_d20210413_t0916186_e0917428_b49018_c20210413092919781783_cspp_dev.txt"


@patch('os.path.basename')
def test_get_edr_times(basename):
"""Test getting the start and end times from the edr filename."""

basename.return_value = TESTFILENAME
timetup = get_edr_times('myfilename')

expected = (datetime(2021, 4, 13, 9, 16, 18), datetime(2021, 4, 13, 9, 17, 42))
assert timetup[0] == expected[0]
assert timetup[1] == expected[1]
14 changes: 2 additions & 12 deletions viirs_active_fires/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2019, 2020 Pytroll
# Copyright (c) 2019, 2020, 2021 Pytroll

# Author(s):

Expand Down Expand Up @@ -87,17 +87,6 @@ def deliver_output_files(affiles, base_dir, subdir=None):
return retvl


def get_local_ips():
inet_addrs = [netifaces.ifaddresses(iface).get(netifaces.AF_INET)
for iface in netifaces.interfaces()]
ips = []
for addr in inet_addrs:
if addr is not None:
for add in addr:
ips.append(add['addr'])
return ips


def cleanup_cspp_workdir(workdir):
"""Clean up the CSPP working dir after processing"""

Expand All @@ -115,6 +104,7 @@ def get_edr_times(filename):
"""
bname = os.path.basename(filename)
sll = bname.split('_')

start_time = datetime.strptime(sll[2] + sll[3][:-1],
"d%Y%m%dt%H%M%S")
end_time = datetime.strptime(sll[2] + sll[4][:-1],
Expand Down

0 comments on commit a0e7d6a

Please sign in to comment.