Loading ...
Sorry, an error occurred while loading the content.

[PATCH] (27/27?) Python interface improvements: add tests for various python interfaces

Expand Messages
  • ZyX
    # HG changeset patch # User ZyX # Date 1367420260 -14400 # Branch python-extended-2 # Node ID 9f25c7e5b0bdee4ecace3c2a337af3e60394e03e # Parent
    Message 1 of 49 , May 1, 2013
    • 0 Attachment
      # HG changeset patch
      # User ZyX <kp-pav@...>
      # Date 1367420260 -14400
      # Branch python-extended-2
      # Node ID 9f25c7e5b0bdee4ecace3c2a337af3e60394e03e
      # Parent 9a4df126f7c42e0b81df62eba1249300a906f450
      Add tests for vim.{current,window*,tabpage*}

      diff -r 9a4df126f7c4 -r 9f25c7e5b0bd src/testdir/test86.in
      --- a/src/testdir/test86.in Wed May 01 17:48:42 2013 +0400
      +++ b/src/testdir/test86.in Wed May 01 18:57:40 2013 +0400
      @@ -334,6 +334,7 @@
      :let g:foo = 'bac'
      :let w:abc = 'def'
      :let b:baz = 'bar'
      +:let t:bar = 'jkl'
      :try
      : throw "Abc"
      :catch
      @@ -342,6 +343,7 @@
      :put =pyeval('vim.vars[''foo'']')
      :put =pyeval('vim.current.window.vars[''abc'']')
      :put =pyeval('vim.current.buffer.vars[''baz'']')
      +:put =pyeval('vim.current.tabpage.vars[''bar'']')
      :"
      :" Options
      :" paste: boolean, global
      @@ -561,6 +563,78 @@
      except StopIteration:
      cb.append('StopIteration')
      EOF
      +:"
      +:" Test vim.{tabpage,window}list and vim.{tabpage,window} objects
      +:tabnew 0
      +:tabnew 1
      +:vnew a.1
      +:tabnew 2
      +:vnew a.2
      +:vnew b.2
      +:vnew c.2
      +py << EOF
      +cb.append('Number of tabs: ' + str(len(vim.tabpages)))
      +cb.append('Current tab pages:')
      +def W(w):
      + if '(unknown)' in repr(w):
      + return '<window object (unknown)>'
      + else:
      + return repr(w)
      +for t in vim.tabpages:
      + cb.append(' ' + repr(t) + '(' + str(t.number) + ')' + ': ' + str(len(t.windows)) + ' windows, current is ' + W(t.window))
      + cb.append(' Windows:')
      + for w in t.windows:
      + cb.append(' ' + W(w) + '(' + str(w.number) + ')' + ': displays buffer ' + repr(w.buffer) + '; cursor is at ' + repr(w.cursor))
      + # Other values depend on the size of the terminal, so they are checked partly:
      + for attr in ('height', 'row', 'width', 'col'):
      + try:
      + aval = getattr(w, attr)
      + if type(aval) is not long:
      + raise TypeError
      + if aval < 0:
      + raise ValueError
      + except Exception:
      + cb.append('!!!!!! Error while getting attribute ' + attr + ': ' + sys.exc_type.__name__)
      + w.cursor = (len(w.buffer), 0)
      +cb.append('Number of windows in current tab page: ' + str(len(vim.windows)))
      +if list(vim.windows) != list(vim.current.tabpage.windows):
      + cb.append('!!!!!! Windows differ')
      +EOF
      +:"
      +:" Test vim.current
      +py << EOF
      +def H(o):
      + return repr(o)
      +cb.append('Current tab page: ' + repr(vim.current.tabpage))
      +cb.append('Current window: ' + repr(vim.current.window) + ': ' + H(vim.current.window) + ' is ' + H(vim.current.tabpage.window))
      +cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ ' is ' + H(vim.current.tabpage.window.buffer))
      +# Assigning: fails
      +try:
      + vim.current.window = vim.tabpages[0].window
      +except ValueError:
      + cb.append('ValueError at assigning foreign tab window')
      +
      +for attr in ('window', 'tabpage', 'buffer'):
      + try:
      + setattr(vim.current, attr, None)
      + except TypeError:
      + cb.append('Type error at assigning None to vim.current.' + attr)
      +
      +# Assigning: success
      +vim.current.tabpage = vim.tabpages[-2]
      +vim.current.buffer = cb
      +vim.current.window = vim.windows[0]
      +vim.current.window.cursor = (len(vim.current.buffer), 0)
      +cb.append('Current tab page: ' + repr(vim.current.tabpage))
      +cb.append('Current window: ' + repr(vim.current.window))
      +cb.append('Current buffer: ' + repr(vim.current.buffer))
      +cb.append('Current line: ' + repr(vim.current.line))
      +for b in vim.buffers:
      + if b is not cb:
      + vim.command('bwipeout! ' + b.number)
      +EOF
      +:tabonly!
      +:only!
      :endfun
      :"
      :call Test()
      diff -r 9a4df126f7c4 -r 9f25c7e5b0bd src/testdir/test86.ok
      --- a/src/testdir/test86.ok Wed May 01 17:48:42 2013 +0400
      +++ b/src/testdir/test86.ok Wed May 01 18:57:40 2013 +0400
      @@ -80,6 +80,7 @@
      bac
      def
      bar
      +jkl
      >>> paste
      p/gopts1: False
      p/wopts1! KeyError
      @@ -328,3 +329,33 @@
      i4:<buffer test86.in>
      i4:<buffer test86.in>
      StopIteration
      +Number of tabs: 4
      +Current tab pages:
      + <tabpage 0>(1): 1 windows, current is <window object (unknown)>
      + Windows:
      + <window object (unknown)>(0): displays buffer <buffer test86.in>; cursor is at (954, 0)
      + <tabpage 1>(2): 1 windows, current is <window object (unknown)>
      + Windows:
      + <window object (unknown)>(0): displays buffer <buffer 0>; cursor is at (1, 0)
      + <tabpage 2>(3): 2 windows, current is <window object (unknown)>
      + Windows:
      + <window object (unknown)>(0): displays buffer <buffer a.1>; cursor is at (1, 0)
      + <window object (unknown)>(0): displays buffer <buffer 1>; cursor is at (1, 0)
      + <tabpage 3>(4): 4 windows, current is <окно 0>
      + Windows:
      + <окно 0>(1): displays buffer <buffer c.2>; cursor is at (1, 0)
      + <окно 1>(2): displays buffer <buffer b.2>; cursor is at (1, 0)
      + <окно 2>(3): displays buffer <buffer a.2>; cursor is at (1, 0)
      + <окно 3>(4): displays buffer <buffer 2>; cursor is at (1, 0)
      +Number of windows in current tab page: 4
      +Current tab page: <tabpage 3>
      +Current window: <окно 0>: <окно 0> is <окно 0>
      +Current buffer: <buffer c.2>: <buffer c.2> is <buffer c.2> is <buffer c.2>
      +ValueError at assigning foreign tab window
      +Type error at assigning None to vim.current.window
      +Type error at assigning None to vim.current.tabpage
      +Type error at assigning None to vim.current.buffer
      +Current tab page: <tabpage 2>
      +Current window: <окно 0>
      +Current buffer: <buffer test86.in>
      +Current line: 'Type error at assigning None to vim.current.buffer'
      diff -r 9a4df126f7c4 -r 9f25c7e5b0bd src/testdir/test87.in
      --- a/src/testdir/test87.in Wed May 01 17:48:42 2013 +0400
      +++ b/src/testdir/test87.in Wed May 01 18:57:40 2013 +0400
      @@ -320,6 +320,7 @@
      :let g:foo = 'bac'
      :let w:abc = 'def'
      :let b:baz = 'bar'
      +:let t:bar = 'jkl'
      :try
      : throw "Abc"
      :catch
      @@ -328,6 +329,7 @@
      :put =py3eval('vim.vars[''foo'']')
      :put =py3eval('vim.current.window.vars[''abc'']')
      :put =py3eval('vim.current.buffer.vars[''baz'']')
      +:put =py3eval('vim.current.tabpage.vars[''bar'']')
      :"
      :" Options
      :" paste: boolean, global
      @@ -547,6 +549,78 @@
      except StopIteration:
      cb.append('StopIteration')
      EOF
      +:"
      +:" Test vim.{tabpage,window}list and vim.{tabpage,window} objects
      +:tabnew 0
      +:tabnew 1
      +:vnew a.1
      +:tabnew 2
      +:vnew a.2
      +:vnew b.2
      +:vnew c.2
      +py3 << EOF
      +def W(w):
      + if '(unknown)' in repr(w):
      + return '<window object (unknown)>'
      + else:
      + return repr(w)
      +cb.append('Number of tabs: ' + str(len(vim.tabpages)))
      +cb.append('Current tab pages:')
      +for t in vim.tabpages:
      + cb.append(' ' + repr(t) + '(' + str(t.number) + ')' + ': ' + str(len(t.windows)) + ' windows, current is ' + W(t.window))
      + cb.append(' Windows:')
      + for w in t.windows:
      + cb.append(' ' + W(w) + '(' + str(w.number) + ')' + ': displays buffer ' + repr(w.buffer) + '; cursor is at ' + repr(w.cursor))
      + # Other values depend on the size of the terminal, so they are checked partly:
      + for attr in ('height', 'row', 'width', 'col'):
      + try:
      + aval = getattr(w, attr)
      + if type(aval) is not int:
      + raise TypeError
      + if aval < 0:
      + raise ValueError
      + except Exception as e:
      + cb.append('!!!!!! Error while getting attribute ' + attr + ': ' + e.__class__.__name__)
      + w.cursor = (len(w.buffer), 0)
      +cb.append('Number of windows in current tab page: ' + str(len(vim.windows)))
      +if list(vim.windows) != list(vim.current.tabpage.windows):
      + cb.append('!!!!!! Windows differ')
      +EOF
      +:"
      +:" Test vim.current
      +py3 << EOF
      +def H(o):
      + return repr(o)
      +cb.append('Current tab page: ' + repr(vim.current.tabpage))
      +cb.append('Current window: ' + repr(vim.current.window) + ': ' + H(vim.current.window) + ' is ' + H(vim.current.tabpage.window))
      +cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ ' is ' + H(vim.current.tabpage.window.buffer))
      +# Assigning: fails
      +try:
      + vim.current.window = vim.tabpages[0].window
      +except ValueError:
      + cb.append('ValueError at assigning foreign tab window')
      +
      +for attr in ('window', 'tabpage', 'buffer'):
      + try:
      + setattr(vim.current, attr, None)
      + except TypeError:
      + cb.append('Type error at assigning None to vim.current.' + attr)
      +
      +# Assigning: success
      +vim.current.tabpage = vim.tabpages[-2]
      +vim.current.buffer = cb
      +vim.current.window = vim.windows[0]
      +vim.current.window.cursor = (len(vim.current.buffer), 0)
      +cb.append('Current tab page: ' + repr(vim.current.tabpage))
      +cb.append('Current window: ' + repr(vim.current.window))
      +cb.append('Current buffer: ' + repr(vim.current.buffer))
      +cb.append('Current line: ' + repr(vim.current.line))
      +for b in vim.buffers:
      + if b is not cb:
      + vim.command('bwipeout! ' + str(b.number))
      +EOF
      +:tabonly!
      +:only!
      :endfun
      :"
      :call Test()
      diff -r 9a4df126f7c4 -r 9f25c7e5b0bd src/testdir/test87.ok
      --- a/src/testdir/test87.ok Wed May 01 17:48:42 2013 +0400
      +++ b/src/testdir/test87.ok Wed May 01 18:57:40 2013 +0400
      @@ -69,6 +69,7 @@
      bac
      def
      bar
      +jkl
      >>> paste
      p/gopts1: False
      p/wopts1! KeyError
      @@ -317,3 +318,33 @@
      i4:<buffer test87.in>
      i4:<buffer test87.in>
      StopIteration
      +Number of tabs: 4
      +Current tab pages:
      + <tabpage 0>(1): 1 windows, current is <window object (unknown)>
      + Windows:
      + <window object (unknown)>(0): displays buffer <buffer test87.in>; cursor is at (929, 0)
      + <tabpage 1>(2): 1 windows, current is <window object (unknown)>
      + Windows:
      + <window object (unknown)>(0): displays buffer <buffer 0>; cursor is at (1, 0)
      + <tabpage 2>(3): 2 windows, current is <window object (unknown)>
      + Windows:
      + <window object (unknown)>(0): displays buffer <buffer a.1>; cursor is at (1, 0)
      + <window object (unknown)>(0): displays buffer <buffer 1>; cursor is at (1, 0)
      + <tabpage 3>(4): 4 windows, current is <окно 0>
      + Windows:
      + <окно 0>(1): displays buffer <buffer c.2>; cursor is at (1, 0)
      + <окно 1>(2): displays buffer <buffer b.2>; cursor is at (1, 0)
      + <окно 2>(3): displays buffer <buffer a.2>; cursor is at (1, 0)
      + <окно 3>(4): displays buffer <buffer 2>; cursor is at (1, 0)
      +Number of windows in current tab page: 4
      +Current tab page: <tabpage 3>
      +Current window: <окно 0>: <окно 0> is <окно 0>
      +Current buffer: <buffer c.2>: <buffer c.2> is <buffer c.2> is <buffer c.2>
      +ValueError at assigning foreign tab window
      +Type error at assigning None to vim.current.window
      +Type error at assigning None to vim.current.tabpage
      +Type error at assigning None to vim.current.buffer
      +Current tab page: <tabpage 2>
      +Current window: <окно 0>
      +Current buffer: <buffer test87.in>
      +Current line: 'Type error at assigning None to vim.current.buffer'

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • ZyX
      ... Because you have problems with encoding somewhere: there were no question marks in the patch, but Russian text. I just was not aware of the strange choice:
      Message 49 of 49 , May 15, 2013
      • 0 Attachment
        > After including this patch the tests were failing. The .ok files had
        > "????" where the test results in "window". I assume those question
        > marks were wrong, so I fixed the .ok files for that. But I wonder why
        > this happened.

        Because you have problems with encoding somewhere: there were no question marks in the patch, but Russian text. I just was not aware of the strange choice: using translated strings in `repr()`. I think translated messages here are just as “good” as translated exceptions; needless to say I have never seen them translated in other projects.

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      Your message has been successfully submitted and would be delivered to recipients shortly.