Skip to content

Commit 6f8b5f3

Browse files
committed
Moved to nose2 for tests
1 parent e3b690c commit 6f8b5f3

File tree

3 files changed

+88
-95
lines changed

3 files changed

+88
-95
lines changed

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r requirements.txt
2+
nose2>=0.6.5

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# Testing also requires nose>=1.2.1
21
requests>=2.10.0

spotlight/tests.py

Lines changed: 86 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
SKIP_ORDERED_DICT_TESTS = False
2-
try:
3-
from collections import OrderedDict
4-
except ImportError:
5-
SKIP_ORDERED_DICT_TESTS = True
6-
import sys
7-
sys.stderr.write('Skipping _dict_cleanup due to OrderedDict not being '
8-
'available.\n')
9-
10-
from collections import namedtuple
11-
from nose.tools import eq_, nottest, raises
12-
1+
from collections import namedtuple, OrderedDict
2+
from nose2.tools.such import helper
133
import spotlight
144

155

16-
@nottest
6+
# Expose unittest assertions to function-style tests
7+
assert_equals = helper.assertEquals
8+
assert_raises = helper.assertRaises
9+
10+
1711
def fake_request_post(self, *args, **kwargs):
1812
RawResponse = namedtuple('RawResponse', ['reason', ])
1913
hear_me_RawR = RawResponse(reason='Just a fake reason.')
@@ -32,62 +26,62 @@ def raise_for_status(self):
3226

3327

3428
def test_number_convert():
35-
eq_(spotlight._convert_number('0'), 0)
36-
eq_(spotlight._convert_number('0.2'), 0.2)
37-
eq_(spotlight._convert_number(True), True)
38-
eq_(spotlight._convert_number('evi'), 'evi')
29+
assert_equals(spotlight._convert_number('0'), 0)
30+
assert_equals(spotlight._convert_number('0.2'), 0.2)
31+
assert_equals(spotlight._convert_number(True), True)
32+
assert_equals(spotlight._convert_number('evi'), 'evi')
3933
# Testing the footnote workaround.
40-
eq_(spotlight._convert_number([1]), '[1]')
34+
assert_equals(spotlight._convert_number([1]), '[1]')
4135

4236

43-
@raises(spotlight.SpotlightException)
4437
def test_protocol_missing():
45-
spotlight.annotate('localhost', 'asdasdasd',
46-
headers={'fake_response': 'invalid json',
47-
'fake_status': 502})
38+
with assert_raises(spotlight.SpotlightException):
39+
spotlight.annotate('localhost', 'asdasdasd',
40+
headers={'fake_response': b'invalid json',
41+
'fake_status': 502})
4842

4943

50-
@raises(spotlight.requests.exceptions.HTTPError)
5144
def test_http_fail():
52-
spotlight.annotate('http://localhost', 'asdasdasd',
53-
headers={'fake_response': 'invalid json',
54-
'fake_status': 502})
45+
with assert_raises(spotlight.requests.exceptions.HTTPError):
46+
spotlight.annotate('http://localhost', 'asdasdasd',
47+
headers={'fake_response': b'invalid json',
48+
'fake_status': 502})
5549

5650

57-
@raises(ValueError)
5851
def test_annotation_invalid_json():
59-
spotlight.annotate('http://localhost', 'asdasdasd',
60-
headers={'fake_response': 'invalid json'})
52+
with assert_raises(ValueError):
53+
spotlight.annotate('http://localhost', 'asdasdasd',
54+
headers={'fake_response': b'invalid json'})
6155

6256

63-
@raises(spotlight.SpotlightException)
6457
def test_missing_resources():
65-
spotlight.annotate('http://localhost', 'asdasdasd',
66-
headers={'fake_response': '{"Test": "Win"}'})
58+
with assert_raises(spotlight.SpotlightException):
59+
spotlight.annotate('http://localhost', 'asdasdasd',
60+
headers={'fake_response': b'{"Test": "Win"}'})
6761

6862

69-
@raises(ValueError)
7063
def test_candidates_invalid_json():
71-
spotlight.annotate('http://localhost', 'asdasdasd',
72-
headers={'fake_response': 'invalid json'})
64+
with assert_raises(ValueError):
65+
spotlight.annotate('http://localhost', 'asdasdasd',
66+
headers={'fake_response': b'invalid json'})
7367

7468

75-
@raises(spotlight.SpotlightException)
7669
def test_missing_annotation():
77-
spotlight.candidates('http://localhost', 'asdasdasd',
78-
headers={'fake_response': '{"Test": "Win"}'})
70+
with assert_raises(spotlight.SpotlightException):
71+
spotlight.candidates('http://localhost', 'asdasdasd',
72+
headers={'fake_response': b'{"Test": "Win"}'})
7973

8074

81-
@raises(spotlight.SpotlightException)
8275
def test_missing_surfaceForms():
83-
spotlight.candidates('http://localhost', 'asdasdasd',
84-
headers={'fake_response': '{"annotation": {"Test": "Win"}}'})
76+
with assert_raises(spotlight.SpotlightException):
77+
spotlight.candidates('http://localhost', 'asdasdasd',
78+
headers={'fake_response': b'{"annotation": {"Test": "Win"}}'})
8579

8680

