Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > site-packages > testfixtures > tests
Operation : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
__pycache__ | Directory | - | - | |
test_django | Directory | - | - | |
__init__.py | File | 64 bytes | April 17 2025 13:10:58. | |
configparser-read.txt | File | 832 bytes | April 17 2025 13:10:58. | |
configparser-write.txt | File | 775 bytes | April 17 2025 13:10:58. | |
directory-contents.txt | File | 739 bytes | April 17 2025 13:10:58. | |
sample1.py | File | 1137 bytes | April 17 2025 13:10:58. | |
sample2.py | File | 412 bytes | April 17 2025 13:10:58. | |
sample3.py | File | 43 bytes | April 17 2025 13:10:58. | |
test_compare.py | File | 62813 bytes | April 17 2025 13:10:58. | |
test_comparison.py | File | 22706 bytes | April 17 2025 13:10:58. | |
test_components.py | File | 974 bytes | April 17 2025 13:10:58. | |
test_date.py | File | 10659 bytes | April 17 2025 13:10:58. | |
test_datetime.py | File | 16979 bytes | April 17 2025 13:10:58. | |
test_diff.py | File | 892 bytes | April 17 2025 13:10:58. | |
test_generator.py | File | 467 bytes | April 17 2025 13:10:58. | |
test_log_capture.py | File | 7379 bytes | April 17 2025 13:10:58. | |
test_logcapture.py | File | 19667 bytes | April 17 2025 13:10:58. | |
test_mappingcomparison.py | File | 9651 bytes | April 17 2025 13:10:58. | |
test_mock.py | File | 2245 bytes | April 17 2025 13:10:58. | |
test_outputcapture.py | File | 4355 bytes | April 17 2025 13:10:58. | |
test_popen.py | File | 23314 bytes | April 17 2025 13:10:58. | |
test_popen_docs.py | File | 7684 bytes | April 17 2025 13:10:58. | |
test_rangecomparison.py | File | 5330 bytes | April 17 2025 13:10:58. | |
test_replace.py | File | 29971 bytes | April 17 2025 13:10:58. | |
test_replacer.py | File | 3906 bytes | April 17 2025 13:10:58. | |
test_roundcomparison.py | File | 4828 bytes | April 17 2025 13:10:58. | |
test_sequencecomparison.py | File | 12368 bytes | April 17 2025 13:10:58. | |
test_should_raise.py | File | 9967 bytes | April 17 2025 13:10:58. | |
test_shouldwarn.py | File | 4619 bytes | April 17 2025 13:10:58. | |
test_stringcomparison.py | File | 1354 bytes | April 17 2025 13:10:58. | |
test_sybil.py | File | 4302 bytes | April 17 2025 13:10:58. | |
test_tempdir.py | File | 2883 bytes | April 17 2025 13:10:58. | |
test_tempdirectory.py | File | 11215 bytes | April 17 2025 13:10:58. | |
test_time.py | File | 7734 bytes | April 17 2025 13:10:58. | |
test_twisted.py | File | 5672 bytes | April 17 2025 13:10:58. | |
test_wrap.py | File | 6576 bytes | April 17 2025 13:10:58. |
from unittest import TestCase from testfixtures.mock import Mock, MagicMock, patch, DEFAULT from testfixtures import wrap, compare, log_capture, LogCapture class TestWrap(TestCase): def test_wrapping(self): m = Mock() @wrap(m.before, m.after) def test_function(r): m.test() return 'something' compare(m.method_calls, []) compare(test_function(), 'something') compare(m.method_calls, [ ('before', (), {}), ('test', (), {}), ('after', (), {}) ]) def test_wrapping_only_before(self): before = Mock() @wrap(before) def test_function(): return 'something' self.assertFalse(before.called) compare(test_function(), 'something') compare(before.call_count, 1) def test_wrapping_wants_return(self): m = Mock() m.before.return_value = 'something' @wrap(m.before, m.after) def test_function(r): m.test(r) return 'r:'+r compare(m.method_calls, []) compare(test_function(), 'r:something') compare(m.method_calls, [ ('before', (), {}), ('test', ('something', ), {}), ('after', (), {}) ]) def test_wrapping_wants_arguments(self): # This only works in python 2.5+, for # earlier versions, you'll have to come # up with your own `partial` class... from functools import partial m = Mock() @wrap(partial(m.before, 1, x=2), partial(m.after, 3, y=4)) def test_function(r): m.test() return 'something' compare(m.method_calls, []) compare(test_function(), 'something') compare(m.method_calls, [ ('before', (1, ), {'x': 2}), ('test', (), {}), ('after', (3, ), {'y': 4}) ]) def test_multiple_wrappers(self): m = Mock() @wrap(m.before2, m.after2) @wrap(m.before1, m.after1) def test_function(): m.test_function() return 'something' compare(m.method_calls, []) compare(test_function(), 'something') compare(m.method_calls, [ ('before1', (), {}), ('before2', (), {}), ('test_function', (), {}), ('after2', (), {}), ('after1', (), {}), ]) def test_multiple_wrappers_wants_return(self): m = Mock() m.before1.return_value = 1 m.before2.return_value = 2 @wrap(m.before2, m.after2) @wrap(m.before1, m.after1) def test_function(r1, r2): m.test_function(r1, r2) return 'something' compare(m.method_calls, []) compare(test_function(), 'something') compare(m.method_calls, [ ('before1', (), {}), ('before2', (), {}), ('test_function', (1, 2), {}), ('after2', (), {}), ('after1', (), {}), ]) def test_multiple_wrappers_only_want_first_return(self): m = Mock() m.before1.return_value = 1 @wrap(m.before2, m.after2) @wrap(m.before1, m.after1) def test_function(r1): m.test_function(r1) return 'something' compare(m.method_calls, []) compare(test_function(), 'something') compare(m.method_calls, [ ('before1', (), {}), ('before2', (), {}), ('test_function', (1, ), {}), ('after2', (), {}), ('after1', (), {}), ]) def test_wrap_method(self): m = Mock() class T: @wrap(m.before, m.after) def method(self): m.method() T().method() compare(m.method_calls, [ ('before', (), {}), ('method', (), {}), ('after', (), {}) ]) def test_wrap_method_wants_return(self): m = Mock() m.before.return_value = 'return' class T: @wrap(m.before, m.after) def method(self, r): m.method(r) T().method() compare(m.method_calls, [ ('before', (), {}), ('method', ('return', ), {}), ('after', (), {}) ]) def test_wrapping_different_functions(self): m = Mock() @wrap(m.before1, m.after1) def test_function1(): m.something1() return 'something1' @wrap(m.before2, m.after2) def test_function2(): m.something2() return 'something2' compare(m.method_calls, []) compare(test_function1(), 'something1') compare(m.method_calls, [ ('before1', (), {}), ('something1', (), {}), ('after1', (), {}) ]) compare(test_function2(), 'something2') compare(m.method_calls, [ ('before1', (), {}), ('something1', (), {}), ('after1', (), {}), ('before2', (), {}), ('something2', (), {}), ('after2', (), {}) ]) def test_wrapping_local_vars(self): m = Mock() @wrap(m.before, m.after) def test_function(): something = 1 m.test() return 'something' compare(m.method_calls, []) compare(test_function(), 'something') compare(m.method_calls, [ ('before', (), {}), ('test', (), {}), ('after', (), {}) ]) def test_wrapping__name__(self): m = Mock() @wrap(m.before, m.after) def test_function(): pass # pragma: no cover compare(test_function.__name__, 'test_function') def test_our_wrap_dealing_with_mock_patch(self): @patch.multiple('testfixtures.tests.sample1', X=DEFAULT) @log_capture() def patched(log, X): from testfixtures.tests.sample1 import X as imported_X assert isinstance(log, LogCapture) assert isinstance(X, MagicMock) assert imported_X is X patched() def test_patch_with_dict(self): @patch('testfixtures.tests.sample1.X', {'x': 1}) @log_capture() def patched(log): assert isinstance(log, LogCapture) from testfixtures.tests.sample1 import X assert X == {'x': 1} patched()
SILENT KILLER Tool