Skip to content

Update unittests for 6.1#832

Open
GaryGriffin wants to merge 3 commits intomaintenance/gramps61from
GaryGriffin-unittest-61
Open

Update unittests for 6.1#832
GaryGriffin wants to merge 3 commits intomaintenance/gramps61from
GaryGriffin-unittest-61

Conversation

@GaryGriffin
Copy link
Copy Markdown
Member

Update to fix gramps_version (from 6.0 to 6.1) and add Gtk 3.0 check

Update to fix gramps_version and add Gtk 3.0 check
Copy link
Copy Markdown
Contributor

@eduralph eduralph left a comment

Choose a reason for hiding this comment

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

Thanks @GaryGriffin — picking up the import-order fix and adding the GTK-3 pin makes sense. One issue and one nit, both isolated to WebSearch/tests/test_filetable.py; the other five files look good.

WebSearch/tests/test_filetable.pyunittest referenced before import

In this file (only) the existing import unittest is removed from the top of the file and re-added several lines below the new gi.require_version block. Since the except branch raises unittest.SkipTest, this means a missing/incompatible gi makes the except branch crash with NameError: name 'unittest' is not defined instead of cleanly skipping the module:

"""docstring"""

# Comment...
try:
    import gi
    gi.require_version("Gtk", "3.0")
    gi.require_version("Gdk", "3.0")
except (ImportError, ValueError, AttributeError) as err:
    raise unittest.SkipTest("GTK 3.0 / PyGObject not available: %s" % err)
    #     ^^^^^^^^ NameError on the first failure path

import os

import sys
import unittest      # ← imported only here

Suggested fix — hoist import unittest above the try block (and keep it grouped with the other stdlib imports):

"""docstring"""

import os
import sys
import unittest

# Comment...
try:
    import gi

    gi.require_version("Gtk", "3.0")
    gi.require_version("Gdk", "3.0")
except (ImportError, ValueError, AttributeError) as err:
    raise unittest.SkipTest("GTK 3.0 / PyGObject not available: %s" % err)

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from models import DBFileTableConfig

The other five files (Sqlite/tests/test_sqlite.py, both TMGimporter/tests/*.py, CalculateEstimatedDates/..., DataEntryGramplet/...) all retain their original top-of-file import unittest, so they're not affected by this issue — only WebSearch needs the change.

Nit — comment misattribution

The comment block above the try reads:

The TMGimporter module imports Gtk at module load — skip the whole file if gi/Gtk aren't available …

This is WebSearch/tests/test_filetable.py, not TMGimporter. Looks like a copy-paste from one of the TMGimporter test files in the same PR. Either drop the "TMGimporter module" reference or rephrase to something like "WebSearch's test imports models/db_file_table which transitively …" if there's actually a GTK import path here (I couldn't find one — models.py/db_file_table.py/constants.py look gi-free, so the GTK-pin block may not even be needed for this file).

If the GTK pin block isn't needed in WebSearch, an alternative is to drop it entirely from this file and keep just the sys.path.insert prologue. Happy to leave that call to you.

@GaryGriffin
Copy link
Copy Markdown
Member Author

Thanks for the feedback. Fixed as you suggested.
The Gtk pin is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants