diff options
author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-11-11 00:00:00 +0000 |
---|---|---|
committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-11-13 08:51:30 +0100 |
commit | e69c3d40c5d46d18d231257037d5d85c24b0aaba (patch) | |
tree | 04b847d2fc03944fdeb06a56caa4e2290f10cd07 | |
parent | 25aca2e7c3c13b298290148cfd55ab426f1c68d4 (diff) | |
download | dconf-e69c3d40c5d46d18d231257037d5d85c24b0aaba.tar.gz |
tests: Add bash path completion tests
-rwxr-xr-x | tests/test-dconf.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test-dconf.py b/tests/test-dconf.py index bbb76f7..ab71124 100755 --- a/tests/test-dconf.py +++ b/tests/test-dconf.py @@ -73,6 +73,12 @@ def dconf_list(key): return dconf('list', key).stdout.splitlines() +def dconf_complete(suffix, prefix): + lines = dconf('_complete', suffix, prefix).stdout.splitlines() + lines.sort() + return lines + + def dconf_watch(path): args = [dconf_exe, 'watch', path] return subprocess.Popen(args, @@ -306,6 +312,64 @@ class DBusTest(unittest.TestCase): keyfile_com = dconf('dump', '/com/').stdout self.assertEqual(keyfile_org, keyfile_com) + def test_complete(self): + """Tests _complete command used internally to implement bash completion. + + Runs completion queries after loading a sample database from key-file. + """ + + keyfile = dedent('''\ + [org] + calamity=false + + [org/calculator] + window-position=(0, 0) + + [org/calendar] + window-position=(0, 0) + + [org/history] + file0='/tmp/a' + file1='/tmp/b' + file2='/tmp/c' + ''') + + dconf('load', '/', input=keyfile) + + # Empty string is completed to '/'. + completions = dconf_complete('', '') + self.assertEqual(completions, ['/']) + completions = dconf_complete('/', '') + self.assertEqual(completions, ['/']) + + # Invalid paths don't return any completions. + completions = dconf_complete('', 'foo/') + self.assertEqual(completions, []) + completions = dconf_complete('/', 'foo/') + self.assertEqual(completions, []) + + # Key completions include trailing whitespace, + # directory completions do not. + completions = dconf_complete('', '/org/') + self.assertEqual(completions, + ['/org/calamity ', + '/org/calculator/', + '/org/calendar/', + '/org/history/']) + + # Only matches with given prefix are returned. + completions = dconf_complete('', '/org/cal') + self.assertEqual(completions, + ['/org/calamity ', + '/org/calculator/', + '/org/calendar/']) + + # Only matches with given suffix are returned. + completions = dconf_complete('/', '/org/cal') + self.assertEqual(completions, + ['/org/calculator/', + '/org/calendar/']) + if __name__ == '__main__': # Make sure we don't pick up mandatory profile. |