[GRASS-SVN] r57171 - grass/trunk/gui/wxpython/core

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 16 06:28:00 PDT 2013


Author: wenzeslaus
Date: 2013-07-16 06:28:00 -0700 (Tue, 16 Jul 2013)
New Revision: 57171

Added:
   grass/trunk/gui/wxpython/core/test.toolboxes_menu.xml
   grass/trunk/gui/wxpython/core/test.toolboxes_menudata.xml
   grass/trunk/gui/wxpython/core/test.toolboxes_user_toolboxes.xml
Modified:
   grass/trunk/gui/wxpython/core/toolboxes.py
Log:
wxGUI/toolboxes: new larger test

Added: grass/trunk/gui/wxpython/core/test.toolboxes_menu.xml
===================================================================
--- grass/trunk/gui/wxpython/core/test.toolboxes_menu.xml	                        (rev 0)
+++ grass/trunk/gui/wxpython/core/test.toolboxes_menu.xml	2013-07-16 13:28:00 UTC (rev 57171)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<toolbox name="TestingMainMenu">
+  <label>Testing menu</label>
+  <items>
+    <subtoolbox name="Region"/>
+    <subtoolbox name="TestingToolboxA"/>
+    <subtoolbox name="MapProjections"/>
+    <subtoolbox name="TestingToolboxB"/>
+  </items>
+</toolbox>


Property changes on: grass/trunk/gui/wxpython/core/test.toolboxes_menu.xml
___________________________________________________________________
Added: svn:mime-type
   + text/xml
Added: svn:eol-style
   + native

Added: grass/trunk/gui/wxpython/core/test.toolboxes_menudata.xml
===================================================================
--- grass/trunk/gui/wxpython/core/test.toolboxes_menudata.xml	                        (rev 0)
+++ grass/trunk/gui/wxpython/core/test.toolboxes_menudata.xml	2013-07-16 13:28:00 UTC (rev 57171)
@@ -0,0 +1,85 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--This is an auto-generated file-->
+<menudata>
+  <menubar>
+    <menu>
+      <label>Region</label>
+      <items>
+        <menuitem>
+          <label>Display region</label>
+          <command>g.region -p</command>
+          <help>Manages the boundary definitions for the geographic region.</help>
+          <keywords>general,settings</keywords>
+          <handler>RunMenuCmd</handler>
+        </menuitem>
+        <menuitem>
+          <label>Set region</label>
+          <command>g.region</command>
+          <help>Manages the boundary definitions for the geographic region.</help>
+          <keywords>general,settings</keywords>
+          <handler>OnMenuCmd</handler>
+        </menuitem>
+      </items>
+    </menu>
+    <menu>
+      <label>&Testing toolbox A</label>
+      <items>
+        <menuitem>
+          <label>Set region</label>
+          <command>g.region</command>
+          <help>Manages the boundary definitions for the geographic region.</help>
+          <keywords>general,settings</keywords>
+          <handler>OnMenuCmd</handler>
+        </menuitem>
+        <separator />
+        <menuitem>
+          <label>Testing unknown module</label>
+          <command>m.unknown</command>
+          <help />
+          <keywords />
+          <handler>OnMenuCmd</handler>
+        </menuitem>
+        <subtoolbox name="QueryRasterMap" />
+      </items>
+    </menu>
+    <menu>
+      <label>Map projections</label>
+      <items>
+        <menuitem>
+          <label>Display map projection</label>
+          <command>g.proj -p</command>
+          <help>Converts co-ordinate system descriptions (i.e. projection information) between various formats (including GRASS format).</help>
+          <keywords>general,projection,create location</keywords>
+          <handler>RunMenuCmd</handler>
+        </menuitem>
+        <menuitem>
+          <label>Manage projections</label>
+          <command>g.proj</command>
+          <help>Prints and manipulates GRASS projection information files (in various co-ordinate system descriptions). Can also be used to create new GRASS locations.</help>
+          <keywords>general,projection,create location</keywords>
+          <handler>OnMenuCmd</handler>
+        </menuitem>
+        <separator />
+        <menuitem>
+          <label>Convert coordinates</label>
+          <command>m.proj</command>
+          <help />
+          <keywords />
+          <handler>OnMenuCmd</handler>
+        </menuitem>
+      </items>
+    </menu>
+    <menu>
+      <label>&Testing toolbox B</label>
+      <items>
+        <menuitem>
+          <label>Set region</label>
+          <command>g.region</command>
+          <help>Manages the boundary definitions for the geographic region.</help>
+          <keywords>general,settings</keywords>
+          <handler>OnMenuCmd</handler>
+        </menuitem>
+      </items>
+    </menu>
+  </menubar>
+</menudata>


