Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write unit test for TaskView.get_title() #1083

Merged

Conversation

SqAtx
Copy link
Contributor

@SqAtx SqAtx commented Apr 6, 2024

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.

The test triggers a segmentation fault when running on GitHub Actions, so it's skipped there while I figure out why.

@nekohayo nekohayo added the maintainability Automated tests suite, tooling, refactoring, or anything that makes it easier for developers label Apr 19, 2024
@SqAtx SqAtx force-pushed the write_test_for_taskview branch 3 times, most recently from dd7654a to a05a1a1 Compare April 22, 2024 01:27
text = self.task.content
title = self.task.title

# Insert text and tags as a non_undoable action, otherwise
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code has moved to the TaskView class. The logic hasn't changed besides the way the objects are named (self.insert() instead of self.textview.insert() etc) and the fact that the TextView calls is_new() on the task object.

def test_get_title(self):
task_title = 'Very important task'
task = Task(id = uuid4(), title=task_title)
view = TaskView(Datastore(), task, None, False)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 lines can probably be encapsulated into a create_task_view_from_task() test helper, but I can do that when I add another test.

@SqAtx SqAtx marked this pull request as ready for review April 22, 2024 01:37
@SqAtx
Copy link
Contributor Author

SqAtx commented Apr 22, 2024

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 SqAtx marked this pull request as draft April 28, 2024 01:35
@SqAtx
Copy link
Contributor Author

SqAtx commented Apr 28, 2024

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 SqAtx force-pushed the write_test_for_taskview branch 2 times, most recently from de7cb07 to 5cb9d90 Compare May 19, 2024 00:22
@SqAtx
Copy link
Contributor Author

SqAtx commented May 19, 2024

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 SqAtx marked this pull request as ready for review May 19, 2024 00:25
@gycsaba96
Copy link
Contributor

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

@SqAtx
Copy link
Contributor Author

SqAtx commented May 25, 2024

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

@gycsaba96
Copy link
Contributor

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.

I started to look at getting-things-gnome#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.

The test triggers a segmentation fault when running on GitHub Actions,
so it's skipped there while I figure out why.
@diegogangl
Copy link
Contributor

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

@SqAtx
Copy link
Contributor Author

SqAtx commented Jun 27, 2024

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

@diegogangl diegogangl merged commit 2f66ac5 into getting-things-gnome:master Jun 27, 2024
1 check passed
@diegogangl
Copy link
Contributor

Thanks!

@SqAtx SqAtx deleted the write_test_for_taskview branch June 29, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainability Automated tests suite, tooling, refactoring, or anything that makes it easier for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants