X Tutup
Skip to content

Commit 57d4ee0

Browse files
committed
Sprinkle some assertIn/assertNotIn into tests. Refs #428.
1 parent c2b4fbe commit 57d4ee0

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed

.travis.yml

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

99
install:
1010
- "python setup.py install"
11-
- "pip install 'curtsies<0.2.0' greenlet pygments requests"
11+
- "pip install 'curtsies<0.2.0' greenlet pygments requests unittest2"
1212

1313
script:
1414
- cd build/lib/

bpython/test/test_crashers.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import sys
66
import termios
77
import textwrap
8-
import unittest
98

109
try:
11-
from unittest import skip
10+
import unittest2 as unittest
1211
except ImportError:
13-
def skip(f):
14-
return lambda self: None
12+
import unittest
1513

1614
try:
1715
from twisted.internet import reactor
@@ -103,14 +101,13 @@ def spam(a, (b, c)):
103101
return self.run_bpython(input).addCallback(self.check_no_traceback)
104102

105103
def check_no_traceback(self, data):
106-
tb = data[data.find("Traceback"):]
107-
self.assertTrue("Traceback" not in data, tb)
104+
self.assertNotIn("Traceback", data)
108105

109106
if reactor is not None:
110107
class CursesCrashersTest(TrialTestCase, CrashersTest):
111108
backend = "cli"
112109

113-
@skip("take 6 seconds, and Simon says we can skip them")
110+
@unittest.skip("take 6 seconds, and Simon says we can skip them")
114111
class UrwidCrashersTest(TrialTestCase, CrashersTest):
115112
backend = "urwid"
116113

bpython/test/test_manual_readline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def setUp(self):
222222
def test_seq(self):
223223
f = lambda cursor_offset, line: ('hi', 2)
224224
self.edits.add('a', f)
225-
self.assertTrue('a' in self.edits)
225+
self.assertIn('a', self.edits)
226226
self.assertEqual(self.edits['a'], f)
227227
self.assertEqual(self.edits.call('a', cursor_offset=3, line='hello'),
228228
('hi', 2))
@@ -245,12 +245,12 @@ def test_config(self):
245245
f = lambda cursor_offset, line: ('hi', 2)
246246
g = lambda cursor_offset, line: ('hey', 3)
247247
self.edits.add_config_attr('att', f)
248-
self.assertFalse('att' in self.edits)
248+
self.assertNotIn('att', self.edits)
249249
class config: att = 'c'
250250
key_dispatch = {'c': 'c'}
251251
configured_edits = self.edits.mapping_with_config(config, key_dispatch)
252252
self.assertTrue(configured_edits.__contains__, 'c')
253-
self.assertFalse('c' in self.edits)
253+
self.assertNotIn('c', self.edits)
254254
self.assertRaises(NotImplementedError,
255255
configured_edits.add_config_attr, 'att2', g)
256256
self.assertRaises(NotImplementedError,

bpython/test/test_repl.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import os
44
import socket
55
import sys
6-
import unittest
76

87
from mock import Mock, MagicMock
98

109
try:
11-
from unittest import skip
10+
import unittest2 as unittest
1211
except ImportError:
13-
def skip(f):
14-
return lambda self: None
12+
import unittest
1513

1614
py3 = (sys.version_info[0] == 3)
1715

@@ -101,7 +99,7 @@ def test_append(self):
10199

102100
self.assertEqual(self.history.back(), 'print "foo\n"')
103101

104-
@skip("I don't understand this test")
102+
@unittest.skip("I don't understand this test")
105103
def test_enter(self):
106104
self.history.enter('#lastnumber!')
107105

@@ -278,7 +276,7 @@ def assert_get_source_error_for_current_function(self, func, msg):
278276
def test_current_function(self):
279277
self.set_input_line('INPUTLINE')
280278
self.repl.current_func = collections.MutableSet.add
281-
self.assertTrue("Add an element." in self.repl.get_source_of_current_name())
279+
self.assertIn("Add an element.", self.repl.get_source_of_current_name())
282280

283281
self.assert_get_source_error_for_current_function(
284282
collections.defaultdict.copy, "No source code found for INPUTLINE")
@@ -295,7 +293,7 @@ def test_current_function(self):
295293
def test_current_line(self):
296294
self.repl.interp.locals['a'] = socket.socket
297295
self.set_input_line('a')
298-
self.assertTrue('dup(self)' in self.repl.get_source_of_current_name())
296+
self.assertIn('dup(self)', self.repl.get_source_of_current_name())
299297

300298
#TODO add tests for various failures without using current function
301299

@@ -334,7 +332,7 @@ def test_simple_global_complete(self):
334332
self.assertEqual(self.repl.matches_iter.matches,
335333
['def', 'del', 'delattr(', 'dict(', 'dir(', 'divmod('])
336334

337-
@skip("disabled while non-simple completion is disabled")
335+
@unittest.skip("disabled while non-simple completion is disabled")
338336
def test_substring_global_complete(self):
339337
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SUBSTRING})
340338
self.setInputLine("time")
@@ -344,7 +342,7 @@ def test_substring_global_complete(self):
344342
self.assertEqual(self.repl.completer.matches,
345343
['RuntimeError(', 'RuntimeWarning('])
346344