Property changes on: grass/trunk/gui/wxpython/core/test.toolboxes_menudata.xml
___________________________________________________________________
Added: svn:mime-type
   + text/xml
Added: svn:eol-style
   + native

Added: grass/trunk/gui/wxpython/core/test.toolboxes_user_toolboxes.xml
===================================================================
--- grass/trunk/gui/wxpython/core/test.toolboxes_user_toolboxes.xml	                        (rev 0)
+++ grass/trunk/gui/wxpython/core/test.toolboxes_user_toolboxes.xml	2013-07-16 13:28:00 UTC (rev 57171)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<toolboxes>
+  <toolbox name="TestingToolboxA">
+    <label>&Testing toolbox A</label>
+    <items>
+      <module-item name="g.region">
+        <label>Set region</label>
+      </module-item>
+      <separator/>
+      <module-item name="m.unknown">
+        <label>Testing unknown module</label>
+      </module-item>
+      <subtoolbox name="QueryRasterMap"/>
+    </items>
+  </toolbox>
+  <toolbox name="TestingToolboxB">
+    <label>&Testing toolbox B</label>
+    <items>
+      <module-item name="g.region">
+        <label>Set region</label>
+      </module-item>
+    </items>
+  </toolbox>
+</toolboxes>
+


Property changes on: grass/trunk/gui/wxpython/core/test.toolboxes_user_toolboxes.xml
___________________________________________________________________
Added: svn:mime-type
   + text/xml
Added: svn:eol-style
   + native

Modified: grass/trunk/gui/wxpython/core/toolboxes.py
===================================================================
--- grass/trunk/gui/wxpython/core/toolboxes.py	2013-07-16 13:27:54 UTC (rev 57170)
+++ grass/trunk/gui/wxpython/core/toolboxes.py	2013-07-16 13:28:00 UTC (rev 57171)
@@ -139,7 +139,7 @@
         return None
 
     if _createPath(path):
-           return path
+        return path
     return None
 
 
@@ -168,30 +168,55 @@
 
     @return ElementTree instance
     """
-    wxguiItems = etree.parse(wxguiItemsFile)
-    moduleItems = etree.parse(moduleItemsFile)
-
     if userDefined and userMainMenuFile:
         mainMenu = etree.parse(userMainMenuFile)
     else:
         mainMenu = etree.parse(mainMenuFile)
+
+    toolboxes = etree.parse(toolboxesFile)
+
+    if userDefined and userToolboxesFile:
+        userToolboxes = etree.parse(userToolboxesFile)
+    else:
+        userToolboxes = None
+
+    wxguiItems = etree.parse(wxguiItemsFile)
+    moduleItems = etree.parse(moduleItemsFile)
+
+    return toolboxes2menudataInternal(mainMenu=mainMenu,
+                                      toolboxes=toolboxes,
+                                      userToolboxes=userToolboxes,
+                                      wxguiItems=wxguiItems,
+                                      moduleItems=moduleItems)
+
+
+def toolboxes2menudataInternal(mainMenu, toolboxes, userToolboxes,
+                               wxguiItems, moduleItems):
+    """!Creates XML file with data for menu.
+
+    Parses toolboxes files from distribution and from users,
+    puts them together, adds metadata to modules and convert
+    tree to previous format used for loading menu.
+
+    @param userDefined use toolboxes defined by user or not (during compilation)
+
+    @return ElementTree instance
+    """
     root = mainMenu.getroot()
-    
+
     userHasToolboxes = False
-    if userDefined and userToolboxesFile:
-        userToolboxes = etree.parse(userToolboxesFile)        
-        # in case user has empty toolboxes file (to avoid genereation)
-        if userToolboxes.findall('.//toolbox'):
-            _expandUserToolboxesItem(root, userToolboxes)
-            _expandToolboxes(root, userToolboxes)
-            userHasToolboxes = True
 
+    # in case user has empty toolboxes file (to avoid genereation)
+    if userToolboxes and userToolboxes.findall('.//toolbox'):
+        _expandUserToolboxesItem(root, userToolboxes)
+        _expandToolboxes(root, userToolboxes)
+        userHasToolboxes = True
+
     if not userHasToolboxes:
         _removeUserToolboxesItem(root)
 
     _expandAddonsItem(root)
-    
-    toolboxes = etree.parse(toolboxesFile)
+
     _expandToolboxes(root, toolboxes)
 
     _expandItems(root, moduleItems, 'module-item')
@@ -232,7 +257,7 @@
 
     @param node tree node where to look for subtoolboxes to be expanded
     @param toolboxes tree of toolboxes to be used for expansion
-    
+
     >>> menu = etree.fromstring('''
     ... <toolbox name="Raster">
     ...   <label>&Raster</label>
@@ -351,7 +376,7 @@
 
 def _expandAddonsItem(node):
     """!Expands tag addons (in main_menu.xml) with currently installed addons.append
