Added functional tests

This commit is contained in:
Carles Barrobés
2012-02-13 23:55:46 +00:00
parent 8fae95add0
commit 12b5b555d8
4 changed files with 44 additions and 0 deletions

3
build.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
nosetests
pep8 ddt.py test

2
test-requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
nose
pep8

0
test/__init__.py Normal file
View File

39
test/test_functional.py Normal file
View File

@@ -0,0 +1,39 @@
from ddt import ddt, data
from nose.tools import assert_equal
class Dummy(object):
"""Dummy class to test decorators on"""
@data(1, 2, 3, 4)
def test_something(self):
pass
def test_data_decorator():
"""Test the ``data`` method decorator"""
def hello():
pass
pre_size = len(hello.__dict__)
keys = hello.__dict__.keys()
data_hello = data(1, 2)(hello)
dh_keys = data_hello.__dict__.keys()
post_size = len(data_hello.__dict__)
assert_equal(post_size, pre_size + 1)
extra_attrs = set(dh_keys) - set(keys)
assert_equal(len(extra_attrs), 1)
extra_attr = extra_attrs.pop()
assert_equal(getattr(data_hello, extra_attr), (1, 2))
def test_ddt():
"""Test the ``ddt`` class decorator"""
is_test = lambda x: x.startswith('test_')
tests = len(filter(is_test, Dummy.__dict__))
assert_equal(tests, 1)
post_dummy = ddt(Dummy)
post_tests = len(filter(is_test, post_dummy.__dict__))
assert_equal(post_tests, 4)