Skip to content
This repository was archived by the owner on Apr 26, 2021. It is now read-only.

Commit e681460

Browse files
author
tsauerwein
committed
Enable tests
1 parent ae4cb51 commit e681460

File tree

6 files changed

+60
-5
lines changed

6 files changed

+60
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ install:
88
- make install
99

1010
script:
11-
- make lint
11+
- make check
1212

1313
notifications:
1414
email: false

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ help:
66
@echo
77
@echo "Main targets:"
88
@echo
9+
@echo "- check Run linter and tests"
10+
@echo "- test Run the tests"
911
@echo "- lint Run flake8 checker on the Python code"
1012
@echo "- clean Remove generated files"
1113
@echo "- cleanall Remove all the build artefacts"
@@ -19,18 +21,28 @@ clean:
1921
cleanall: clean
2022
rm -rf .build
2123

24+
.PHONY: check
25+
check: lint test
26+
2227
.PHONY: lint
2328
lint: .build/venv/bin/flake8
2429
.build/venv/bin/flake8 c2corg_common
2530

31+
.PHONY: test
32+
test: .build/venv/bin/nosetests .build/requirements.timestamp
33+
.build/venv/bin/nosetests
34+
2635
.PHONY: install
27-
install: install-dev-egg
36+
install: .build/requirements.timestamp
2837

29-
.PHONY: install-dev-egg
30-
install-dev-egg: $(SITE_PACKAGES)/c2corg_common.egg-link
38+
.build/requirements.timestamp: .build/venv requirements.txt
39+
.build/venv/bin/pip install -r requirements.txt
40+
touch $@
3141

3242
.build/venv/bin/flake8: .build/dev-requirements.timestamp
3343

44+
.build/venv/bin/nosetests: .build/dev-requirements.timestamp
45+
3446
.build/dev-requirements.timestamp: .build/venv dev-requirements.txt
3547
.build/venv/bin/pip install -r dev-requirements.txt
3648
touch $@

c2corg_common/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# package
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import unittest
2+
3+
from c2corg_common import attributes, sortable_search_attributes
4+
5+
6+
class SortableSearchAttributes(unittest.TestCase):
7+
8+
def test_check_search_attributes(self):
9+
""" Check that all values used in `sortable_search_attributes` have
10+
a corresponding value in `attributes`.
11+
"""
12+
for sortable_attribute_key in [
13+
key for key in sortable_search_attributes.__dict__
14+
if key.startswith('sortable_')]:
15+
original_attribute_key = sortable_attribute_key. \
16+
replace('sortable_', '')
17+
18+
if original_attribute_key not in attributes.__dict__:
19+
self.fail('{0} not found in {1}'.format(
20+
original_attribute_key, attributes))
21+
22+
self._check_values(sortable_attribute_key, original_attribute_key)
23+
24+
def _check_values(self, sortable_attribute_key, original_attribute_key):
25+
sortable_attribute = sortable_search_attributes. \
26+
__dict__[sortable_attribute_key]
27+
original_attribute = attributes. \
28+
__dict__[original_attribute_key]
29+
30+
used_numbers = set()
31+
for val in original_attribute:
32+
if val not in sortable_attribute:
33+
self.fail('{0} defined on {1} but not on {2}'.format(
34+
val, original_attribute_key, sortable_attribute_key
35+
))
36+
num = sortable_attribute[val]
37+
if num in used_numbers:
38+
self.fail('{0} is used twice in {1}'.format(
39+
num, sortable_attribute_key
40+
))
41+
used_numbers.add(num)

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
flake8==2.2.2
22
pep8-naming==0.2.2
3+
nose==1.3.7

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
packages=find_packages(),
2323
include_package_data=True,
2424
zip_safe=False,
25-
test_suite='c2corg_api',
25+
test_suite='c2corg_common',
2626
install_requires=requires,
2727
)

0 commit comments

Comments
 (0)