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
Idle: mock Text class and test thereof #62565
Comments
test_rstrip2.patch contain a Text class to be added to mock_tk.py. The purpose of a mock class is to imitate another class with respect to certain behaviors. The way to verify that is does that is to run the same set of tests for those behaviors with both. This is similar in idea and will be the same in execution as running the same set of tests with a Python-coded module and a c-coded accelerator version of at least some functions of the module. The trick is to do this without code duplication is write a mixin class with the tests and derive two testcase classes using the mixin. |
Added Text class to mock_tk.py and GUI/non-GUI tests in test_text.py. Running the IDLE tests produced no errors for me. |
Great start! Some revisions:
Here is the result. I think it is about ready to commit after sleeping on it and a final review. |
Upon further review and tests, I notice that ._decode
Tests with 'end' only pass now because the tested methods ignore the buggy decode for 'end' and special-case it instead. When I added tests with out of bounds indexes, they failed. I am working now on fixing all this. Spaces are supposed to follow arg-separating commas in function calls. The initial patch lacked them and I have added them. I need them because they make code easier for *me* to read and review, which is an example of why PEP-8 requires them. |
Whoops, I got that partly wrong in that index returns a 'r.c' string after doing what _decode is supposed to do, which is to decode the input according to the current text. The mock index should just return '%s.%s' % _decode(position). There is still the point that index and _decode now give different coordinates for 'end' and that _decode should be tested by testing mock index, which wraps it, against tk index. Since tk.Text args can be passed by name, the mock methods should use the same parameter names. |
Thanks Terry, I will start PEP-8-checking my code before I submit (as well as testing more thoroughly). I was thinking the same thing about the logic behind _decode and index functions needing to be combined. How would you recommend adding functionality to the decode function to handle expressions like "1.2 +5 chars" or "1.0 lineend-5c"? AutoComplete.py (bpo-18409) uses this kind of index, so it will be needed soon. I'm thinking that splitting off the base index then parsing the remaining modifier expressions is the way to go. I was also thinking that a _checkIndex method would be good to have especially when using the +/-line and +/-char expressions. |
The real problem with 'end' and 'big.m' is that there are three proper decodings, depending on the method asking. I think this patch mostly solves the problems mentioned before. All tests, including many new ones, pass. |
A little more polishing and the tests pass again. I think I am done with the implemented methods. Before I commit, I want to review the set of 'pass' functions. It seems a bit haphazard. I think display changing methods like .see are fine.I am not sure about including internal operation methods like .mark_set (until actually needed). |
I want to commit this patch more or less as is so we can move forward with the tests that do not need anything more. We can then elaborate mock Text as needed and desired. Looking at http://effbot.org/tkinterbook/text.htm, for instance, I see that 'lineend' is an expression modifier in that same category as +/- chars/lines. So _decode should not really handle it until it handles such modifiers more generally. As near as I could tell from experiment, 'm.n lineend' is the same as 'm.end', so the former is never needed and could be changed to the latter in Idle code. As far as you know, correct? The use for 'lineend' would seem to be after other modifiers, as in '1.0 +100c lineend', where the line whose end we go to is likely not line 1. Remember that for advanced Text use, we have the option of using tk.Text for a test, at least at first. The gain would be not having to reproduce baroque behavior*. The cost would be making the test a gui test and running on fewer buildbots. I felt that the basic mock done so far would be worth the time because a) it would be useful for many tests and b) I would learn the Text widget and how to experiment with it to determine its under-documented behavior. *For instance, having optional spaces within modifiers as well as using them to separate modifiers. Do you know if there is a coherent index grammar anywhere? Or is it only defined by the Text.index C code? |
Using tk.Text for more involved tests sounds good (at least as a start). The pass functions were used to get the FormatParagraph test (bpo-18226) working. I've been using the same effbot.org site as a reference and haven't found anything more detailed. |
New changeset 5ac2ec0a34a5 by Terry Jan Reedy in branch '2.7': New changeset 8f13fb4c5826 by Terry Jan Reedy in branch '3.3': New changeset 5611d3a954f8 by Terry Jan Reedy in branch '3.3': New changeset 86cc1983a94d by Terry Jan Reedy in branch '2.7': |
I documented and left most of the 'pass' methods. The bind method is inherited from Misc class and is not specifically a Text method, but I will leave it here for now. These def undo_block_start(self, *args):
pass
def undo_block_stop(self, *args):
pass are not Text methods, so I removed them. We can discuss what you intended as part of the FormatParagraph issue. |
New changeset 008d83c4efaf by Terry Jan Reedy in branch '2.7': |
Well, that is annoying. I expected 2.7 failures due to mistakes already corrected, but not with 3.x, and these look to be the latter. ====================================================================== Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.coghlan-redhat/build/Lib/idlelib/idle_test/test_text.py", line 219, in setUpClass
cls.root = Tk()
File "/home/buildbot/buildarea/3.x.coghlan-redhat/build/Lib/tkinter/__init__.py", line 1789, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable I do not get this on my system, and I just retried with I did get a test_idle failure running all tests _tkinter.TclError: Can't find a usable init.tcl in the following directories: This is followed by a list of non-existent directories that omits the one what it actually is and where it is routinely found and it obviously was on the previous run with only test_idle run. What puzzles me is that both buildbots skipped test_tk and test_ttk_guionly, which suggests that they do not have -ugui, (Nick, one of these is yours) which means they should not have ever called tkinter. On my machine, |
New changeset bc3a34e47923 by Terry Jan Reedy in branch '3.3': New changeset ba4c826848d5 by Terry Jan Reedy in branch '2.7': |
Looking through the 11 stable 3.x buildbots (1 still running), I see 3 outcomes.
_tkinter.create just calls Tkapp_New with the same args and the message comes from tcl/tk. I do not know if 'display name' is the same as the 'screenName' parameter or not. The doc string just says "Return a new Toplevel widget on screen SCREENNAME." Is this something to do with X11? If so, why isn't $DISPLAY set? Passing screenName='fake' has no effect on my Win7 machine. I think the following patch should quiet things for now, even if not the best patch. |
Yeah, DISPLAY is how unix finds the X11 display. I don't remember how the tkguionly tests deal with that being missing, but since the tests are run "headless" there is indeed no DISPLAY for the tests to talk to. |
Looks like ttk_guionly gets skipped on my buildbot because of the following code at the top of test_ttk_guionly: try: So your skip fix may actually be the best solution. |
The change worked, so this issue can be closed. I opened a new issue, bpo-18441, for dealing with the problem in test_idle by moving the TclError check there, so it does not arise in other idle_test/test_*.py files. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: