Skip to content

Commit

Permalink
Merge pull request #38 from pysat/flake8
Browse files Browse the repository at this point in the history
TST: Add pytest-flake8 to travis tests
  • Loading branch information
aburrell authored Apr 21, 2020
2 parents 043505e + cad3bcc commit 43f5b17
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 98 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ addons:

before_install:
- pip install pytest-cov
- pip install pytest-flake8
- pip install coveralls
- pip install future
- pip install numpy
Expand Down Expand Up @@ -41,7 +42,7 @@ install:
- python setup.py install

script:
- pytest -vs --cov=pysatModels/
- pytest -vs --cov=pysatModels/ --flake8

after_success:
- coveralls
62 changes: 36 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ Contributing
============

Bug reports, feature suggestions and other contributions are greatly
appreciated! pysatModels is a community-driven project and welcomes both feedback and contributions.
appreciated! pysatModels is a community-driven project and welcomes both
feedback and contributions.

Short version
=============

* Submit bug reports and feature requests at `GitHub <https://github.com/pysat/pysatModels/issues>`_
* Submit bug reports and feature requests at
[GitHub Issues](https://github.com/pysat/pysatModels/issues)
* Make pull requests to the ``develop`` branch

Bug reports
===========

When `reporting a bug <https://github.com/pysat/pysatModels/issues>`_ please
When [reporting a bug](https://github.com/pysat/pysatModels/issues) please
include:

* Your operating system name and version
Expand All @@ -24,7 +26,7 @@ Feature requests and feedback
=============================

The best way to send feedback is to file an issue at
`GitHub <https://github.com/pysat/pysatModels/issues>`_.
[GitHub Issues](https://github.com/pysat/pysatModels/issues).

If you are proposing a feature:

Expand All @@ -38,40 +40,48 @@ Development

To set up `pysatModels` for local development:

1. `Fork pysat on GitHub <https://github.com/pysat/pysatModels/fork>`_.
1. Fork pysat on [GitHub](https://github.com/pysat/pysatModels/fork).
2. Clone your fork locally::


git clone [email protected]:your_name_here/pysatModels.git
git clone [email protected]:your_name_here/pysatModels.git

3. Create a branch for local development::


git checkout -b name-of-your-bugfix-or-feature
git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally. Tests for new instruments are
performed automatically. Tests for custom functions should be added to the
appropriately named file in ``pysatModels/tests``. For example, the averaging routines in avg.py are tested in ``pysatModels/tests/test_avg.py``. If no
test file exists, then you should create one. This testing uses pytest, which
will run tests on any python file in the test directory that starts with
``test_``.
appropriately named file in ``pysatModels/tests``. For example, the
averaging routines in avg.py are tested in
``pysatModels/tests/test_avg.py``. If no test file exists, then you should
create one. This testing uses pytest, which will run tests on any python
file in the test directory that starts with ``test_``.

4. When you're done making changes, run all the checks to ensure that nothing
is broken on your local system::
4. When you're done making changes, run all the checks from the
``pysatModels/tests`` directory to ensure that nothing is broken on your
local system. You may need to install
[pytest](https://docs.pytest.org/en/latest/) and
[pytest-flake8](https://pypi.org/project/pytest-flake8/) first. ::


pytest -vs
python -m pytest -vs --flake8

5. Update/add documentation (in ``docs``), if relevant
5. Update or add documentation (in ``docs``), if relevant. If you have added
a new routine, you will need to add an example in the ``docs/examples``
folder.

5. Commit your changes and push your branch to GitHub::
6. Commit your changes and push your branch to GitHub. Our commit statements
follow the basic rules in the
[Numpy/SciPy workflow](https://docs.scipy.org/doc/numpy-1.15.1/dev/gitwash/development_workflow.html)::


git add .
git commit -m "Brief description of your changes"
git push origin name-of-your-bugfix-or-feature
git add .
git commit -m "TYPE: Brief description of your changes"
git push origin name-of-your-bugfix-or-feature

6. Submit a pull request through the GitHub website. Pull requests should be
7. Submit a pull request through the GitHub website. Pull requests should be
made to the ``develop`` branch.

Pull Request Guidelines
Expand All @@ -85,10 +95,10 @@ For merging, you should:
1. Include an example for use
2. Add a note to ``CHANGELOG.md`` about the changes
3. Ensure that all checks passed (current checks include Scrutinizer, Travis-CI,
and Coveralls) [1]_
and Coveralls).

.. [1] If you don't have all the necessary Python versions available locally or
have trouble building all the testing environments, you can rely on
Travis to run the tests for each change you add in the pull request.
Because testing here will delay tests by other developers, please ensure
that the code passes all tests on your local system first.
If you don't have all the necessary Python versions available locally or
have trouble building all the testing environments, you can rely on
Travis to run the tests for each change you add in the pull request.
Because testing here will delay tests by other developers, please ensure
that the code passes all tests on your local system first.
7 changes: 4 additions & 3 deletions pysatModels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# -----------------------------------------------------------------------------
"""
pysatModels
===============
===========
Model utilities designed to facilitate studies that integrate observational
and modelled data sets.
Expand All @@ -18,8 +18,9 @@
import logging
import os

from pysatModels import (utils)
from pysatModels import (models)
# Import key modules and skip F401 testing in flake8
from pysatModels import (utils) # noqa: F401
from pysatModels import (models) # noqa: F401

# set the version
here = os.path.abspath(os.path.dirname(__file__))
Expand Down
3 changes: 2 additions & 1 deletion pysatModels/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from pysatModels.models import ucar_tiegcm
# Import key modules and skip F401 testing in flake8
from pysatModels.models import ucar_tiegcm # noqa: F401
3 changes: 2 additions & 1 deletion pysatModels/tests/test_utils_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def test_bad_arg_input(self, bad_index, bad_input, err_msg):
"interpn only understands the methods"),
("model_label", 1, "Unknown format code "),
("time_method", "fun", "unknown time method"),
("pair_method", "fun", "unknown pairing method")])
("pair_method", "fun",
"unknown pairing method")])
def test_bad_kwarg_input(self, bad_key, bad_val, err_msg):
""" Test for expected failure with bad kwarg input """
kwargs = {bad_key: bad_val}
Expand Down
13 changes: 8 additions & 5 deletions pysatModels/tests/test_utils_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import pysat

import pysatModels as ps_mod
import pysatModels.utils.match as match


Expand Down Expand Up @@ -77,12 +76,16 @@ def teardown(self):
del self.input_args, self.required_kwargs, self.inst, self.model

@pytest.mark.parametrize("del_key,err_msg",
[("inst_lon_name", "Need longitude name for inst"),
("mod_lon_name", "Need longitude name for model"),
("inst_name", "Must provide instrument location"),
[("inst_lon_name",
"Need longitude name for inst"),
("mod_lon_name",
"Need longitude name for model"),
("inst_name",
"Must provide instrument location"),
("mod_name", "Must provide the same number"),
("mod_units", "Must provide units for each "),
("mod_datetime_name", "Need datetime coordinate"),
("mod_datetime_name",
"Need datetime coordinate"),
("mod_time_name", "Need time coordinate"),
("inst_clean_rout", "Need routine to clean")])
def test_input_failure(self, del_key, err_msg):
Expand Down
11 changes: 6 additions & 5 deletions pysatModels/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
# -----------------------------------------------------------------------------
"""
pysatModels.utils
=====================
=================
Utilities designed to extract, match, and compare modelled and observed data
"""

from __future__ import absolute_import, unicode_literals
from __future__ import absolute_import, unicode_literals

from pysatModels.utils import extract
from pysatModels.utils import match
from pysatModels.utils import compare
# Import key modules and skip F401 testing in flake8
from pysatModels.utils import extract # noqa: F401
from pysatModels.utils import match # noqa: F401
from pysatModels.utils import compare # noqa: F401
12 changes: 6 additions & 6 deletions pysatModels/utils/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def compare_model_and_inst(pairs=None, inst_name=[], mod_name=[],
raise ValueError('must provide Dataset of paired observations')

if len(inst_name) != len(mod_name):
raise ValueError('must provide equal number of instrument and model ' +
'data names for comparison')
raise ValueError(''.join(['must provide equal number of instrument ',
'and model data names for comparison']))

if not np.all([iname in pairs.data_vars.keys() for iname in inst_name]):
raise ValueError('unknown instrument data value supplied')
Expand All @@ -130,9 +130,9 @@ def compare_model_and_inst(pairs=None, inst_name=[], mod_name=[],
known_methods.extend(list(grouped_methods.keys()))
unknown_methods = [mm for mm in methods
if mm not in list(method_rout.keys())]
raise ValueError('unknown statistical method(s) requested:\n' +
'{:}\nuse only:\n{:}'.format(unknown_methods,
known_methods))
raise ValueError(''.join(['unknown statistical method(s) requested:\n',
'{:}\nuse only:\n'.format(unknown_methods),
'{:}'.format(unknown_methods)]))

# Initialize the output
stat_dict = {iname: dict() for iname in inst_name}
Expand Down Expand Up @@ -170,6 +170,6 @@ def compare_model_and_inst(pairs=None, inst_name=[], mod_name=[],
# instead of stopping processing. Only valid statistics will
# be included in output
ps_mod.logger.info("{:s} can't use {:s}: {:}".format(iname,
mm, err))
mm, err))

return stat_dict, data_units
Loading

0 comments on commit 43f5b17

Please sign in to comment.