def test_cifloop_roundtrip(): loop = CIFLoop() loop.add('_potatoes', [2.5, 3.0, -1.0], '{:8.5f}') loop.add('_eggs', [1, 2, 3], '{:2d}') string = loop.tostring() + '\n' print('hmm', string) lines = string.splitlines()[::-1] assert lines.pop() == 'loop_' for line in lines: print(repr(line)) dct = parse_loop(lines) assert dct['_potatoes'] == pytest.approx([2.5, 3.0, -1.0]) assert dct['_eggs'] == [1, 2, 3]
def test_cifloop(): dct = {'_eggs': range(4), '_potatoes': [1.3, 7.1, -1, 0]} loop = CIFLoop() loop.add('_eggs', dct['_eggs'], '{:<2d}') loop.add('_potatoes', dct['_potatoes'], '{:.4f}') string = loop.tostring() + '\n\n' lines = string.splitlines()[::-1] assert lines.pop() == 'loop_' newdct = parse_loop(lines) print(newdct) assert set(dct) == set(newdct) for name in dct: assert dct[name] == pytest.approx(newdct[name])
def test_parse_cifloop_simple(): dct = parse_loop(['_apples', '_verysmallrocks', '2 200', '3 300', '4 400'][::-1]) assert dct['_apples'] == [2, 3, 4] assert dct['_verysmallrocks'] == [200, 300, 400]
def test_parse_cifloop_incomplete(): with pytest.raises(RuntimeError): parse_loop(['_spam', '_eggs', '1 2', '1'][::-1])
def test_parse_cifloop_warn_duplicate_header(): with pytest.warns(UserWarning): parse_loop(['_hello', '_hello'])