|
1 | 1 | import datetime |
2 | 2 | import os |
| 3 | +import re |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 |
|
@@ -69,22 +70,34 @@ def test_can_test_for_relative_path(): |
69 | 70 | assert_relative_path("foo.txt", "file") |
70 | 71 | assert_relative_path("dir/foo.txt", "file") |
71 | 72 |
|
72 | | - with pytest.raises( |
73 | | - Exception, match="Expected file path '/foo.txt' to be a relative path" |
74 | | - ): |
| 73 | + msg = "Expected file path '/foo.txt' to be a relative path" |
| 74 | + with pytest.raises(Exception, match=re.escape(msg)): |
75 | 75 | assert_relative_path("/foo.txt", "file") |
76 | 76 |
|
77 | | - with pytest.raises( |
78 | | - Exception, match="Path '../foo.txt' must not contain '..' component" |
79 | | - ): |
| 77 | + msg = "Path '../foo.txt' must not contain '..' component" |
| 78 | + with pytest.raises(Exception, match=re.escape(msg)): |
80 | 79 | assert_relative_path("../foo.txt", "file") |
81 | 80 |
|
82 | | - with pytest.raises( |
83 | | - Exception, match="Path 'aa/../foo.txt' must not contain '..' component" |
84 | | - ): |
| 81 | + msg = "Path 'aa/../foo.txt' must not contain '..' component" |
| 82 | + with pytest.raises(Exception, match=re.escape(msg)): |
85 | 83 | assert_relative_path("aa/../foo.txt", "file") |
86 | 84 |
|
87 | 85 |
|
| 86 | +@pytest.mark.skipif(os.name != "nt", reason="Windows-specific test") |
| 87 | +def test_can_test_for_relative_path_windows(): |
| 88 | + msg = "Expected file path 'C:\\aa\\foo.txt' to be a relative path" |
| 89 | + with pytest.raises(Exception, match=re.escape(msg)): |
| 90 | + assert_relative_path("C:\\aa\\foo.txt", "file") |
| 91 | + |
| 92 | + msg = "Expected file path 'C:foo.txt' to be a relative path" |
| 93 | + with pytest.raises(Exception, match=re.escape(msg)): |
| 94 | + assert_relative_path("C:foo.txt", "file") |
| 95 | + |
| 96 | + msg = "Expected file path '\\aa\\foo.txt' to be a relative path" |
| 97 | + with pytest.raises(Exception, match=re.escape(msg)): |
| 98 | + assert_relative_path("\\aa\\foo.txt", "file") |
| 99 | + |
| 100 | + |
88 | 101 | def test_all_normal_files_recurses(tmp_path): |
89 | 102 | helpers.touch_files( |
90 | 103 | tmp_path / "foo.txt", |
|
0 commit comments