Skip to content

App module handler/does app mod exists: return false when called before imports are initialized #9800

Merged
michaelDCurran merged 2 commits into
nvaccess:threshold_py3_stagingfrom
josephsl:i9797appModExistsException
Jun 25, 2019
Merged

App module handler/does app mod exists: return false when called before imports are initialized #9800
michaelDCurran merged 2 commits into
nvaccess:threshold_py3_stagingfrom
josephsl:i9797appModExistsException

Conversation

@josephsl

Copy link
Copy Markdown
Contributor

Link to issue number:

Fixes #9797

Summary of the issue:

Attribute error is thrown if doesAppModuleExist function is invoked from system tests in Python 3.

Description of how this pull request fixes the issue:

When invoked from system tests under Python 3, app module handler will not be initialized, leaving importers (a private list) as None. By the time does app module exists function is called, this will return an attribute error. Thus return False if this happens.

Testing performed:

Tested with Python 2 and 3 source copies.

Known issues with pull request:

None

Change log entry:

None

Additional context:

This PR is part of an overall PR series on system tests.

Thanks.

…ume there is no app module for desktop object if invokved from system tests in Python 3. Re nvaccess#9797.

When invoked from system tests under Python 3, app module handler will not be initialized, leaving importers (a private list) as None. By the time does app module exists function is called, this will return an attribute error. Thus return False if this happens.
@josephsl josephsl requested a review from michaelDCurran June 24, 2019 05:09
Comment thread source/appModuleHandler.py Outdated
def doesAppModuleExist(name):
return any(importer.find_module("appModules.%s" % name) for importer in _importers)
# #9797: when invoked from system tests, importers list isn't initialized (attribute error on a None object), thus assume no app module exists.
try:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I would prefer just to check if _importers is None and return False, rather than letting it knowingly fail.
Though I'd like to also understand why systemTestSpy actually causes doesAppModule exist to be called? can you provide an example traceback on the issue?

@josephsl

Copy link
Copy Markdown
Contributor Author

Hi,

Traceback:

DEBUG - core.main (07:55:15.904):
Initializing displayModel
DEBUG - core.main (07:55:15.904):
Initializing GUI
CRITICAL - external:main (07:55:16.000):
core failure
Traceback (most recent call last):
File "D:\nvda\code\nvda\source/nvda.pyw", line 221, in
core.main()
File "core.py", line 414, in main
desktopObject=NVDAObjects.window.Window(windowHandle=winUser.getDesktopWindow())
File "NVDAObjects_init_.py", line 89, in call
appModule=obj.appModule
File "baseObject.py", line 46, in get
return instance._getPropertyViaCache(self.fget)
File "baseObject.py", line 149, in getPropertyViaCache
val=getterMethod(self)
File "NVDAObjects_init
.py", line 385, in _get_appModule
a=appModuleHandler.getAppModuleForNVDAObject(self)
File "appModuleHandler.py", line 105, in getAppModuleForNVDAObject
return getAppModuleFromProcessID(obj.processID)
File "appModuleHandler.py", line 119, in getAppModuleFromProcessID
mod=fetchAppModule(processID,appName)
File "appModuleHandler.py", line 171, in fetchAppModule
if doesAppModuleExist(modName):
File "appModuleHandler.py", line 156, in doesAppModuleExist
return any(importer.find_module("appModules.%s" % name) for importer in _importers)
File "appModuleHandler.py", line 156, in
return any(importer.find_module("appModules.%s" % name) for importer in _importers)
AttributeError: 'NoneType' object has no attribute 'find_module'

Thanks.

…not set. Re nvaccess#9797.

Reviewed by Mick Curran (NV Access): instead of using a try block, let NVDA say there is no app module if importers list isn't set, seen when invoking this function from system tests.
@michaelDCurran michaelDCurran changed the title App module handler/does app mod exists: catch attribute error and assume no app module exists for the app name App module handler/does app mod exists: return false when called before imports are initialized Jun 25, 2019
@michaelDCurran michaelDCurran merged commit 5db55ce into nvaccess:threshold_py3_staging Jun 25, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Jun 25, 2019
michaelDCurran added a commit that referenced this pull request Jun 26, 2019
…led before imports are initialized (#9800)"

This reverts commit 5db55ce.
michaelDCurran added a commit that referenced this pull request Jun 26, 2019
…led before imports are initialized (#9800)"

This reverts commit 5db55ce.
michaelDCurran added a commit that referenced this pull request Jun 26, 2019
…led before imports are initialized (#9800)" (#9815)

This reverts commit 5db55ce.
@michaelDCurran

Copy link
Copy Markdown
Member

When I reviewed this I assumed it was _importers that was none. However, it is actually that _importers contains None as one of its items.
I have found the root cause to this and handled it in pr #9814 and therefore this pr has been reverted.

@josephsl josephsl deleted the i9797appModExistsException branch November 2, 2019 11:34
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.

3 participants