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

Improve __repr__ output for many pywinauto objects #322

Closed
vasily-v-ryabov opened this issue Feb 28, 2017 · 3 comments
Closed

Improve __repr__ output for many pywinauto objects #322

vasily-v-ryabov opened this issue Feb 28, 2017 · 3 comments

Comments

@vasily-v-ryabov
Copy link
Contributor

Current output looks quite useless with unnecessary object address.

>>> dlg_spec.wrapper_object()
<pywinauto.controls.win32_controls.DialogWrapper object at 0x05639B70>

This could be improved so:

>>> dlg_spec.wrapper_object()
<win32_controls.DialogWrapper object "Dialog title">

Similar improvement could be done for a window specification object.

Thanks J. Does for the report.

@airelil
Copy link
Contributor

airelil commented Mar 4, 2017

As it's pointed out in this SO answer. There is a difference between __repr__ and __str__. The first is more for a developer while the latter is for the user. In the meantime, I implemented __str__ for wrapper-classes that produces the following output for a wrapper with a title:
u'uiawrapper.UIAWrapper - "[No Name] - GVIM"'

while for a wrapper without a text it just appends an object ID:
u'uiawrapper.UIAWrapper - "" <object 0x4fd98d0>'

Should we produce the same output for __repr__ calls or it might have more technical details ?

@vasily-v-ryabov
Copy link
Contributor Author

In our case both strings are for test developers. We may print the same things for both.
So if __repr__ tends to be unambiguous, we need a unique control identifier to be printed if no text provided. For Win32 it's a handle, for UIA it's a RuntimeID property that I use in __hash__ method.

Also I think in case of no text we may print auto_id value in the following format:

u'uiawrapper.UIAWrapper - "" <auto_id "m_grpBox">'

And only if there are no both text values we may output handle or runtime_id.

I may be wrong about "str is for developers too". Alternative way is making str(wrp) an alias for wrp.window_text() but I don't like this idea for now. It would be nice to hear customers opinions about that.

vasily-v-ryabov added a commit that referenced this issue Mar 5, 2017
Fix issue #322: implement BaseWrapper.__repr__() and ElementInfo.__repr__()
@vasily-v-ryabov
Copy link
Contributor Author

I think we can close this issue. Current implementation is good enough. We can open another issue for further improvements if necessary.

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

No branches or pull requests

2 participants