test_completions.py 1.4 KB

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