Skip to content

Commit

Permalink
nose testing stub
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Feb 25, 2011
1 parent 7cd909f commit 9241520
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
10 changes: 9 additions & 1 deletion README.rst
Expand Up @@ -26,7 +26,15 @@ If you have `nose` installed, you may run the test suite by running:

::

nosetests gpustats
import gpustats
gpustats.test()

Use
---

::

import gpustats

Notes
-----
Expand Down
54 changes: 54 additions & 0 deletions gpustats/__init__.py
@@ -0,0 +1,54 @@
from pdfs import *

from numpy import errstate
from numpy.testing import Tester
class NoseWrapper(Tester):
'''
This is simply a monkey patch for numpy.testing.Tester.
It allows extra_argv to be changed from its default None to ['--exe'] so
that the tests can be run the same across platforms. It also takes kwargs
that are passed to numpy.errstate to suppress floating point warnings.
'''
def test(self, label='fast', verbose=1, extra_argv=['--exe'], doctests=False,
coverage=False, **kwargs):
''' Run tests for module using nose
%(test_header)s
doctests : boolean
If True, run doctests in module, default False
coverage : boolean
If True, report coverage of NumPy code, default False
(Requires the coverage module:
http://nedbatchelder.com/code/modules/coverage.html)
kwargs
Passed to numpy.errstate. See its documentation for details.
'''

# cap verbosity at 3 because nose becomes *very* verbose beyond that
verbose = min(verbose, 3)

from numpy.testing import utils
utils.verbose = verbose

if doctests:
print "Running unit tests and doctests for %s" % self.package_name
else:
print "Running unit tests for %s" % self.package_name

self._show_system_info()

# reset doctest state on every run
import doctest
doctest.master = None

argv, plugins = self.prepare_test_args(label, verbose, extra_argv,
doctests, coverage)
from numpy.testing.noseclasses import NumpyTestProgram
from warnings import simplefilter #, catch_warnings
with errstate(**kwargs):
## with catch_warnings():
simplefilter('ignore', category=DeprecationWarning)
t = NumpyTestProgram(argv=argv, exit=False, plugins=plugins)
return t.result
test = NoseWrapper().test
2 changes: 2 additions & 0 deletions gpustats/pdfs.py
Expand Up @@ -12,6 +12,8 @@

from pandas.util.testing import set_trace as st

__all__ = ['mvnpdf', 'mvnpdf_multi', 'normpdf', 'normpdf_multi']

cu_module = codegen.get_full_cuda_module()

#-------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions gpustats/tests/test_pdfs.py
Expand Up @@ -9,7 +9,7 @@

import scipy.stats as sp_stats

import gpustats.pdfs as pdfs
import gpustats as gps
import gpustats.compat as compat
import gpustats.util as util

Expand All @@ -36,7 +36,7 @@ def _compare_multi(n, k, p):
pyresult = compat.python_mvnpdf(data, means, covs)

# gpu
result = pdfs.mvnpdf_multi(data, means, covs)
result = gps.mvnpdf_multi(data, means, covs)

return result, pyresult

Expand All @@ -49,7 +49,7 @@ def _compare_single(n, k):
# cpu in PyMC
pyresult = compat.python_mvnpdf(data, [mean], [cov]).squeeze()
# gpu
result = pdfs.mvnpdf(data, mean, cov)
result = gps.mvnpdf(data, mean, cov)
return result, pyresult

class TestMVN(unittest.TestCase):
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_normal(self):
data = randn(n)
pyresult = sp_stats.norm.pdf(data, loc=mean, scale=std)

result = pdfs.normpdf(data, mean, std, logged=True)
result = gps.normpdf(data, mean, std, logged=True)
assert_almost_equal(result, np.log(pyresult), DECIMAL_5)

if __name__ == '__main__':
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@
AUTHOR_EMAIL = "wesmckinn@gmail.com"
URL = "https://github.com/dukestats/gpustats"
CLASSIFIERS = [
'Development Status :: 3 - Alpha',
'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Operating System :: OS Independent',
'Intended Audience :: Science/Research',
Expand All @@ -55,6 +55,8 @@ def configuration(parent_package='', top_path=None):
quiet=True)

config.add_subpackage('gpustats')
config.add_data_dir('gpustats/tests')
config.add_data_dir('gpustats/cufiles')
return config

if __name__ == '__main__':
Expand Down

0 comments on commit 9241520

Please sign in to comment.