347-
@skip("disabled while non-simple completion is disabled")
345+
@unittest.skip("disabled while non-simple completion is disabled")
348346
def test_fuzzy_global_complete(self):
349347
self.repl = FakeRepl({'autocomplete_mode': autocomplete.FUZZY})
350348
self.setInputLine("doc")
@@ -368,7 +366,7 @@ def test_simple_attribute_complete(self):
368366
self.assertEqual(self.repl.matches_iter.matches,
369367
['Foo.bar'])
370368

371-
@skip("disabled while non-simple completion is disabled")
369+
@unittest.skip("disabled while non-simple completion is disabled")
372370
def test_substring_attribute_complete(self):
373371
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SUBSTRING})
374372
self.setInputLine("Foo.az")
@@ -382,7 +380,7 @@ def test_substring_attribute_complete(self):
382380
self.assertEqual(self.repl.completer.matches,
383381
['Foo.baz'])
384382

385-
@skip("disabled while non-simple completion is disabled")
383+
@unittest.skip("disabled while non-simple completion is disabled")
386384
def test_fuzzy_attribute_complete(self):
387385
self.repl = FakeRepl({'autocomplete_mode': autocomplete.FUZZY})
388386
self.setInputLine("Foo.br")
@@ -412,7 +410,7 @@ def test_file_should_not_appear_in_complete(self):
412410
self.setInputLine("_")
413411
self.assertTrue(self.repl.complete())
414412
self.assertTrue(hasattr(self.repl.matches_iter,'matches'))
415-
self.assertTrue('__file__' not in self.repl.matches_iter.matches)
413+
self.assertNotIn('__file__', self.repl.matches_iter.matches)
416414

417415

418416
class TestCliRepl(unittest.TestCase):
@@ -465,7 +463,7 @@ def test_simple_tab_complete(self):
465463
self.repl.complete.assert_called_with(tab=True)
466464
self.assertEqual(self.repl.s, "foobar")
467465

468-
@skip("disabled while non-simple completion is disabled")
466+
@unittest.skip("disabled while non-simple completion is disabled")
469467
def test_substring_tab_complete(self):
470468
self.repl.s = "bar"
471469
self.repl.config.autocomplete_mode = autocomplete.FUZZY
@@ -474,7 +472,7 @@ def test_substring_tab_complete(self):
474472
self.repl.tab()
475473
self.assertEqual(self.repl.s, "foofoobar")
476474

477-
@skip("disabled while non-simple completion is disabled")
475+
@unittest.skip("disabled while non-simple completion is disabled")
478476
def test_fuzzy_tab_complete(self):
479477
self.repl.s = "br"
480478
self.repl.config.autocomplete_mode = autocomplete.FUZZY
@@ -509,7 +507,7 @@ def test_back_parameter(self):
509507
self.assertTrue(self.repl.s, "previtem")
510508

511509
# Attribute Tests
512-
@skip("disabled while non-simple completion is disabled")
510+
@unittest.skip("disabled while non-simple completion is disabled")
513511
def test_fuzzy_attribute_tab_complete(self):
514512
"""Test fuzzy attribute with no text"""
515513
self.repl.s = "Foo."
@@ -518,7 +516,7 @@ def test_fuzzy_attribute_tab_complete(self):
518516
self.repl.tab()
519517
self.assertEqual(self.repl.s, "Foo.foobar")
520518

521-
@skip("disabled while non-simple completion is disabled")
519+
@unittest.skip("disabled while non-simple completion is disabled")
522520
def test_fuzzy_attribute_tab_complete2(self):
523521
"""Test fuzzy attribute with some text"""
524522
self.repl.s = "Foo.br"
@@ -538,14 +536,14 @@ def test_simple_expand(self):
538536
self.repl.tab()
539537
self.assertEqual(self.repl.s, "foo")
540538

541-
@skip("disabled while non-simple completion is disabled")
539+
@unittest.skip("disabled while non-simple completion is disabled")
542540
def test_substring_expand_forward(self):
543541
self.repl.config.autocomplete_mode = autocomplete.SUBSTRING
544542
self.repl.s = "ba"
545543
self.repl.tab()
546544
self.assertEqual(self.repl.s, "bar")
547545

548-
@skip("disabled while non-simple completion is disabled")
546+
@unittest.skip("disabled while non-simple completion is disabled")
549547
def test_fuzzy_expand(self):
550548
pass
551549

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def initialize_options(self):
183183
'requests'
184184
],
185185
extras_require = extras_require,
186-
tests_require = ['mock'],
186+
tests_require = ['mock', 'unittest2'],
187187
packages = packages,
188188
data_files = data_files,
189189
package_data = {

0 commit comments

Comments
 (0)
X Tutup