|
13 | 13 | import xmlrunner |
14 | 14 | from xmlrunner.result import _DuplicateWriter |
15 | 15 | from xmlrunner.result import _XMLTestResult |
| 16 | +from xmlrunner.result import resolve_filename |
16 | 17 | import doctest |
17 | 18 | import tests.doctest_example |
18 | 19 | from io import StringIO, BytesIO |
@@ -964,3 +965,23 @@ def test_xmlrunner_output_file(self, exiter, testrunner, opener): |
964 | 965 |
|
965 | 966 | testrunner.assert_called_once_with(**kwargs) |
966 | 967 | exiter.assert_called_once_with(False) |
| 968 | + |
| 969 | + |
| 970 | +class ResolveFilenameTestCase(unittest.TestCase): |
| 971 | + @mock.patch('os.path.relpath') |
| 972 | + def test_resolve_filename_relative(self, relpath): |
| 973 | + relpath.return_value = 'somefile.py' |
| 974 | + filename = resolve_filename('/path/to/somefile.py') |
| 975 | + self.assertEqual(filename, 'somefile.py') |
| 976 | + |
| 977 | + @mock.patch('os.path.relpath') |
| 978 | + def test_resolve_filename_outside(self, relpath): |
| 979 | + relpath.return_value = '../../../tmp/somefile.py' |
| 980 | + filename = resolve_filename('/tmp/somefile.py') |
| 981 | + self.assertEqual(filename, '/tmp/somefile.py') |
| 982 | + |
| 983 | + @mock.patch('os.path.relpath') |
| 984 | + def test_resolve_filename_error(self, relpath): |
| 985 | + relpath.side_effect = ValueError("ValueError: path is on mount 'C:', start on mount 'D:'") |
| 986 | + filename = resolve_filename('C:\\path\\to\\somefile.py') |
| 987 | + self.assertEqual(filename, 'C:\\path\\to\\somefile.py') |
0 commit comments