Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Now requires python2.7 (or at least for the name `unittest` to resolve

  to unittest2)
* Strip unittest2 dependency
* Add testscenarios dependency, for much cleaner gneration of tests
* Add testtools, so we can take advantage of its nice test runner.
  • Loading branch information...
commit a8d686ac64c5c4b08bf3da05c7d66bc26b007cba 1 parent b8d35ac
@jamezpolley authored
View
1  .gitignore
@@ -10,3 +10,4 @@ include/
MANIFEST
dist/
lib64/
+.pipped
View
10 Makefile
@@ -4,7 +4,7 @@ ACTIVATE = . bin/activate
all: test doc
-virtualenv: lib/python2.6/site.py
+virtualenv: lib/python2.7/site.py
distclean: virtualenv-clean clean
@@ -15,8 +15,8 @@ clean:
find . \( -name \*\.pyc -o -name \*\.dot -o -name \*\.svg -o -name \*\.png \) -delete
hg clean
-lib/python2.6/site.py:
- virtualenv --no-site-packages .
+lib/python2.7/site.py:
+ virtualenv --python=python2.7 --no-site-packages .
freeze:
pip freeze -E . > requirements.txt
@@ -28,8 +28,8 @@ freeze:
install: virtualenv .pipped
test: install
- $(ACTIVATE) && unit2 discover -t ./ tests/
- $(ACTIVATE) && cd doc && $(MAKE) doctest
+ $(ACTIVATE) && python -m testtools.run discover
+ #$(ACTIVATE) && cd doc && $(MAKE) doctest
edit:
$(EDITOR) *.py tests/*.py tests/*.yaml rules/*.yaml
View
7 requirements.txt
@@ -1,6 +1,3 @@
PyYAML==3.10
-distribute==0.6.19
-readline==6.2.0
-ipython==0.11
-unittest2==0.5.1
-wsgiref==0.1.2
+testscenarios==0.2
+testtools==0.9.14
View
5 setup.py
@@ -4,7 +4,7 @@
setup (
name = 'constraints',
packages = ['constraints'],
- version = '0.9.2',
+ version = '0.9.5',
description = 'Returns a constrained subset of the members of a dict of dicts',
author = 'James Polley',
author_email = 'jamezpolley@gmail.com',
@@ -20,7 +20,8 @@
],
requires = [
'PyYAML',
- 'unittest2'
+ 'testtools',
+ 'testscenarios',
],
)
View
21 test/groups.yaml
@@ -63,3 +63,24 @@ test_additions:
- eddard
- bran
- catelyn
+test_members_for_attr:
+ groupname: big_cities
+ criteria:
+ - location:
+ - Free Cities
+ - Kings Landing
+ members:
+ - robert
+ - cersei
+ - tyrion
+ - viserys
+ - daenrys
+test_members_for_multiple_criteria:
+ groupname: winterfell_tullys
+ criteria:
+ - location:
+ - Winterfell
+ department:
+ - Tully
+ members:
+ - catelyn
View
58 test/test_constraints.py
@@ -1,7 +1,9 @@
#!/usr/bin/env python
import yaml
-import unittest2
+import unittest
+
+from testscenarios import TestWithScenarios
from constraints.constraints import Constraints
@@ -13,49 +15,31 @@
groups_file=open('test/groups.yaml')
groups=yaml.load(groups_file)
-def generate_group_membership_checker(criteria, expected_members, exceptions):
- def check_group_membership(self):
- generated_members = self.constrainer.get_members(criteria, exceptions)
- self.assertItemsEqual(expected_members, generated_members)
- return check_group_membership
+scenarios = []
-class TestConstraints(unittest2.TestCase):
+for test_name, test_data in groups.items():
+ if 'exceptions' not in test_data:
+ test_data['exceptions'] = None
+ scenarios.append((test_name, test_data))
+
+class TestConstraintsWithSampleDirectory(TestWithScenarios):
+
+ scenarios = scenarios
def setUp(self):
self.groups = groups
self.directory = directory
self.constrainer = Constraints(self.directory)
- def test_members_for_attr(self):
- attr = 'location'
- values = ['Free Cities', 'Kings Landing']
- expected_members = ['robert', 'cersei', 'tyrion', 'viserys', 'daenrys']
- generated_members = self.constrainer._get_members_for_attr(
- attr, values)
- self.assertItemsEqual(expected_members, generated_members)
-
- def test_members_for_criterion(self):
- criterion = { 'location': ['Winterfell'], 'department': ['Tully'] }
- expected_members = ['catelyn']
- generated_members = self.constrainer._get_members_for_criterion(
- criterion)
- self.assertItemsEqual(expected_members, generated_members)
-
-for test_name, test_data in groups.items():
- if 'exceptions' not in test_data:
- test_data['exceptions'] = None
- test = generate_group_membership_checker(test_data['criteria'],
- test_data['members'], test_data['exceptions'])
- setattr(TestConstraints, test_name, test)
-test_cases = [TestConstraints]
+ def test_group(self):
+ generated_members = self.constrainer.get_members(self.criteria,
+ self.exceptions)
+ self.assertItemsEqual(self.members, generated_members)
-def load_tests(loader, tests, pattern):
- suite = unittest2.TestSuite()
- for test_class in test_cases:
- tests = loader.loadTestsFromTestCase(test_class)
- suite.addTests(tests)
- return suite
+class TestConstraints(unittest.TestCase):
-if __name__=='__main__':
- unittest2.main()
+ def setUp(self):
+ self.groups = groups
+ self.directory = directory
+ self.constrainer = Constraints(self.directory)
Please sign in to comment.
Something went wrong with that request. Please try again.