Il 28/01/2011 19:53, Tommaso Cucinotta ha scritto:
Il 28/01/2011 12:37, Pavel Sanda ha scritto:
keytest should be more powerful.
in fact, with that I can probably choose whether to test also the GUI part (sending characters that push buttons or type stuff), or to test only the LFUN (by sending [M-x ....]). The lyxserver would probably only allow the latter. I'll have a closer loot at keytest.py.

From my preliminary attempts of use of this machinery, I came up with the attached "hello world" test case.

A few comments:
-) what's the rationale behind the syntax "\Afn" (which stands for menu voice "&File &New") ? -) is there a simpler syntax to let LyX type text, i.e., something like "HelloWorld" instead of the monster in the attached in-sample.txt ?

Now I'm missing something to dump the current selection (or other info from the Advanced F&R subsystem) somewhere, and a way to compare it with what I expect.

A few alternatives:
1) a special command-line (debug) flag of LyX that forces it to dump the current cursor position and associated selection to a file at the end of each LFUN dispatch (or after each key press processing cycle) 2) I rely on "-dbg find", then I dump whatever I want wherever I want, then I try to understand whether (parts of) the debugging output is how I expect, i.e., cursor(s), selection(s), exported paragraph(s) or buffer(s) content(s), etc...

Any advice ? Thanks,

    T.

Index: keytest.py
===================================================================
--- keytest.py	(revisione 37352)
+++ keytest.py	(copia locale)
@@ -139,7 +139,7 @@
             os._exit(0)
         if self.i >= len(self.lines):
             self.loops = self.loops + 1
-            if self.loops > 3:
+            if self.loops >= max_loops:
                 os._exit(0)
             self.i = 0
             return 'Loop'
@@ -212,8 +212,8 @@
         os._exit(1)
 
 def RaiseWindow():
-    os.system("echo x-session-manager PID: $X_PID.")
-    os.system("echo x-session-manager open files: `lsof -p $X_PID | grep ICE-unix | wc -l`")
+    #os.system("echo x-session-manager PID: $X_PID.")
+    #os.system("echo x-session-manager open files: `lsof -p $X_PID | grep ICE-unix | wc -l`")
     ####os.system("wmctrl -l | ( grep '"+lyx_window_name+"' || ( killall lyx ; sleep 1 ; killall -9 lyx ))")
     #os.system("wmctrl -R '"+lyx_window_name+"' ;sleep 0.1")
     system_retry(30, "wmctrl -R '"+lyx_window_name+"'")
@@ -227,6 +227,14 @@
 lyx_window_name = os.environ.get('LYX_WINDOW_NAME')
 screenshot_out = os.environ.get('SCREENSHOT_OUT')
 
+max_loops = os.environ.get('MAX_LOOPS')
+if max_loops is None:
+    max_loops = 3
+
+lyx_exe = os.environ.get('LYX_EXE')
+if lyx_exe is None:
+    lyx_exe = "lyx"
+
 file_new_command = os.environ.get('FILE_NEW_COMMAND')
 if file_new_command is None:
     file_new_command = "\Afn"
@@ -257,20 +265,39 @@
 
 outfile = open(outfilename, 'w')
 
-RaiseWindow()
-sendKeystring("\Afn", lyx_pid)
+if lyx_pid != "":
+    RaiseWindow()
+    sendKeystring("\Afn", lyx_pid)
+
 write_commands = True
 
 while True:
     #os.system('echo -n LOADAVG:; cat /proc/loadavg')
     c = x.getCommand()
-    if c == 'Loop':
+    outfile.writelines(c + '\n')
+    outfile.flush()
+    if c == 'TestBegin':
+        print "\n"
+        lyx_pid=os.popen("pidof lyx").read()
+        if lyx_pid != "":
+            print "Found running instance(s) of LyX: " + lyx_pid + ": killing them all\n"
+            os.system("killall lyx")
+        time.sleep(0.2)
+        print "Starting LyX...\n"
+        os.system(lyx_exe + "&")
+        time.sleep(2)
+        lyx_pid=os.popen("pidof lyx").read().rstrip()
+        lyx_window_name=os.popen("wmctrl -l | grep -i 'lyx$' | sed -e 's/.*\\([Ll]y[Xx].*\\)$/\\1/'").read().rstrip()
+        print 'lyx_pid: ' + lyx_pid + '\n'
+        print 'lyx_win: ' + lyx_window_name + '\n'
+        #RaiseWindow()
+        sendKeystring("\Afn", lyx_pid)
+        time.sleep(0.5)
+    elif c == 'Loop':
         outfile.close()
         outfile = open(outfilename + '+', 'w')
         print 'Now Looping'
-    outfile.writelines(c + '\n')
-    outfile.flush()
-    if c == 'RaiseLyx':
+    elif c == 'RaiseLyx':
         print 'Raising Lyx'
         RaiseWindow()
     elif c[0:4] == 'KK: ':
@@ -286,5 +313,11 @@
     elif c == 'Loop':
         RaiseWindow()
         sendKeystring(ResetCommand, lyx_pid)
+    elif c == 'TestEnd':
+        time.sleep(1)
+        print "\nTerminating lyx instance: " + str(lyx_pid) + "\n"
+        os.system("kill -9 " + str(lyx_pid) + "\n");
+        print "Test case terminated\n"
+        os._exit(0)
     else:
         print "Unrecognised Command '" + c + "'\n"
Index: run-test.sh
===================================================================
--- run-test.sh	(revisione 0)
+++ run-test.sh	(revisione 0)
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+KEYTEST=./keytest.py
+
+export KEYTEST_OUTFILE=out.txt
+export KEYTEST_INFILE=in-sample.txt
+if [ "$1" != "" ]; then
+    KEYTEST_INFILE="$1";
+fi
+
+export LYX_PID=`pidof lyx`
+export MAX_DROP=0
+export LYX_WINDOW_NAME=$(wmctrl -l | grep LyX | sed -e 's/.*\(LyX: .*\)$/\1/')
+export MAX_LOOPS=1
+export LYX_EXE=../../src/lyx
+
+$KEYTEST

Proprietà modificate su: run-test.sh
___________________________________________________________________
Added: svn:executable
   + *

Index: in-sample.txt
===================================================================
--- in-sample.txt	(revisione 0)
+++ in-sample.txt	(revisione 0)
@@ -0,0 +1,12 @@
+TestBegin
+KK: H
+KK: e
+KK: l
+KK: l
+KK: o
+KK: W
+KK: o
+KK: r
+KK: l
+KK: d
+TestEnd

Reply via email to