Split the tests between the core and plugin
The tests for _assertionnew are much better, the ones for pytest_assert_compare() are still not great. --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									2b3ac35780
								
							
						
					
					
						commit
						6fb56443a9
					
				|  | @ -9,66 +9,36 @@ def getframe(): | |||
|     return py.code.Frame(sys._getframe(1)) | ||||
| 
 | ||||
| 
 | ||||
| def setup_module(mod): | ||||
|     py.code.patch_builtins(assertion=True, compile=False) | ||||
| def pytest_funcarg__hook(request): | ||||
|     class MockHook(object): | ||||
|         def __init__(self): | ||||
|             self.called = False | ||||
|             self.args = tuple() | ||||
|             self.kwargs = dict() | ||||
| 
 | ||||
|         def __call__(self, op, left, right): | ||||
|             self.called = True | ||||
|             self.op = op | ||||
|             self.left = left | ||||
|             self.right = right | ||||
|     return MockHook() | ||||
| 
 | ||||
| 
 | ||||
| def teardown_module(mod): | ||||
|     py.code.unpatch_builtins(assertion=True, compile=False) | ||||
| def test_pytest_assert_compare_called(monkeypatch, hook): | ||||
|     monkeypatch.setattr(py._plugin.pytest_assertion, | ||||
|                         'pytest_assert_compare', hook) | ||||
|     interpret('assert 0 == 1', getframe()) | ||||
|     assert hook.called | ||||
| 
 | ||||
| 
 | ||||
| def test_assert_simple(): | ||||
|     # Simply test that this way of testing works | ||||
|     a = 0 | ||||
|     b = 1 | ||||
|     r = interpret('assert a == b', getframe()) | ||||
|     assert r == 'assert 0 == 1' | ||||
| 
 | ||||
| 
 | ||||
| def test_assert_list(): | ||||
|     r = interpret('assert [0, 1] == [0, 2]', getframe()) | ||||
|     msg = ('assert [0, 1] == [0, 2]\n' | ||||
|            '  First differing item 1: 1 != 2\n' | ||||
|            '  - [0, 1]\n' | ||||
|            '  ?     ^\n' | ||||
|            '  + [0, 2]\n' | ||||
|            '  ?     ^') | ||||
|     print r | ||||
|     assert r == msg | ||||
| 
 | ||||
| 
 | ||||
| def test_assert_string(): | ||||
|     r = interpret('assert "foo and bar" == "foo or bar"', getframe()) | ||||
|     msg = ("assert 'foo and bar' == 'foo or bar'\n" | ||||
|            "  - foo and bar\n" | ||||
|            "  ?     ^^^\n" | ||||
|            "  + foo or bar\n" | ||||
|            "  ?     ^^") | ||||
|     print r | ||||
|     assert r == msg | ||||
| 
 | ||||
| 
 | ||||
| def test_assert_multiline_string(): | ||||
|     a = 'foo\nand bar\nbaz' | ||||
|     b = 'foo\nor bar\nbaz' | ||||
|     r = interpret('assert a == b', getframe()) | ||||
|     msg = ("assert 'foo\\nand bar\\nbaz' == 'foo\\nor bar\\nbaz'\n" | ||||
|            '    foo\n' | ||||
|            '  - and bar\n' | ||||
|            '  + or bar\n' | ||||
|            '    baz') | ||||
|     print r | ||||
|     assert r == msg | ||||
| 
 | ||||
| 
 | ||||
| def test_assert_dict(): | ||||
|     a = {'a': 0, 'b': 1} | ||||
|     b = {'a': 0, 'c': 2} | ||||
|     r = interpret('assert a == b', getframe()) | ||||
|     msg = ("assert {'a': 0, 'b': 1} == {'a': 0, 'c': 2}\n" | ||||
|            "  - {'a': 0, 'b': 1}\n" | ||||
|            "  ?           ^   ^\n" | ||||
|            "  + {'a': 0, 'c': 2}\n" | ||||
|            "  ?           ^   ^") | ||||
|     print r | ||||
|     assert r == msg | ||||
| def test_pytest_assert_compare_args(monkeypatch, hook): | ||||
|     print hook.called | ||||
|     monkeypatch.setattr(py._plugin.pytest_assertion, | ||||
|                         'pytest_assert_compare', hook) | ||||
|     interpret('assert [0, 1] == [0, 2]', getframe()) | ||||
|     print hook.called | ||||
|     print hook.left | ||||
|     print hook.right | ||||
|     assert hook.op == '==' | ||||
|     assert hook.left == [0, 1] | ||||
|     assert hook.right == [0, 2] | ||||
|  |  | |||
|  | @ -1,3 +1,7 @@ | |||
| import py | ||||
| import py._plugin.pytest_assertion as plugin | ||||
| 
 | ||||
| 
 | ||||
| def test_functional(testdir): | ||||
|     testdir.makepyfile(""" | ||||
|         def test_hello(): | ||||
|  | @ -49,3 +53,31 @@ def test_traceback_failure(testdir): | |||
|         "*test_traceback_failure.py:4: AssertionError" | ||||
|     ]) | ||||
| 
 | ||||
| 
 | ||||
| class Test_pytest_assert_compare: | ||||
|     def test_different_types(self): | ||||
|         assert plugin.pytest_assert_compare('==', [0, 1], 'foo') is None | ||||
| 
 | ||||
|     def test_summary(self): | ||||
|         summary = plugin.pytest_assert_compare('==', [0, 1], [0, 2])[0] | ||||
|         assert len(summary) < 65 | ||||
| 
 | ||||
|     def test_text_diff(self): | ||||
|         diff = plugin.pytest_assert_compare('==', 'spam', 'eggs')[1:] | ||||
|         assert '- spam' in diff | ||||
|         assert '+ eggs' in diff | ||||
| 
 | ||||
|     def test_multiline_text_diff(self): | ||||
|         left = 'foo\nspam\nbar' | ||||
|         right = 'foo\neggs\nbar' | ||||
|         diff = plugin.pytest_assert_compare('==', left, right) | ||||
|         assert '- spam' in diff | ||||
|         assert '+ eggs' in diff | ||||
| 
 | ||||
|     def test_list(self): | ||||
|         expl = plugin.pytest_assert_compare('==', [0, 1], [0, 2]) | ||||
|         assert len(expl) > 1 | ||||
| 
 | ||||
|     def test_dict(self): | ||||
|         expl = plugin.pytest_assert_compare('==', {'a': 0}, {'a': 1}) | ||||
|         assert len(expl) > 1 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue