|
| 1 | +import re |
| 2 | +import pytest |
| 3 | + |
| 4 | +def test_foo(): |
| 5 | + |
| 6 | + ### Errors |
| 7 | + |
| 8 | + with pytest.raises(FooAtTheEnd, match="foo."): ... |
| 9 | + with pytest.raises(PackageExtraSpecifier, match="Install `foo[bar]` to enjoy all features"): ... |
| 10 | + with pytest.raises(InnocentQuestion, match="Did you mean to use `Literal` instead?"): ... |
| 11 | + |
| 12 | + with pytest.raises(StringConcatenation, match="Huh" |
| 13 | + "?"): ... |
| 14 | + with pytest.raises(ManuallyEscapedWindowsPathToDotFile, match="C:\\\\Users\\\\Foo\\\\.config"): ... |
| 15 | + |
| 16 | + with pytest.raises(MiddleDot, match="foo.bar"): ... |
| 17 | + with pytest.raises(EndDot, match="foobar."): ... |
| 18 | + with pytest.raises(EscapedFollowedByUnescaped, match="foo\\.*bar"): ... |
| 19 | + with pytest.raises(UnescapedFollowedByEscaped, match="foo.\\*bar"): ... |
| 20 | + |
| 21 | + |
| 22 | + ## Metasequences |
| 23 | + |
| 24 | + with pytest.raises(StartOfInput, match="foo\\Abar"): ... |
| 25 | + with pytest.raises(WordBoundary, match="foo\\bbar"): ... |
| 26 | + with pytest.raises(NonWordBoundary, match="foo\\Bbar"): ... |
| 27 | + with pytest.raises(Digit, match="foo\\dbar"): ... |
| 28 | + with pytest.raises(NonDigit, match="foo\\Dbar"): ... |
| 29 | + with pytest.raises(Whitespace, match="foo\\sbar"): ... |
| 30 | + with pytest.raises(NonWhitespace, match="foo\\Sbar"): ... |
| 31 | + with pytest.raises(WordCharacter, match="foo\\wbar"): ... |
| 32 | + with pytest.raises(NonWordCharacter, match="foo\\Wbar"): ... |
| 33 | + with pytest.raises(EndOfInput, match="foo\\zbar"): ... |
| 34 | + |
| 35 | + with pytest.raises(StartOfInput2, match="foobar\\A"): ... |
| 36 | + with pytest.raises(WordBoundary2, match="foobar\\b"): ... |
| 37 | + with pytest.raises(NonWordBoundary2, match="foobar\\B"): ... |
| 38 | + with pytest.raises(Digit2, match="foobar\\d"): ... |
| 39 | + with pytest.raises(NonDigit2, match="foobar\\D"): ... |
| 40 | + with pytest.raises(Whitespace2, match="foobar\\s"): ... |
| 41 | + with pytest.raises(NonWhitespace2, match="foobar\\S"): ... |
| 42 | + with pytest.raises(WordCharacter2, match="foobar\\w"): ... |
| 43 | + with pytest.raises(NonWordCharacter2, match="foobar\\W"): ... |
| 44 | + with pytest.raises(EndOfInput2, match="foobar\\z"): ... |
| 45 | + |
| 46 | + |
| 47 | + ### Acceptable false positives |
| 48 | + |
| 49 | + with pytest.raises(NameEscape, match="\\N{EN DASH}"): ... |
| 50 | + |
| 51 | + |
| 52 | + ### No errors |
| 53 | + |
| 54 | + with pytest.raises(NoMatch): ... |
| 55 | + with pytest.raises(NonLiteral, match=pattern): ... |
| 56 | + with pytest.raises(FunctionCall, match=frobnicate("qux")): ... |
| 57 | + with pytest.raises(ReEscaped, match=re.escape("foobar")): ... |
| 58 | + with pytest.raises(RawString, match=r"fo()bar"): ... |
| 59 | + with pytest.raises(RawStringPart, match=r"foo" '\bar'): ... |
| 60 | + with pytest.raises(NoMetacharacters, match="foobar"): ... |
| 61 | + with pytest.raises(EndBackslash, match="foobar\\"): ... |
| 62 | + |
| 63 | + with pytest.raises(ManuallyEscaped, match="some\\.fully\\.qualified\\.name"): ... |
| 64 | + with pytest.raises(ManuallyEscapedWindowsPath, match="C:\\\\Users\\\\Foo\\\\file\\.py"): ... |
| 65 | + |
| 66 | + with pytest.raises(MiddleEscapedDot, match="foo\\.bar"): ... |
| 67 | + with pytest.raises(MiddleEscapedBackslash, match="foo\\\\bar"): ... |
| 68 | + with pytest.raises(EndEscapedDot, match="foobar\\."): ... |
| 69 | + with pytest.raises(EndEscapedBackslash, match="foobar\\\\"): ... |
| 70 | + |
| 71 | + |
| 72 | + ## Not-so-special metasequences |
| 73 | + |
| 74 | + with pytest.raises(Alert, match="\\f"): ... |
| 75 | + with pytest.raises(FormFeed, match="\\f"): ... |
| 76 | + with pytest.raises(Newline, match="\\n"): ... |
| 77 | + with pytest.raises(CarriageReturn, match="\\r"): ... |
| 78 | + with pytest.raises(Tab, match="\\t"): ... |
| 79 | + with pytest.raises(VerticalTab, match="\\v"): ... |
| 80 | + with pytest.raises(HexEscape, match="\\xFF"): ... |
| 81 | + with pytest.raises(_16BitUnicodeEscape, match="\\FFFF"): ... |
| 82 | + with pytest.raises(_32BitUnicodeEscape, match="\\0010FFFF"): ... |
| 83 | + |
| 84 | + ## Escaped metasequences |
| 85 | + |
| 86 | + with pytest.raises(Whitespace, match="foo\\\\sbar"): ... |
| 87 | + with pytest.raises(NonWhitespace, match="foo\\\\Sbar"): ... |
| 88 | + |
| 89 | + ## Work by accident |
| 90 | + |
| 91 | + with pytest.raises(OctalEscape, match="\\042"): ... |
0 commit comments