[dconf: 3/6] tests: Add bash path completion tests



commit e69c3d40c5d46d18d231257037d5d85c24b0aaba
Author: Tomasz Miąsko <tomasz miasko gmail com>
Date:   Sun Nov 11 00:00:00 2018 +0000

    tests: Add bash path completion tests

 tests/test-dconf.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
---
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.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]