Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tieqiong PR #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2019, Brookhaven National Laboratory
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# diffpy-cookie-cutter
A cookie-cutter for DiffPy packages.
# diffpy-cookiecutter
a cookiecutter for diffpy packages
12 changes: 12 additions & 0 deletions RELEASES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
===============
Release History
===============

v0.1.1 (2021-10-26)
...................
+ relax python version for pre-commit


v0.1.0 (2021-10-08)
...................
Initial Release
4 changes: 3 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"email": "",
"github_username": "",
"project_name": "Your Project Name",
"project_slug": "{{ cookiecutter.project_name|replace('.', '')|lower }}",
"project_short_name": "",
"package_dist_name": "{{ cookiecutter.project_name|replace(' ', '-')|lower }}",
"package_dir_name": "{{ cookiecutter.project_name|replace(' ', '_')|replace('-', '_')|lower }}",
"repo_name": "{{ cookiecutter.project_name|replace(' ', '-')|lower }}",
"project_short_description": "Python package for doing science.",
"project_short_description": "",
"minimum_supported_python_version": ["3.8", "3.9", "3.10"],
"_copy_without_render": [
"*.html",
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS = "-W" # This flag turns warnings into errors.
SPHINXBUILD = sphinx-build
SPHINXPROJ = PackagingScientificPython
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
36 changes: 36 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
set SPHINXPROJ=PackagingScientificPython

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%

:end
popd
Empty file.
155 changes: 155 additions & 0 deletions docs/source/advanced-testing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
=========================
Common Patterns for Tests
=========================

In this section you will learn some useful features of pytest that can make
your tests succinct and easy to maintain.

Parametrized Tests
------------------

Tests that apply the same general test logic to a collection of different
parameters can use parametrized tests. For example, this:

.. code-block:: python

import numpy as np
from ..refraction import snell


def test_perpendicular():
# For any indexes, a ray normal to the surface should not bend.
# We'll try a couple different combinations of indexes....

actual = snell(0, 2.00, 3.00)
expected = 0
assert actual == expected

actual = snell(0, 3.00, 2.00)
expected = 0
assert actual == expected

can be rewritten as:

.. code-block:: python

import numpy as np
import pytest
from ..refraction import snell


@pytest.mark.parametrize('n1, n2',
[(2.00, 3.00),
(3.00, 2.00),
])
def test_perpendicular(n1, n2):
# For any indexes, a ray normal to the surface should not bend.
# We'll try a couple different combinations of indexes....

actual = snell(0, n1, n2)
expected = 0
assert actual == expected

The string ``'n1, n2'`` specifies which parameters this decorator will fill in.
Pytest will run ``test_perpendicular`` twice, one for each entry in the
list ``[(2.00, 3.00), (3.00, 2.00)]``, passing in the respective values ``n1``
and ``n2`` as arguments.

From here we refer you to the
`pytest parametrize documentation <https://docs.pytest.org/en/latest/parametrize.html>`_.

Fixtures
--------

Tests that have different logic but share the same setup code can use pytest
fixtures. For example, this:

.. code-block:: python

import numpy as np


def test_height():
# Construct a 1-dimensional Gaussian peak.
x = np.linspace(-10, 10, num=21)
sigma = 3.0
peak = np.exp(-(x / sigma)**2 / 2) / (sigma * np.sqrt(2 * np.pi))
expected = 1 / (sigma * np.sqrt(2 * np.pi))
# Test that the peak height is correct.
actual = np.max(peak)
assert np.allclose(actual, expected)


def test_nonnegative():
# Construct a 1-dimensional Gaussian peak.
x = np.linspace(-10, 10, num=20)
sigma = 3.0
peak = np.exp(-(x / sigma)**2 / 2) / (sigma * np.sqrt(2 * np.pi))
# Test that there are no negative values.
assert np.all(peak >= 0)

can be written as:

.. code-block:: python

import pytest
import numpy as np


@pytest.fixture
def peak():
# Construct a 1-dimensional Gaussian peak.
x = np.linspace(-10, 10, num=21)
sigma = 3.0
peak = np.exp(-(x / sigma)**2 / 2) / (sigma * np.sqrt(2 * np.pi))
return peak


def test_height(peak):
expected = 1 / (sigma * np.sqrt(2 * np.pi))
# Test that the peak height is correct.
actual = np.max(peak)
assert np.allclose(actual, expected)


def test_nonnegative(peak):
# Test that there are no negative values.
assert np.all(peak >= 0)

To reuse a fixture in multiple files, add it to ``conftest.py`` located in the
``tests/`` directory. It will automatically be imported by pytest into each
test module.

From here we refer you to the
`pytest fixtures documentation <https://docs.pytest.org/en/latest/fixture.html>`_.

Skipping Tests
--------------

Sometimes it is useful to skip specific tests under certain conditions.
Examples:

.. code-block:: python

import pytest
import sys


@pytest.mark.skipif(sys.version_info < (3, 7),
reason="requires python3.7 or higher")
def test_something():
...


@pytest.mark.skipif(sys.platform == 'win32',
reason="does not run on windows")
def test_something_that_does_not_work_on_windows():
...


def test_something_that_needs_a_special_dependency():
some_library = pytest.importorskip("some_library")
...

From here we refer you to the
`pytest skipping documentation <https://docs.pytest.org/en/latest/skipping.html>`_.
63 changes: 63 additions & 0 deletions docs/source/ci.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
=============================
Continous Integration Testing
=============================

In this section you will:

* Understand the benefits Continuous Integration.
* Configure Travis-CI, a "continuous integration" service, to operate on your
GitHub repository.

What is CI for?
---------------

If "Continuous Integration" (CI) is new to you, we refer you to
`this excellent Software Carpentry tutorial <https://katyhuff.github.io/python-testing/08-ci/>`_
on the subject. To summarize, CI speeds development by checking out your code on
a fresh, clean server, installing your software, running the tests, and
reporting the results. This helps you ensure that your code will work on your
colleague's computer---that it doesn't accidentally depend on some local detail
of your machine. It also creates a clear, public record of whether the tests
passed or failed, so if things are accidentally broken (say, while you are on
vacation) you can trace when the breaking change occurred.

Travis-CI Configuration
-----------------------

The cookiecutter template has already generated a configuration file for
Travis-CI, which is one of several CI services that are free for public
open-source projects.

.. literalinclude:: example_travis.yml

You can customize this to your liking. For example, if you are migrating a
large amount of existing code that is not compliant with PEP8, you may want to
remove the line that does ``flake8`` style-checking.

Activate Travis-CI for Your GitHub Repository
---------------------------------------------

#. Go to https://travis-ci.org and sign in with your GitHub account.
#. You will be prompted to authorize Travis-CI to access your GitHub account.
Authorize it.
#. You will be redirected to https://travis-ci.org/profile, which shows a list
of your GitHub repositories. If necessary, click the "Sync Account" button
to refresh that list.
#. Find your new repository in the list. Click the on/off switch next to its
name activate Travis-CI on that repository.
#. Click the repository name, which will direct you to the list of *builds* at
``https://travis-ci.org/YOUR_GITHUB_USERNAME/YOUR_REPO_NAME/builds``. The
list will currently be empty. You'll see construction cones.
#. The next time you open a pull request or push a new commit to the master
branch, Travis-CI will kick off a new build, and that list will update.

.. note::

If this repository belongs to a GitHub *organization* (e.g.
http://github.com/NSLS-II) as opposed to a personal user account
(e.g. http://github.com/danielballan) you should follow Steps 3-5
above for the organization's profile at
``https://travis-ci.org/profile/YOUR_GITHUB_ORGANIZATION``. It does no
harm to *also* activate Travis-CI for your personal fork at
``https://travis-ci.org/profile``, but it's more important to activate it for
the upstream fork associated with the organization.
Loading