This repository was archived by the owner on Mar 27, 2022. It is now read-only.
File tree Expand file treeCollapse file tree 6 files changed+43
-1
lines changedFilter options
+43
-1
lines changed Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
11
11
from mockwrapper import MockWrapper, mock_wrapper
12
12
from mockanchor import MockAnchor, mock_on
13
13
14
+
__unittest = True
15
+
14
16
def _setup():
15
17
MockWrapper._setup()
16
18
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1
1
from callrecord import CallRecord
2
+
__unittest = True
2
3
3
4
class MockMatcher(object):
4
5
_multiplicity = None
Original file line number Diff line number Diff line change
@@ -19,8 +19,11 @@
19
19
import unittest
20
20
import re
21
21
import sys
22
+
import os
22
23
import mock
23
24
25
+
__unittest = True
26
+
24
27
def _compose(hook, func):
25
28
if hook is None:
26
29
return func
@@ -272,4 +275,4 @@ def run(self, result=None):
272
275
if ok: result.addSuccess(self)
273
276
finally:
274
277
result.stopTest(self)
275
-
278
+
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
8
8
A MockWrapper / SilentMock pair can be created with mock_wrapper()
9
9
(the silent mock object is accessible via mock_wrapper()_)
10
10
"""
11
+
__unittest = True
11
12
12
13
from lib.realsetter import RealSetter
13
14
from silentmock import SilentMock, raw_mock
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
9
9
from mockerror import MockError
10
10
11
11
DEFAULT = object()
12
+
__unittest = True
12
13
13
14
def raw_mock(name = None, **kwargs):
14
15
"""a silent mock object. use mock_of(silent_mock) to set expectations, etc"""
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1
1
import unittest
2
2
import re
3
3
import sys
4
+
import os
4
5
5
6
import helper
6
7
import mocktest
@@ -354,6 +355,39 @@ def test_reality_formatting(self):
354
355
355
356
for got, expected in zip(line_agnostic_repr, expected_lines):
356
357
self.assertEqual(got, expected)
358
+
359
+
def test_removing_of_mocktest_lines_from_exception_traces(self):
360
+
# unittest has built-in functionality to ignore lines that correspond
361
+
# to internal unittest code. Mocktest hooks into this, by defining
362
+
# a __unittest variable in the global scope of all mocktest files that
363
+
# raise AssertionErrors. This causes unittest to think that mocktest is
364
+
# an internal part of unittest.
365
+
mocktest_file_names = os.listdir(os.path.join(os.path.dirname(__file__), '..','mocktest'))
366
+
mocktest_file_names = filter(lambda x: x.endswith('.py'), mocktest_file_names)
367
+
self.assertTrue(len(mocktest_file_names) > 2) # make sure we have some file names
368
+
def ensure_no_mocktest_files_appear_in_failure(failure_func):
369
+
result = self.run_method(failure_func)
370
+
self.assertEqual(len(result.failures), 1)
371
+
lines = result.failures[0][1].splitlines()
372
+
for filename in mocktest_file_names:
373
+
lines_containing_mocktest_internal_files = [line for line in lines if (filename + '"') in line]
374
+
self.assertEqual([], lines_containing_mocktest_internal_files)
375
+
376
+
ensure_no_mocktest_files_appear_in_failure(lambda slf: slf.assertEqual(False, True))
377
+
ensure_no_mocktest_files_appear_in_failure(lambda slf: slf.assertTrue(False))
378
+
ensure_no_mocktest_files_appear_in_failure(lambda slf: slf.assertFalse(True))
379
+
ensure_no_mocktest_files_appear_in_failure(lambda slf: slf.assertRaises(TypeError, self.make_error))
380
+
381
+
def failing_mock_expectation(slf):
382
+
mocktest.mock_wrapper().is_expected
383
+
# emulate a refresh
384
+
try:
385
+
mocktest._teardown()
386
+
finally:
387
+
mocktest._setup()
388
+
ensure_no_mocktest_files_appear_in_failure(failing_mock_expectation)
389
+
390
+
357
391
358
392
class MockTestTest(mocktest.TestCase):
359
393
def test_should_do_expectations(self):
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4