-    
+
     Note: there is no mechanism yet to tell the gui to rebuild the menudata.xml
     file when new addons are added/removed.
     """
@@ -488,7 +513,7 @@
 
 def _convertTag(node, old, new):
     """!Converts tag name.
-    
+
     >>> tree = etree.fromstring('<toolboxes><toolbox><items><module-item/></items></toolbox></toolboxes>')
     >>> _convertTag(tree, 'toolbox', 'menu')
     >>> _convertTag(tree, 'module-item', 'menuitem')
@@ -577,7 +602,7 @@
     __builtin__._ = new_translator
 
 
-def test():
+def doc_test():
     """Tests the module using doctest
 
     @return a number of failed tests
@@ -589,6 +614,56 @@
     return doctest.testmod().failed
 
 
+def module_test():
+    """Tests the module using test files included in the current directory and
+    in files from distribution.
+    """
+    toolboxesFile = os.path.join(ETCWXDIR, 'xml', 'toolboxes.xml')
+    userToolboxesFile = 'test.toolboxes_user_toolboxes.xml'
+    menuFile = 'test.toolboxes_menu.xml'
+    wxguiItemsFile = os.path.join(ETCWXDIR, 'xml', 'wxgui_items.xml')
+    moduleItemsFile = os.path.join(ETCWXDIR, 'xml', 'module_items.xml')
+
+    toolboxes = etree.parse(toolboxesFile)
+    userToolboxes = etree.parse(userToolboxesFile)
+    menu = etree.parse(menuFile)
+
+    wxguiItems = etree.parse(wxguiItemsFile)
+    moduleItems = etree.parse(moduleItemsFile)
+
+    tree = toolboxes2menudataInternal(mainMenu=menu,
+                                      toolboxes=toolboxes,
+                                      userToolboxes=userToolboxes,
+                                      wxguiItems=wxguiItems,
+                                      moduleItems=moduleItems)
+    root = tree.getroot()
+    tested = _getXMLString(root)
+    # useful to generate the correct file (uncomment)
+    #sys.stdout.write(_getXMLString(root))
+    #return 0
+
+    menudataFile = 'test.toolboxes_menudata.xml'
+    with open(menudataFile) as correctMenudata:
+        correct = str(correctMenudata.read())
+
+    import difflib
+    differ = difflib.Differ()
+    result = list(differ.compare(correct.splitlines(True),
+                                 tested.splitlines(True)))
+
+    someDiff = False
+    for line in result:
+        if line.startswith('+') or line.startswith('-'):
+            sys.stdout.write(line)
+            someDiff = True
+    if someDiff:
+        print "difference"
+    else:
+        print "OK"
+
+    return 0
+
+
 def main():
     """Converts the toolboxes files on standard paths to the menudata file
 
@@ -604,5 +679,7 @@
 if __name__ == '__main__':
     if len(sys.argv) > 1:
         if sys.argv[1] == 'doctest':
-            sys.exit(test())
+            sys.exit(doc_test())
+        elif sys.argv[1] == 'test':
+            sys.exit(module_test())
     sys.exit(main())



More information about the grass-commit mailing list