1from .common import TestCase
2
3
4class TestCompletions(TestCase):
5
6    def test_group_completions(self):
7        # Test completions on top-level file.
8        g = self.f.create_group('g')
9        self.f.create_group('h')
10        self.f.create_dataset('data', [1, 2, 3])
11        self.assertEqual(
12            self.f._ipython_key_completions_(),
13            ['data', 'g', 'h'],
14        )
15
16        self.f.create_group('data2', [1, 2, 3])
17        self.assertEqual(
18            self.f._ipython_key_completions_(),
19            ['data', 'data2', 'g', 'h'],
20        )
21
22        # Test on subgroup.
23        g.create_dataset('g_data1', [1, 2, 3])
24        g.create_dataset('g_data2', [4, 5, 6])
25        self.assertEqual(
26            g._ipython_key_completions_(),
27            ['g_data1', 'g_data2'],
28        )
29
30        g.create_dataset('g_data3', [7, 8, 9])
31        self.assertEqual(
32            g._ipython_key_completions_(),
33            ['g_data1', 'g_data2', 'g_data3'],
34        )
35
36    def test_attrs_completions(self):
37        attrs = self.f.attrs
38
39        # Write out of alphabetical order to test that completions come back in
40        # alphabetical order, as opposed to, say, insertion order.
41        attrs['b'] = 1
42        attrs['a'] = 2
43        self.assertEqual(
44            attrs._ipython_key_completions_(),
45            ['a', 'b']
46        )
47
48        attrs['c'] = 3
49        self.assertEqual(
50            attrs._ipython_key_completions_(),
51            ['a', 'b', 'c']
52        )
53