| 150 | |
| 151 | |
| 152 | def test_parse(): |
| 153 | with taddons.context() as tctx: |
| 154 | kmc = keymap.KeymapConfig(tctx.master) |
| 155 | assert kmc.parse("") == [] |
| 156 | assert kmc.parse("\n\n\n \n") == [] |
| 157 | with pytest.raises(keymap.KeyBindingError, match="expected a list of keys"): |
| 158 | kmc.parse("key: val") |
| 159 | with pytest.raises(keymap.KeyBindingError, match="expected a list of keys"): |
| 160 | kmc.parse("val") |
| 161 | with pytest.raises(keymap.KeyBindingError, match="Unknown key attributes"): |
| 162 | kmc.parse( |
| 163 | """ |
| 164 | - key: key1 |
| 165 | nonexistent: bar |
| 166 | """ |
| 167 | ) |
| 168 | with pytest.raises( |
| 169 | keymap.KeyBindingError, match="Missing required key attributes" |
| 170 | ): |
| 171 | kmc.parse( |
| 172 | """ |
| 173 | - help: key1 |
| 174 | """ |
| 175 | ) |
| 176 | with pytest.raises(keymap.KeyBindingError, match="Invalid type for cmd"): |
| 177 | kmc.parse( |
| 178 | """ |
| 179 | - key: key1 |
| 180 | cmd: [ cmd ] |
| 181 | """ |
| 182 | ) |
| 183 | with pytest.raises(keymap.KeyBindingError, match="Invalid type for ctx"): |
| 184 | kmc.parse( |
| 185 | """ |
| 186 | - key: key1 |
| 187 | ctx: foo |
| 188 | cmd: cmd |
| 189 | """ |
| 190 | ) |
| 191 | assert kmc.parse( |
| 192 | """ |
| 193 | - key: key1 |
| 194 | ctx: [one, two] |
| 195 | help: one |
| 196 | cmd: > |
| 197 | foo bar |
| 198 | foo bar |
| 199 | """ |
| 200 | ) == [ |
| 201 | { |
| 202 | "key": "key1", |
| 203 | "ctx": ["one", "two"], |
| 204 | "help": "one", |
| 205 | "cmd": "foo bar foo bar\n", |
| 206 | } |
| 207 | ] |