Terry J. Reedy added the comment:

The patch models Text.data as a single string. But a tkinter Text contains a 
sequence of strings. While the single sequence works for the one test of the 
...event method, a list of strings is needed for .get and many other methods 
with position parameters to actually work. And .get is needed for testing 
find_paragraph and, I am sure, other methods of other classes.

I am not sure of the correct initialization, but it mostly will not matter.

More troublesome is that tkinter lines start at 1, not 0. Possible responses 
are 1) add a dummy first line to self.data, 2) added all line number by -1 
before indexing, or 3) ignore the difference as it will not matter for most 
tests. I like 3). Any test that cares can prepend an extra \n to the beginning 
of the text is loads into the editor.

Choosing 3, the methods would be

def __init__(self):
    self.data = ['']  # I think

def setData(self, text)
    self.data = text.split('\n)

def getData(self):
    return '\n'.join(self.data)

# easy so far ;-)

def _decode(self, position):  # private helper
    line, col = position.split('.')
    line = int(line)
    col = len(self.data[line]) if col == '0 lineend' else int(col)
    return line, col

Doc string for Text.get(self, index1, index2=None) is
"Return the text from INDEX1 to INDEX2 (not included)."
Interpreting this gives

def get(self, start, end=None):
    line, col = self._decode(start)
    if end is None:
        return self.data[line][col]
    else:
        endline, endcol = self._decode(end)
        if line == endline:
            return self.data[line][col:endcol]
        else:
            lines = [self.data[line][col:]]
            for i in range(line+1, endline):
                lines.append(self.data[i])
            lines.append(self.data[endline][:endcol])
            return '\n'.join(lines)

This .get code can be used or adapted for .count, .dump, .delete, .replace, and 
even .insert.  At this point, we need a test for the mock Text class. Maybe we 
can extract something from tkinter.Text tests.

I am not sure how far to go with this; at some point (use of marks or tags?), 
we say "Use tkinter.Text and make it a gui test.". But handling as least basic 
indexing and pairs of indexes seems essential to me.

For gui methods like .see and .scan*, the docstring should be something short 
like "Gui method, do nothing."

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18226>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to