MCPcopy Index your code
hub / github.com/ipython/ipython / test_struct_array_key_completion

Method test_struct_array_key_completion

tests/test_completer.py:1684–1719  ·  view source on GitHub ↗

Test dict key completion applies to numpy struct arrays

(self)

Source from the content-addressed store, hash-verified

1682
1683 @dec.skip_without("numpy")
1684 def test_struct_array_key_completion(self):
1685 """Test dict key completion applies to numpy struct arrays"""
1686 import numpy
1687
1688 ip = get_ipython()
1689 complete = ip.Completer.complete
1690 ip.user_ns["d"] = numpy.array([], dtype=[("hello", "f"), ("world", "f")])
1691 _, matches = complete(line_buffer="d['")
1692 self.assertIn("hello", matches)
1693 self.assertIn("world", matches)
1694 # complete on the numpy struct itself
1695 dt = numpy.dtype(
1696 [("my_head", [("my_dt", ">u4"), ("my_df", ">u4")]), ("my_data", ">f4", 5)]
1697 )
1698 x = numpy.zeros(2, dtype=dt)
1699 ip.user_ns["d"] = x[1]
1700 _, matches = complete(line_buffer="d['")
1701 self.assertIn("my_head", matches)
1702 self.assertIn("my_data", matches)
1703
1704 def completes_on_nested():
1705 ip.user_ns["d"] = numpy.zeros(2, dtype=dt)
1706 _, matches = complete(line_buffer="d[1]['my_head']['")
1707 self.assertTrue(any(["my_dt" in m for m in matches]))
1708 self.assertTrue(any(["my_df" in m for m in matches]))
1709
1710 # complete on a nested level
1711 with greedy_completion():
1712 completes_on_nested()
1713
1714 with evaluation_policy("limited"):
1715 completes_on_nested()
1716
1717 with evaluation_policy("minimal"):
1718 with pytest.raises(AssertionError):
1719 completes_on_nested()
1720
1721 @dec.skip_without("pandas")
1722 def test_dataframe_key_completion(self):

Callers

nothing calls this directly

Calls 3

get_ipythonFunction · 0.90
greedy_completionFunction · 0.85
evaluation_policyFunction · 0.85

Tested by

no test coverage detected