8781
def test_single_candidate():
8882
# Test with a single returned candidate, as was reported by issue #3.
8983
# Thanks to aolieman for the awesome test data!
90-
data = """
84+
data = b"""
9185
{
9286
"annotation":{
9387
"@text":"Industrial Design at the Technische Universiteit Delft",
@@ -123,61 +117,59 @@ def test_single_candidate():
123117
candidates = spotlight.candidates('http://localhost', 'asdasdasd',
124118
headers={'fake_response': data})
125119
expected_out = [
126-
{u'resource':
127-
[
120+
{
121+
'resource': [
128122
{
129-
u'finalScore': 0.8754365122251001,
130-
u'support': 3,
131-
u'uri': u'Technische_Universiteit_Delft',
132-
u'label': u'Technische Universiteit Delft',
133-
u'types': u'',
134-
u'percentageOfSecondRank': 0.1422872887244497,
135-
u'priorScore': 2.8799662606192636e-08,
136-
u'contextualScore': 0.9991813164782087
123+
'finalScore': 0.8754365122251001,
124+
'support': 3,
125+
'uri': 'Technische_Universiteit_Delft',
126+
'label': 'Technische Universiteit Delft',
127+
'types': '',
128+
'percentageOfSecondRank': 0.1422872887244497,
129+
'priorScore': 2.8799662606192636e-08,
130+
'contextualScore': 0.9991813164782087
137131
},
138132
{
139-
u'finalScore': 0.12456348777489806,
140-
u'support': 521,
141-
u'uri': u'Delft_University_of_Technology',
142-
u'label': u'Delft University of Technology',
143-
u'types': u'DBpedia:Agent, Schema:Organization, DBpedia:Organisation, Schema:EducationalOrganization, DBpedia:EducationalInstitution, Schema:CollegeOrUniversity, DBpedia:University',
144-
u'percentageOfSecondRank': 0.0,
145-
u'priorScore': 5.001541405942121e-06,
146-
u'contextualScore': 0.0008186418452925803
133+
'finalScore': 0.12456348777489806,
134+
'support': 521,
135+
'uri': 'Delft_University_of_Technology',
136+
'label': 'Delft University of Technology',
137+
'types': 'DBpedia:Agent, Schema:Organization, DBpedia:Organisation, Schema:EducationalOrganization, DBpedia:EducationalInstitution, Schema:CollegeOrUniversity, DBpedia:University',
138+
'percentageOfSecondRank': 0.0,
139+
'priorScore': 5.001541405942121e-06,
140+
'contextualScore': 0.0008186418452925803
147141
},
148-
],
149-
u'name': u'Technische Universiteit Delft',
150-
u'offset': 25
142+
],
143+
'name': 'Technische Universiteit Delft',
144+
'offset': 25
151145
}
152146
]
153-
eq_(candidates, expected_out)
154-
155-
156-
if not SKIP_ORDERED_DICT_TESTS:
157-
def test_dict_key_cleanup():
158-
dirty_dict = OrderedDict()
159-
dirty_dict['@dirty'] = 'value'
160-
dirty_dict['@empty'] = None # None values should be removed.
161-
dirty_dict['@recursive'] = OrderedDict()
162-
dirty_dict['@recursive']['tests'] = '1'
163-
dirty_dict['@recursive']['stuff'] = OrderedDict()
164-
more = OrderedDict()
165-
more['something'] = 'isgoingon'
166-
moremore = OrderedDict()
167-
moremore['@moar'] = True
168-
moar_iterable = [more, moremore]
169-
dirty_dict['@recursive']['stuff'] = moar_iterable
170-
171-
clean_dict = OrderedDict()
172-
clean_dict['dirty'] = 'value'
173-
clean_dict['recursive'] = OrderedDict()
174-
clean_dict['recursive']['tests'] = 1
175-
clean_dict['recursive']['stuff'] = OrderedDict()
176-
more = OrderedDict()
177-
more['something'] = 'isgoingon'
178-
moremore = OrderedDict()
179-
moremore['moar'] = True
180-
moar_iterable = [more, moremore]
181-
clean_dict['recursive']['stuff'] = moar_iterable
182-
eq_(spotlight._dict_cleanup(dirty_dict, dict_type=OrderedDict),
183-
clean_dict)
147+
assert_equals(candidates, expected_out)
148+
149+
150+
def test_dict_key_cleanup():
151+
dirty_dict = OrderedDict()
152+
dirty_dict['@dirty'] = 'value'
153+
dirty_dict['@empty'] = None # None values should be removed.
154+
dirty_dict['@recursive'] = OrderedDict()
155+
dirty_dict['@recursive']['tests'] = '1'
156+
dirty_dict['@recursive']['stuff'] = OrderedDict()
157+
more = OrderedDict()
158+
more['something'] = 'isgoingon'
159+
moremore = OrderedDict()
160+
moremore['@moar'] = True
161+
moar_iterable = [more, moremore]
162+
dirty_dict['@recursive']['stuff'] = moar_iterable
163+
164+
clean_dict = OrderedDict()
165+
clean_dict['dirty'] = 'value'
166+
clean_dict['recursive'] = OrderedDict()
167+
clean_dict['recursive']['tests'] = 1
168+
clean_dict['recursive']['stuff'] = OrderedDict()
169+
more = OrderedDict()
170+
more['something'] = 'isgoingon'
171+
moremore = OrderedDict()
172+
moremore['moar'] = True
173+
moar_iterable = [more, moremore]
174+
clean_dict['recursive']['stuff'] = moar_iterable
175+
assert_equals(spotlight._dict_cleanup(dirty_dict, dict_type=OrderedDict), clean_dict)

0 commit comments

Comments
 (0)