|
| 1 | +import distutils.dist |
| 2 | + |
| 3 | +import mock |
| 4 | + |
| 5 | +import readme_renderer.integration.distutils |
| 6 | + |
| 7 | + |
| 8 | +def test_valid_rst(): |
| 9 | + dist = distutils.dist.Distribution(attrs=dict( |
| 10 | + long_description="Hello, I am some text.")) |
| 11 | + checker = readme_renderer.integration.distutils.Check(dist) |
| 12 | + checker.warn = mock.Mock() |
| 13 | + |
| 14 | + checker.check_restructuredtext() |
| 15 | + |
| 16 | + checker.warn.assert_not_called() |
| 17 | + |
| 18 | + |
| 19 | +def test_invalid_rst(): |
| 20 | + dist = distutils.dist.Distribution(attrs=dict( |
| 21 | + long_description="Hello, I am some `totally borked< text.")) |
| 22 | + checker = readme_renderer.integration.distutils.Check(dist) |
| 23 | + checker.warn = mock.Mock() |
| 24 | + |
| 25 | + checker.check_restructuredtext() |
| 26 | + |
| 27 | + # Should warn once for the syntax error, and finally to warn that the |
| 28 | + # overall syntax is invalid |
| 29 | + checker.warn.call_count = 2 |
| 30 | + message_one = checker.warn.call_args_list[0][0][0] |
| 31 | + assert 'start-string without end-string' in message_one |
| 32 | + message_two = checker.warn.call_args_list[1][0][0] |
| 33 | + assert 'invalid markup' in message_two |
| 34 | + |
| 35 | + |
| 36 | +def test_invalid_missing(): |
| 37 | + dist = distutils.dist.Distribution(attrs=dict()) |
| 38 | + checker = readme_renderer.integration.distutils.Check(dist) |
| 39 | + checker.warn = mock.Mock() |
| 40 | + |
| 41 | + checker.check_restructuredtext() |
| 42 | + |
| 43 | + checker.warn.assert_called_once_with(mock.ANY) |
| 44 | + assert 'missing' in checker.warn.call_args[0][0] |
| 45 | + |
| 46 | + |
| 47 | +def test_invalid_empty(): |
| 48 | + dist = distutils.dist.Distribution(attrs=dict( |
| 49 | + long_description="")) |
| 50 | + checker = readme_renderer.integration.distutils.Check(dist) |
| 51 | + checker.warn = mock.Mock() |
| 52 | + |
| 53 | + checker.check_restructuredtext() |
| 54 | + |
| 55 | + checker.warn.assert_called_once_with(mock.ANY) |
| 56 | + assert 'missing' in checker.warn.call_args[0][0] |
0 commit comments