Show More
@@ -445,8 +445,11 b' class HistoryAccessor(HistoryAccessorBase):' | |||||
445 | Parameters |
|
445 | Parameters | |
446 | ---------- |
|
446 | ---------- | |
447 | rangestr : str |
|
447 | rangestr : str | |
448 |
A string specifying ranges, e.g. "5 ~2/1-4". |
|
448 | A string specifying ranges, e.g. "5 ~2/1-4". If empty string is used, | |
449 | :func:`magic_history` for full details. |
|
449 | this will return everything from current session's history. | |
|
450 | ||||
|
451 | See the documentation of :func:`%history` for the full details. | |||
|
452 | ||||
450 | raw, output : bool |
|
453 | raw, output : bool | |
451 | As :meth:`get_range` |
|
454 | As :meth:`get_range` | |
452 |
|
455 | |||
@@ -851,11 +854,18 b' $""", re.VERBOSE)' | |||||
851 | def extract_hist_ranges(ranges_str): |
|
854 | def extract_hist_ranges(ranges_str): | |
852 | """Turn a string of history ranges into 3-tuples of (session, start, stop). |
|
855 | """Turn a string of history ranges into 3-tuples of (session, start, stop). | |
853 |
|
856 | |||
|
857 | Empty string results in a `[(0, 1, None)]`, i.e. "everything from current | |||
|
858 | session". | |||
|
859 | ||||
854 | Examples |
|
860 | Examples | |
855 | -------- |
|
861 | -------- | |
856 | >>> list(extract_hist_ranges("~8/5-~7/4 2")) |
|
862 | >>> list(extract_hist_ranges("~8/5-~7/4 2")) | |
857 | [(-8, 5, None), (-7, 1, 5), (0, 2, 3)] |
|
863 | [(-8, 5, None), (-7, 1, 5), (0, 2, 3)] | |
858 | """ |
|
864 | """ | |
|
865 | if ranges_str == '': | |||
|
866 | yield (0, 1, None) # Everything from current session | |||
|
867 | return | |||
|
868 | ||||
859 | for range_str in ranges_str.split(): |
|
869 | for range_str in ranges_str.split(): | |
860 | rmatch = range_re.match(range_str) |
|
870 | rmatch = range_re.match(range_str) | |
861 | if not rmatch: |
|
871 | if not rmatch: |
@@ -160,6 +160,14 b' def test_extract_hist_ranges():' | |||||
160 | actual = list(extract_hist_ranges(instr)) |
|
160 | actual = list(extract_hist_ranges(instr)) | |
161 | nt.assert_equal(actual, expected) |
|
161 | nt.assert_equal(actual, expected) | |
162 |
|
162 | |||
|
163 | ||||
|
164 | def test_extract_hist_ranges_empty_str(): | |||
|
165 | instr = '' | |||
|
166 | expected = [(0, 1, None)] # 0 == current session, None == to end | |||
|
167 | actual = list(extract_hist_ranges(instr)) | |||
|
168 | nt.assert_equal(actual, expected) | |||
|
169 | ||||
|
170 | ||||
163 | def test_magic_rerun(): |
|
171 | def test_magic_rerun(): | |
164 | """Simple test for %rerun (no args -> rerun last line)""" |
|
172 | """Simple test for %rerun (no args -> rerun last line)""" | |
165 | ip = get_ipython() |
|
173 | ip = get_ipython() |
General Comments 0
You need to be logged in to leave comments.
Login now