| 75 | |
| 76 | |
| 77 | def test_load_path(tmpdir): |
| 78 | dst = str(tmpdir.join("conf")) |
| 79 | |
| 80 | with taddons.context() as tctx: |
| 81 | kmc = keymap.KeymapConfig(tctx.master) |
| 82 | km = keymap.Keymap(tctx.master) |
| 83 | tctx.master.keymap = km |
| 84 | |
| 85 | with open(dst, "wb") as f: |
| 86 | f.write(b"\xff\xff\xff") |
| 87 | with pytest.raises(keymap.KeyBindingError, match="expected UTF8"): |
| 88 | kmc.load_path(km, dst) |
| 89 | |
| 90 | with open(dst, "w") as f: |
| 91 | f.write("'''") |
| 92 | with pytest.raises(keymap.KeyBindingError): |
| 93 | kmc.load_path(km, dst) |
| 94 | |
| 95 | with open(dst, "w") as f: |
| 96 | f.write( |
| 97 | """ |
| 98 | - key: key1 |
| 99 | ctx: [unknown] |
| 100 | cmd: > |
| 101 | foo bar |
| 102 | foo bar |
| 103 | """ |
| 104 | ) |
| 105 | with pytest.raises(keymap.KeyBindingError): |
| 106 | kmc.load_path(km, dst) |
| 107 | |
| 108 | with open(dst, "w") as f: |
| 109 | f.write( |
| 110 | """ |
| 111 | - key: key1 |
| 112 | ctx: [chooser] |
| 113 | help: one |
| 114 | cmd: > |
| 115 | foo bar |
| 116 | foo bar |
| 117 | """ |
| 118 | ) |
| 119 | kmc.load_path(km, dst) |
| 120 | assert km.get("chooser", "key1") |
| 121 | |
| 122 | with open(dst, "w") as f: |
| 123 | f.write( |
| 124 | """ |
| 125 | - key: key2 |
| 126 | ctx: [flowlist] |
| 127 | cmd: foo |
| 128 | - key: key2 |
| 129 | ctx: [flowview] |
| 130 | cmd: bar |
| 131 | """ |
| 132 | ) |
| 133 | kmc.load_path(km, dst) |
| 134 | assert km.get("flowlist", "key2") |