From 8ce6c0f460f90561cf2e846c1b3fa281d11fba62 Mon Sep 17 00:00:00 2001 From: Jon Stutters Date: Thu, 27 Oct 2016 15:31:40 +0100 Subject: [PATCH] Add additional test of recorders when a return is captured --- tests/test_recorders.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_recorders.py b/tests/test_recorders.py index 3cd5ae9..7e3a665 100644 --- a/tests/test_recorders.py +++ b/tests/test_recorders.py @@ -16,6 +16,18 @@ def a_pipeline(): return a_pipeline +@pytest.fixture +def returning_pipeline(): + @record('value') + def recorded_function(): + return 5.12 + + def a_pipeline(): + recorded_function() + + return a_pipeline + + def test_csvfile(simple_pipeline, tmpdir): with tmpdir.as_cwd(): recorder = CSVFile( @@ -54,3 +66,23 @@ def test_stdout(simple_pipeline, tmpdir, capsys): ) out, err = capsys.readouterr() assert out == 'id: 1\ndata: 6.35\n' + + +def test_return_record(returning_pipeline, tmpdir): + with tmpdir.as_cwd(): + recorder = CSVFile( + 'test.csv', + OrderedDict([ + ('data', lambda x: x['processes'][0]['returned'][0].strip()) + ]) + ) + pipeline.run( + 'test', + returning_pipeline, + str(tmpdir), + metadata={'id': 1}, + recorder=recorder + ) + with open('test.csv') as f: + assert f.readline().strip() == 'data' + assert f.readline().strip() == '5.12'