Skip to content

Commit

Permalink
fleshed out testing section a bit, cleaned up a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Torborg committed Nov 18, 2012
1 parent 1302d47 commit e1be75a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
html_title = 'Python Packaging Tutorial'

# A shorter title for the navigation bar. Default is the same as html_title.
html_short_title = 'How To Package Your Python Code'
Expand Down
7 changes: 0 additions & 7 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,3 @@ We'll walk through the basic steps of building up a contrived package **funniest
.. note::

At this time, this documentation focuses on Python 2.x only, and may not be *as* applicable to packages targeted to Python 3.x.


Indices
=======

* :ref:`genindex`
* :ref:`search`
12 changes: 6 additions & 6 deletions minimal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ The main setup config file, ``setup.py``, should contain a single call to ``setu

Now we can install the package locally (for use on our system), with::

python setup.py install
$ python setup.py install

We can also install the package with a symlink, so that changes to the source files will be immediately available to other users of the package on our system::

python setup.py develop
$ python setup.py develop

Anywhere else in our system using the same Python, we can do this now::

Expand All @@ -75,7 +75,7 @@ The ``setup.py`` script is also our main entrypoint to register the package name

To "register" the package (this will reserve the name, upload package metadata, and create the pypi.python.org webpage)::

python setup.py register
$ python setup.py register

If you haven't published things on PyPI before, you'll need to create an account by following the steps provided at this point.

Expand All @@ -87,17 +87,17 @@ Although users can follow the URL link to find our git repository, we'll probabl

First create a source distribution with::

python setup.py sdist
$ python setup.py sdist

This will create ``dist/funniest-0.1.tar.gz`` inside our top-level directory. If you like, copy that file to another host and try unpacking it and install it, just to verify that it works for you.

That file can then be uploaded to PyPI with::

python setup.py upload
$ python setup.py upload

You can combine all of these steps, to update metadata and publish a new build in a single step::

python setup.py register sdist upload
$ python setup.py register sdist upload


Installing the Package
Expand Down
40 changes: 38 additions & 2 deletions testing.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
Let There Be Tests
------------------

.. todo::
The **funniest** package needs some tests. These should be placed in a submodule of ``funniest.`` so that they can be imported, but won't pollute the global namespace.::

Explain basics of configuring nose, requiring it, and using the setup.py integration.
funniest/
funniest/
__init__.py
tests/
__init__.py
test_joke.py
setup.py
...

The ``test_joke.py`` file is our first test file. Although it's overkill for now, we'll use a ``unittest.TestCase`` subclass to provide infrastructure for later development.::

from unittest import TestCase

import funniest

class TestJoke(TestCase):
def test_is_string(self):
s = funniest.joke()
self.assertTrue(isinstance(s, basestring))

The best way to get these tests going (particularly if you're not sure what to use) is `Nose <https://nose.readthedocs.org/en/latest/>`_. With those files added, it's just a matter of running this from the root of the repository::

$ nosetests

To integrate this with our ``setup.py``, and ensure that Nose is installed when we run the tests, we'll add a few lines to ``setup()``::

setup(
...
test_suite='nose.collector',
tests_require=['nose'],
)

Then, to run tests, we can simply do::

$ python setup.py test

Setuptools will take care of installing nose and running the test suite.

0 comments on commit e1be75a

Please sign in to comment.