mesh-adaptation / goalie

Goal-oriented error estimation and mesh adaptation for finite element problems solved using Firedrake
Other
2 stars 0 forks source link

Use `sed` instead of `GOALIE_REGRESSION_TEST` #175

Closed jwallwork23 closed 4 months ago

jwallwork23 commented 5 months ago

Rather than confusing the demo content with environment variables, we should apply specific modifications with sed when running the test suite.

ddundo commented 4 months ago

You mentioned on the meeting that you don't really like the use of sed here. How about this instead:

demo.py:

end_time = 2000.0
print("end time", end_time)

test_demo.py

def test_demo(capsys):
    with open('demo.py', 'r') as file:
        demo_content = file.read()

    modified_demo_content = demo_content.replace('end_time = 2000.0', 'end_time = 10.0')
    exec(modified_demo_content)

    # Capture the print output to check that it worked
    captured = capsys.readouterr()
    assert "end time 10.0" in captured.out

Essentially the same thing, but more flexible and avoids changing the original script (I guess we'd have to create a copy of the script before using sed).

jwallwork23 commented 4 months ago

Nice! Yes, that's much more Pythonic and would be a better approach.