From 12b5b555d86a79199f289c55dac10178d3840ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carles=20Barrob=C3=A9s?= Date: Mon, 13 Feb 2012 23:55:46 +0000 Subject: [PATCH] Added functional tests --- build.sh | 3 +++ test-requirements.txt | 2 ++ test/__init__.py | 0 test/test_functional.py | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100755 build.sh create mode 100644 test-requirements.txt create mode 100644 test/__init__.py create mode 100644 test/test_functional.py diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..63d4cd4 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash +nosetests +pep8 ddt.py test diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..9831eab --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +nose +pep8 diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_functional.py b/test/test_functional.py new file mode 100644 index 0000000..20033ce --- /dev/null +++ b/test/test_functional.py @@ -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)