|
1 | 1 | """ |
2 | | -`argumented` provides a way of 'multiplying' functions - usually test cases - |
3 | | -allowing them to be called with multiple argument sets and still appear as |
4 | | -seperate test cases. |
5 | | -
|
6 | | -In the following example, each of the test cases would be replaced with two test |
7 | | -cases, each of which would call the test case with the given arguments. |
8 | | -
|
9 | | -`@argument(*args, **kwargs)` |
10 | | -
|
11 | | -Will call the test case with the given argument set |
12 | | -
|
13 | | -`@argument_list(*args)` |
14 | | -
|
15 | | -Will call the test case with each item in `*args` |
16 | | -
|
17 | | -`@argument_tuples(*args)` |
18 | | -
|
19 | | -Each item in `*args` must be a tuple containing an interable and a mapping, |
20 | | -which will then be used as an argument set for the test case (i.e. `([], {})`) |
21 | | -
|
22 | | -The decorators can be used multiple times, or used together - each of them |
23 | | -takes the arguments they are given and passes it to `pack_arguments(func, *args, |
24 | | -**kwargs)`, which adds a wrapped function to `func.__argumented__`. |
25 | | -
|
26 | | - @unpack_arguments |
27 | | - class TestArgumentedCases (unittest.TestCase): |
28 | | - |
29 | | - @argument("hello", thing="world") |
30 | | - @argument("goodbye", thing="world") |
31 | | - def test_greeting (self, greeting, thing): |
32 | | - self.assertIn(greeting, ["hello", "goodbye"]) |
33 | | - self.assertEquals(thing, "world") |
34 | | - |
35 | | - @argument_list(1, 2) |
36 | | - def test_with_arguments (self, n): |
37 | | - self.assertIsInstance(n, int) |
38 | | - |
39 | | - @argument_tuples( ([1, 2], {'a': 'A'}), ([1, 2], {'a': 'B'}) ) |
40 | | - def test_with_arguments (self, *args, *kwargs): |
41 | | - self.assertEquals(args, (1, 2)) |
42 | | - self.assertIn(kwargs['a'], ['A', 'B']) |
43 | | - |
44 | | -Originally inspired by [github.com/santtu/ddt](http://github.com/santtu/ddt), |
45 | | -though it ended up working somewhat diffrently. |
| 2 | +Pack and unpack functions into a set of wrapped functions with set arguments |
46 | 3 | """ |
47 | 4 |
|
| 5 | +__all__ = ['unpack_arguments', 'argument', 'argument_list', 'argument_tuples'] |
| 6 | + |
48 | 7 | from functools import wraps |
49 | 8 |
|
50 | 9 | def unpack_arguments (cls): |
|
0 commit comments