|
3 | 3 | import varlink |
4 | 4 |
|
5 | 5 |
|
6 | | -def assert_invalid_description_raises(description: str) -> None: |
7 | | - with pytest.raises(SyntaxError): |
8 | | - varlink.Interface(description) |
9 | | - |
10 | | - |
11 | 6 | def test_scanner_1() -> None: |
12 | 7 | interface = varlink.Interface("""# Example Varlink service |
13 | 8 | interface org.example.more |
@@ -89,37 +84,50 @@ def test_complex() -> None: |
89 | 84 | assert isinstance(interface.members.get("TypeEnum"), varlink.scanner._Alias) |
90 | 85 |
|
91 | 86 |
|
92 | | -def test_interfacename() -> None: |
93 | | - assert_invalid_description_raises("interface .a.b.c\nmethod F()->()") |
94 | | - assert_invalid_description_raises("interface com.-example.leadinghyphen\nmethod F()->()") |
95 | | - assert_invalid_description_raises("interface com.example-.danglinghyphen-\nmethod F()->()") |
96 | | - assert_invalid_description_raises("interface co9.example.number-toplevel\nmethod F()->()") |
97 | | - assert_invalid_description_raises("interface 1om.example.number-toplevel\nmethod F()->()") |
98 | | - assert_invalid_description_raises("interface ab\nmethod F()->()") |
99 | | - assert_invalid_description_raises("interface .a.b.c\nmethod F()->()") |
100 | | - assert_invalid_description_raises("interface a.b.c.\nmethod F()->()") |
101 | | - assert_invalid_description_raises("interface a..b.c\nmethod F()->()") |
102 | | - assert_invalid_description_raises("interface 1.b.c\nmethod F()->()") |
103 | | - assert_invalid_description_raises("interface 8a.0.0\nmethod F()->()") |
104 | | - assert_invalid_description_raises("interface -a.b.c\nmethod F()->()") |
105 | | - assert_invalid_description_raises("interface a.b.c-\nmethod F()->()") |
106 | | - assert_invalid_description_raises("interface a.b-.c-\nmethod F()->()") |
107 | | - assert_invalid_description_raises("interface a.-b.c-\nmethod F()->()") |
108 | | - assert_invalid_description_raises("interface a.-.c\nmethod F()->()") |
109 | | - assert_invalid_description_raises("interface a.*.c\nmethod F()->()") |
110 | | - assert_invalid_description_raises("interface a.?\nmethod F()->()") |
111 | | - |
112 | | - assert varlink.Interface("interface a.b\nmethod F()->()").name is not None |
113 | | - assert varlink.Interface("interface a.b.c\nmethod F()->()").name is not None |
114 | | - assert varlink.Interface("interface a.1\nmethod F()->()").name is not None |
115 | | - assert varlink.Interface("interface a.0.0\nmethod F()->()").name is not None |
116 | | - assert varlink.Interface("interface org.varlink.service\nmethod F()->()").name is not None |
117 | | - assert varlink.Interface("interface com.example.0example\nmethod F()->()").name is not None |
118 | | - assert varlink.Interface("interface com.example.example-dash\nmethod F()->()").name is not None |
119 | | - assert varlink.Interface("interface xn--lgbbat1ad8j.example.algeria\nmethod F()->()").name is not None |
120 | | - assert ( |
121 | | - varlink.Interface("interface xn--c1yn36f.xn--c1yn36f.xn--c1yn36f\nmethod F()->()").name is not None |
122 | | - ) |
| 87 | +invalid_interfacenames = [ |
| 88 | + "interface .a.b.c\nmethod F()->()", |
| 89 | + "interface com.-example.leadinghyphen\nmethod F()->()", |
| 90 | + "interface com.example-.danglinghyphen-\nmethod F()->()", |
| 91 | + "interface co9.example.number-toplevel\nmethod F()->()", |
| 92 | + "interface 1om.example.number-toplevel\nmethod F()->()", |
| 93 | + "interface ab\nmethod F()->()", |
| 94 | + "interface .a.b.c\nmethod F()->()", |
| 95 | + "interface a.b.c.\nmethod F()->()", |
| 96 | + "interface a..b.c\nmethod F()->()", |
| 97 | + "interface 1.b.c\nmethod F()->()", |
| 98 | + "interface 8a.0.0\nmethod F()->()", |
| 99 | + "interface -a.b.c\nmethod F()->()", |
| 100 | + "interface a.b.c-\nmethod F()->()", |
| 101 | + "interface a.b-.c-\nmethod F()->()", |
| 102 | + "interface a.-b.c-\nmethod F()->()", |
| 103 | + "interface a.-.c\nmethod F()->()", |
| 104 | + "interface a.*.c\nmethod F()->()", |
| 105 | + "interface a.?\nmethod F()->()", |
| 106 | +] |
| 107 | + |
| 108 | + |
| 109 | +@pytest.mark.parametrize("description", invalid_interfacenames) |
| 110 | +def test_interfacename_invalid(description) -> None: |
| 111 | + with pytest.raises(SyntaxError): |
| 112 | + varlink.Interface(description) |
| 113 | + |
| 114 | + |
| 115 | +valid_interfacenames = [ |
| 116 | + "interface a.b\nmethod F()->()", |
| 117 | + "interface a.b.c\nmethod F()->()", |
| 118 | + "interface a.1\nmethod F()->()", |
| 119 | + "interface a.0.0\nmethod F()->()", |
| 120 | + "interface org.varlink.service\nmethod F()->()", |
| 121 | + "interface com.example.0example\nmethod F()->()", |
| 122 | + "interface com.example.example-dash\nmethod F()->()", |
| 123 | + "interface xn--lgbbat1ad8j.example.algeria\nmethod F()->()", |
| 124 | + "interface xn--c1yn36f.xn--c1yn36f.xn--c1yn36f\nmethod F()->()", |
| 125 | +] |
| 126 | + |
| 127 | + |
| 128 | +@pytest.mark.parametrize("description", valid_interfacenames) |
| 129 | +def test_interfacename_valid(description) -> None: |
| 130 | + assert varlink.Interface(description).name is not None |
123 | 131 |
|
124 | 132 |
|
125 | 133 | def test_bad_types() -> None: |
|
0 commit comments