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

IDLE: Improve Mock_Text #62704

Open
JayKrish mannequin opened this issue Jul 19, 2013 · 4 comments
Open

IDLE: Improve Mock_Text #62704

JayKrish mannequin opened this issue Jul 19, 2013 · 4 comments
Assignees
Labels
3.10 only security fixes tests Tests in the Lib/test dir topic-IDLE type-feature A feature request or enhancement

Comments

@JayKrish
Copy link
Mannequin

JayKrish mannequin commented Jul 19, 2013

BPO 18504
Nosy @terryjreedy, @ezio-melotti, @rovitotv
Files
  • decodeChecklist.txt
  • decodeTest.py
  • mocktk_decodeByRE1.patch
  • mock-text-_decode.diff
  • 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:

    assignee = 'https://github.com/terryjreedy'
    closed_at = None
    created_at = <Date 2013-07-19.13:00:52.640>
    labels = ['expert-IDLE', 'type-feature', '3.10']
    title = 'IDLE: Improve Mock_Text'
    updated_at = <Date 2020-06-07.20:34:42.385>
    user = 'https://bugs.python.org/JayKrish'

    bugs.python.org fields:

    activity = <Date 2020-06-07.20:34:42.385>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = False
    closed_date = None
    closer = None
    components = ['IDLE']
    creation = <Date 2013-07-19.13:00:52.640>
    creator = 'JayKrish'
    dependencies = []
    files = ['30979', '30980', '31043', '35435']
    hgrepos = []
    issue_num = 18504
    keywords = ['patch']
    message_count = 4.0
    messages = ['193358', '193395', '193740', '219502']
    nosy_count = 7.0
    nosy_names = ['terry.reedy', 'ezio.melotti', 'jesstess', 'Todd.Rovito', 'JayKrish', 'philwebster', 'Saimadhav.Heblikar']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18504'
    versions = ['Python 3.10']

    @JayKrish
    Copy link
    Mannequin Author

    JayKrish mannequin commented Jul 19, 2013

    Following the Idle: mock Text class and test thereof created bpo-18365
    I am trying to improve the _decode function because most of the Idletests needs the mock text and requires some more features to handle indexes.
    Started improving the mockText _decode method while writing unit test for AutoExpand.py at bpo-18292.
    For now I want the mock text to decode following indexes:
    line.char, insert, end, +-#c/chars, lineend, linestart, wordstart, wordend

    For this I am trying to write regular expressions to extract the parts of index.
    The submitted decodeTest.py is a sample script to show how my regular expression starts manipulating the decoding of indexes.

    I have attached a checklist of several indexes. So you can easily run them and get an understanding of my approach.

    @terryjreedy
    Copy link
    Member

    Further changes should be aimed at actual idlelib uses. Wordstart and wordend are used once each in AutoExpand.py (and wordstart a couple of times for tag.start positions). So forget them.

    Does idlelib really have indexes like "2.3 + 1c" ('2.4'), "2.3-1c" ('2.2'), and "22.33-1chars" ('22.32')?

    The grammar we need to parse is something like
    index := base modifier* # nearly always 0, 1, few 2, one 3 times, so
    index := base modifier{0:3}
    index := base modmaybe modmaybe modmaybe
    base := numpair | mark
    numpair := int '.' ( int | 'end' )
    mark := 'end' | 'insert' | 'iomark' | 'my_anchor'
    | 'sel.first' | sel.last # parts tags but this should work
    modmaybe := modifier | ''
    modifier := ' linestart' | ' lineend' | incr
    incr := ' '* ('+' | '-') ' '* int ('c' | 'line')
    # Could change the one 'char' to 'c'

    Rather than parse an entire index at once, parse, interpret as position, and remove base from input. While remainder, parse, apply to position, and remove from remainder. Whether the parsing is done with base and modifier REs with groups or code or some mixture does not much matter.

    @terryjreedy terryjreedy self-assigned this Jul 20, 2013
    @terryjreedy terryjreedy added the type-feature A feature request or enhancement label Jul 20, 2013
    @JayKrish
    Copy link
    Mannequin Author

    JayKrish mannequin commented Jul 26, 2013

    Yes,correcting myself. I should aim indexes which actual idlelib uses. Thank you Terry for the grammar. Fighting with the index parsing last week, and finally came up with a level to break the index into base and modifier and decode it along with using regular expressions.
    Now the mock_tk attached at this patch passes all the existing test cases, and failing the new test I have written on text_test

    The problem now I am dealing with is, there are four exceeding conditions I have to handle which make errors.
    1.returning line < 0
    2.returning line > last line
    3.returning char < 0
    4.returning char > its line length

    For example, in parsing base the return line may exceed last line but the modifier will say '-2lines' doing that, now the return line is not exceeding last line.

    @SaimadhavHeblikar
    Copy link
    Mannequin

    SaimadhavHeblikar mannequin commented Jun 1, 2014

    This patch tries to enable mock_Tk.Text._decode to handle the following patterns
    insert linestart
    insert lineend
    insert wordstart
    insert wordend
    insert +x chars
    insert -x chars

    These additions are required for testing AutoExpand and are written keeping the same in mind. Also, adds respective tests for test_decode in test_text.py.

    I would like to know if my approach is acceptable or whether it needs changes.

    bpo-18292 is about adding unittests for AutoExpand.

    (A 2.7 patch will be submitted once the above changes become acceptable)

    @terryjreedy terryjreedy changed the title IDLE:Improvements- Improving Mock_Text IDLE: Improve Mock_Text Jun 19, 2017
    @terryjreedy terryjreedy added 3.10 only security fixes and removed 3.7 (EOL) end of life labels Jun 7, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland erlend-aasland added the tests Tests in the Lib/test dir label Jul 27, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes tests Tests in the Lib/test dir topic-IDLE type-feature A feature request or enhancement
    Projects
    Status: No status
    Development

    No branches or pull requests

    2 participants