Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
test: import cleanup & nosetests intro
Browse files Browse the repository at this point in the history
While investigating how to deliver a clear user/developer interface for MONK's
unittest suite, I found that `nosetests` is a rather powerful tool for testing.
As far as I understand it is a framework/tooling around Python's unittest
library adding more features.

Those features include:
 - automatic test discovery, no more need for test suites (but still possible)
 - simpler test methods without TestCase overhead and without removing any
   feature
 - decorators for Exception testing -> simpler code
 - plugins for coverage
 - plugins for various xml output

That's why nosetests seems to be the standard tool for unit testing in the
Python community.

Making the decision to use nosetests and the need to change the unittests to
comply with the new virtualenv-install-import policy makes a rewrite of the
existing unit tests rather attractive. This commit starts that approach,
deleting all the old school unit tests (which can be retrieved later on if
necessary anyway).

The first test will be about serial_conn, because that is the next development
focus for MONK. It imports monk_tf and creates a SerialConn object in a very
code-effective nosetest.

Then setup.cfg and setup.py were adapted. Now it is possible to simply call the
following commands and let setuptools and nosetests do the rest:

    $ pip install -r test-env.txt
    $ python setup.py nosetests

If there are errors running the installations you might miss the required
packages:

    #Ubuntu
    $ sudo apt-get install python-dev libssh2-1-dev
    # or Fedora
    $ yum install python-devel libssh2-devel
    # Sorry, no idea on Suse and the others

Here's the example for you to follow:

    # checkout a fresh MONK
    $ mkdir fresh
    $ cd fresh
    $ git clone git@github.com:DFE/MONK
    $ cd MONK
    # checkout this branch
    $ git checkout f-unittest-virtualenv
    # create a virtual conf to not play around with your system configuration
    $ virtualenv .
    $ source bin/activate
    # now let the tools do their jobs
    (MONK)$ pip install -r test-env.txt
    (MONK)$ python setup.py nosetests
    <installing requirements>
    <installing monk_tf>
    check if creating a SerialConn object works.. ok
    <coverage statistics>
    <test results>

    OK

With using `$ python setup.py develop` it's also possible to change your code
and test suite while also being able to unit test it with `$ python setup.py
nosetests` on the fly. Google for `setuptools develop` or ask me, if you want
to know more about that.

Last but not least this commit changes the place of the monk_tf folder again.
The reason is, that all the tools' default behaviour is to expect the structure
without the src/ folder. Before we decided that the src/ folder would be a
better choice, because then potential additional packages might be structured
in a more readable fashion with monk_tf. Because different tools are
interacting now and each has the same default expectation it seems more
logical to follow that expectation in the future. That's why this commit
changes the structure instead of configuring all the tools to our structure.

See Github Issue #34.

Signed-off-by: Erik Bernoth <erik.bernoth@gmail.com>
  • Loading branch information
erikbgithub committed May 21, 2013
1 parent ab7a91d commit 97c2462
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 668 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[nosetests]
#should not be set to 1 until bug is fixed in nosetests project
verbosity=2
detailed-errors=1
#xml output for jenkins and the likes
with-xunit=1
#coverage with xml as well
with-xcoverage=1
#only cover the monk package and leave the rest of python alone
cover-package=monk_tf
debug=nose.loader
pdb=1
pdb-failures=1
28 changes: 15 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@
# 2 of the License, or (at your option) any later version.
#

from distutils.core import setup
from setuptools import setup

project = 'monk_tf'
src_path = 'src'
version = '0.1.1'
project = "monk_tf"
version = "0.1.1"

setup(
name=project,
version=version,
description = 'a test framework for embedded systems',
author = 'DResearch Fahrzeugelektronik GmbH',
author_email = 'project-monk@dresearch-fe.de',
url='https://github.com/DFE/MONK',
description = "a test framework for embedded systems",
author = "DResearch Fahrzeugelektronik GmbH",
author_email = "project-monk@dresearch-fe.de",
url="https://github.com/DFE/MONK",
packages=[project],
package_dir = { '' : src_path },
setup_requires = [
"nose >= 1.0"
],
install_requires = [
'pyserial ==2.5',
'pylibssh2 ==1.0.1'
"pyserial >=2.5",
"pylibssh2 >=1.0.1"
],provides = [
'{} ({})'.format(project, version)
]
"{} ({})".format(project, version)
],
test_suite = "nose.collector"
)
6 changes: 6 additions & 0 deletions test-env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
argparse==1.2.1
coverage==3.6
distribute==0.6.34
nose==1.3.0
nosexcover==1.0.8
wsgiref==0.1.2
41 changes: 0 additions & 41 deletions test/test_all.py

This file was deleted.

260 changes: 0 additions & 260 deletions test/test_bcc.py

This file was deleted.

Loading

0 comments on commit 97c2462

Please sign in to comment.