def test_flatten_recursion_error(): """ Test the flatten function for reference cycle detection """ data = [1, 2, 3, [4]] data.append(data) with pytest.raises(RecursionError) as err: salt.utils.data.flatten(data) assert str(err.value) == "Reference cycle detected. Check input list."
def _xfs_inventory_output(out): ''' Transform xfsrestore inventory data output to a Python dict source and evaluate it. ''' data = [] out = [line for line in out.split("\n") if line.strip()] # No inventory yet if len(out) == 1 and 'restore status' in out[0].lower(): return {'restore_status': out[0]} ident = 0 data.append("{") for line in out[:-1]: if len([elm for elm in line.strip().split(":") if elm]) == 1: n_ident = len(re.sub("[^\t]", "", line)) if ident > n_ident: for step in range(ident): data.append("},") ident = n_ident data.append(_xr_to_keyset(line)) data.append("{") else: data.append(_xr_to_keyset(line)) for step in range(ident + 1): data.append("},") data.append("},") # We are evaling into a python dict, a json load # would be safer data = eval('\n'.join(data))[0] # pylint: disable=W0123 data['restore_status'] = out[-1] return data