gtg
gtg copied to clipboard
Write unit test for TaskView.get_title()
I started to look at #1077 and I thought it would be nice to be able to unit test this type of thing.
A simple unit test for TaskView would be
- create a task
- create a view for it
- check that the title of the view is the title of the task
In the current state of affairs, this is difficult because the code that puts the Task data into the view lives in TaskEditor. But we pass a Task to the constructor of TaskView, so TaskView actually has all the data it needs. So I moved the logic there. I also moved the is_new()
logic from the TaskEditor down to the Task.
I feel like it should be possible to eventually do this in the TaskView constructor but for now, TaskEditor calls self.textview.set_text_from_task()
from the same place it used to run that code.
Ugh okay, let's not merge that yet... GHA fails with "Fatal Python error: Segmentation fault", which is going to be a joy to debug.
OK so I have confirmed that this is caused by test_get_title()
- skipping it makes the tests green again. Trying Python 3.9 doesn't, and I've only seen it o GHA so far.
I think this is worth merging even though I haven't solved the segfault issue (it anyone wants to look: https://github.com/getting-things-gnome/gtg/actions/runs/8864137269/job/24339006474?pr=1083), and even though it looks like the bug I set out to fix will be fixed by #1102
I'll work on unskipping the test separately.
I managed to reproduce the segfault outside of the GitHub Action using a small server VM. The main problem seems to be that GA runs without any graphical display features, and the new GUI test wants to use these features. If you provide a fake display server, everything works fine:
xvfb-run python3 -m pytest
Thanks a lot for looking into it! That would have taken me a while to figure out.
It feels a bit like a hack somehow? But I can't really articulate why, nor do I have a better way to fix the problem =D
It feels a bit like a hack somehow? But I can't really articulate why, nor do I have a better way to fix the problem =D
I think we can defend the move:
- The test ensures that a GUI component is correctly displayed. Using a display server during the process sounds reasonable.
- Moreover, this would only change the GHA workflow without limiting anything else.
Hi @SqAtx, this LGTM. Is this ready to merge or is there something else to do in this branch?
@diegogangl It's ready to merge! It's a good first step.
Thanks!