Skip to content
This repository was archived by the owner on Dec 9, 2020. It is now read-only.

Commit f82cdc4

Browse files
committed
Inital packaged version
1 parent 02b384e commit f82cdc4

6 files changed

Lines changed: 119 additions & 44 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
MANIFEST
2+
dist/*
3+
build/*
4+
*.egg-info/*
5+
*.pyc

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# `argumented`
2+
3+
`argumented` provides a way of 'multiplying' functions - usually test cases - allowing them to be called with multiple argument sets and still appear as seperate functions.
4+
5+
It provides several decorators that can be used to add argument sets, and then unpack them.
6+
7+
## Decorators
8+
9+
The argument decorators can be used multiple times, or used together - each of them takes the arguments they are given and passes it to `pack_arguments(func, *args, **kwargs)`, which adds a wrapped function to `func.__argumented__`.
10+
11+
#### `@argument(*args, **kwargs)`
12+
13+
Adds the given argument set
14+
15+
#### `@argument_list(*args)`
16+
17+
Adds each item in args as an argument set
18+
19+
#### `@argument_tuples(*args)`
20+
21+
Each item in `*args` must be a tuple containing an interable and a mapping, which will then be used as an argument set (i.e. `([], {})`)
22+
23+
#### `@unpack_arguments`
24+
25+
Unpacks all of the argument sets in a class, replacing each function with a list of argument sets with wrapped functions that call each argument set. The wrapped functions are named `{original name}_{argument set index}`.
26+
27+
## Example
28+
29+
In the following example, each test cases would be replaced with two test cases, which would each call the test case with the given arguments.
30+
31+
from unittest import TestCase
32+
from argumented import *
33+
34+
@unpack_arguments
35+
class TestArgumentedCases (TestCase):
36+
37+
@argument("hello", thing="world")
38+
@argument("goodbye", thing="world")
39+
def test_greeting (self, greeting, thing):
40+
self.assertIn(greeting, ["hello", "goodbye"])
41+
self.assertEquals(thing, "world")
42+
43+
@argument_list(1, 2)
44+
def test_with_arguments (self, n):
45+
self.assertIsInstance(n, int)
46+
47+
@argument_tuples( ([1, 2], {'a': 'A'}), ([1, 2], {'a': 'B'}) )
48+
def test_with_arguments (self, *args, **kwargs):
49+
self.assertEquals(args, (1, 2))
50+
self.assertIn(kwargs['a'], ['A', 'B'])
51+
52+
This example can also be found in `argumented/test_example.py`.
53+
54+
## License
55+
56+
`argumented` is licensed under the MIT License.
57+
58+
`argumented` was originally inspired by [ddt](http://github.com/santtu/ddt).

argumented/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
""" Multiply test cases or functions into several functions with argument sets """
2+
3+
from argumented import *
4+
5+
__version__ = "1.0.0"

argumented.py renamed to argumented/argumented.py

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,9 @@
11
"""
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
463
"""
474

5+
__all__ = ['unpack_arguments', 'argument', 'argument_list', 'argument_tuples']
6+
487
from functools import wraps
498

509
def unpack_arguments (cls):

argumented/test_example.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
""" A set of example tests for `argumented` """
2+
3+
from unittest import TestCase
4+
from argumented import *
5+
6+
@unpack_arguments
7+
class TestArgumentedCases (TestCase):
8+
9+
@argument("hello", thing="world")
10+
@argument("goodbye", thing="world")
11+
def test_greeting (self, greeting, thing):
12+
self.assertIn(greeting, ["hello", "goodbye"])
13+
self.assertEquals(thing, "world")
14+
15+
@argument_list(1, 2)
16+
def test_with_arguments (self, n):
17+
self.assertIsInstance(n, int)
18+
19+
@argument_tuples( ([1, 2], {'a': 'A'}), ([1, 2], {'a': 'B'}) )
20+
def test_with_arguments (self, *args, **kwargs):
21+
self.assertEquals(args, (1, 2))
22+
self.assertIn(kwargs['a'], ['A', 'B'])

setup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from distutils.core import setup
2+
from argumented import __version__, __doc__
3+
4+
setup(
5+
name = 'argumented',
6+
version = __version__,
7+
description = __doc__,
8+
long_description = open("README.md").read(),
9+
10+
author = 'Sam Clements',
11+
author_email = 'sam@borntyping.co.uk',
12+
url = 'https://github.com/borntyping/argumented',
13+
license = 'MIT License',
14+
15+
packages = ['argumented'],
16+
17+
classifiers = [
18+
'Development Status :: 4 - Beta',
19+
'Intended Audience :: Developers',
20+
'License :: OSI Approved :: MIT License',
21+
'Operating System :: OS Independent',
22+
'Programming Language :: Python',
23+
'Programming Language :: Python :: 2',
24+
'Topic :: Software Development :: Testing'
25+
],
26+
)

0 commit comments

Comments
 (0)