gtg icon indicating copy to clipboard operation
gtg copied to clipboard

Write unit test for TaskView.get_title()

Open SqAtx opened this issue 10 months ago • 2 comments

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.

SqAtx avatar Apr 06 '24 23:04 SqAtx

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.

SqAtx avatar Apr 22 '24 01:04 SqAtx

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.

SqAtx avatar Apr 28 '24 01:04 SqAtx

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.

SqAtx avatar May 19 '24 00:05 SqAtx

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

gycsaba96 avatar May 20 '24 12:05 gycsaba96

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

SqAtx avatar May 25 '24 18:05 SqAtx

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.

gycsaba96 avatar May 26 '24 19:05 gycsaba96

Hi @SqAtx, this LGTM. Is this ready to merge or is there something else to do in this branch?

diegogangl avatar Jun 20 '24 21:06 diegogangl

@diegogangl It's ready to merge! It's a good first step.

SqAtx avatar Jun 27 '24 04:06 SqAtx

Thanks!

diegogangl avatar Jun 27 '24 12:06 diegogangl