Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@M3ssman
Copy link
Contributor

@M3ssman M3ssman commented Dec 20, 2021

This refactoring of test_resource_manager is also meant as proposal to reduce the environmental and internal dependencies in the ocrd-modules.

As @kba pointed out, there's actually a strong dependency between the resource_manager-module to the time, when the constants XDG_CONFIG_HOME and XDG_DATA_HOME are loaded / evaluated.
The trouble with testing the resource_manager originates from the - somehow intransparent - relationship to the execution environment i.e. context - intransparent to the caller in the moment of execution, which makes it difficult to test any depending functionalities, since testing is a rather artificial execution. The rather plain "workaround" for this bias is the possibility to pass these this info to the objects which require them, as properties or at initialization time. I found myself often ending up in implementations like this, which only exist to ease testing purposes and nothing else.

This way there's no need to run the three resource_manager tests separate from regular unit tests.

Personally, I tried even to go further this line, which simply results in having no "constant" values for HOME or the xdg-stuff, but rather evaluated both only when they are really required, but this interferes with other modules - os.py and bashlib.py, the latter which I do not yet understand.

Copy link
Member

@kba kba left a comment

Choose a reason for hiding this comment

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

Thanks again! You're probably right, it's best to inject these into the object rather than relying on "constants" that need to be changed for testing. The final testing code is much more readable like this. I also discovered monkeypatch today, this is extremely useful, e.g. for mocking sys.stdin etc. Looking forward to using that once we completely migrated to pytest :)

@kba kba force-pushed the feat/rfct/pytest3 branch from e19191f to d7de707 Compare December 23, 2021 13:50
@kba kba merged commit 9567190 into OCR-D:master Dec 23, 2021
@kba kba deleted the feat/rfct/pytest3 branch December 23, 2021 13:53
@bertsky
Copy link
Collaborator

bertsky commented Jan 17, 2022

@M3ssman @kba I'm not sure if it was this or one of the other merged pytest PRs, but I am having a regression when testing on a local system with ~/ocrd_logging.conf in place. (Related to #679 I think...)

@M3ssman
Copy link
Contributor Author

M3ssman commented Jan 17, 2022

Must confess I usually do not have an account-global logging configuration, I pass it straight into the working directory for each OCR-D-Workflow. Please can you provide some more details on how the regression turns out and how one might reproduce this?

@bertsky
Copy link
Collaborator

bertsky commented Jan 17, 2022

Of course: take the default ocrd_utils/ocrd_logging.conf and modify it in some places, say by defining a logger for qualname=PIL and level=ERROR (which will fail at

self.assertEqual(logging.getLogger('PIL').getEffectiveLevel(), logging.INFO)
), or by setting the default consoleHandler to sys.stdout instead of stderr.

@M3ssman
Copy link
Contributor Author

M3ssman commented Jan 17, 2022

Thanks! Plz give me some time to take a closer look to the mentioned test module test_decorators.py.

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