[[nbpython-commits]] [hg] main/contrib: Template work: (1) Add a unit test template, ...

  • From: Tor Norbye < >
  • To:
  • Subject: [[nbpython-commits]] [hg] main/contrib: Template work: (1) Add a unit test template, ...
  • Date: Thu, 21 Oct 2010 08:34:25 -0700

changeset f0513065d822 in main/contrib
details: http://hg.netbeans.org/main/contrib?cmd=changeset;node=f0513065d822
description:
        Template work: (1) Add a unit test template, (2) Change template 
layer names such that you end up with lower case, underscored names 
(new_module) instead of "NewModule" to make things more python'y. Change 
extensions to ftl (freemarker), add user-configurable copyright sections. 
Some description updates.

diffstat:

 python.editor/src/org/netbeans/modules/python/editor/Bundle.properties       
                           |   13 ++-
 python.editor/src/org/netbeans/modules/python/editor/layer.xml               
                           |   32 +++++++--
 
python.editor/src/org/netbeans/modules/python/editor/templates/EmptyModule.html
                         |    4 +
 
python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.html
                    |    2 +-
 python.editor/src/org/netbeans/modules/python/editor/templates/UnitTest.html 
                           |    4 +
 
python.editor/src/org/netbeans/modules/python/editor/templates/emptymodule.py.ftl
                       |    8 ++
 
python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.template
                |    7 ++
 python.editor/src/org/netbeans/modules/python/editor/templates/init.html     
                           |    4 +
 python.editor/src/org/netbeans/modules/python/editor/templates/init.template 
                           |    0 
 
python.editor/src/org/netbeans/modules/python/editor/templates/Module.template
                          |    8 ++-
 
python.editor/src/org/netbeans/modules/python/editor/templates/unittest.py.ftl
                          |   31 +++++++++
 
python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/PythonPackageWizardIterator.java
 |    2 +-
 
python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/pythonPackage.html
               |    4 +-
 python.project/src/org/netbeans/modules/python/project/PythonProject.java    
                           |    8 +-
 
python.project/src/org/netbeans/modules/python/project/templates/NewPythonProjectWizardIterator.java
    |    2 +-
 
python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.form
                |    2 +-
 
python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.java
                |    5 +-
 17 files changed, 110 insertions(+), 26 deletions(-)

diffs (307 lines):

diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/Bundle.properties 
b/python.editor/src/org/netbeans/modules/python/editor/Bundle.properties
--- a/python.editor/src/org/netbeans/modules/python/editor/Bundle.properties
+++ b/python.editor/src/org/netbeans/modules/python/editor/Bundle.properties
@@ -1,13 +1,14 @@
 OpenIDE-Module-Display-Category=Python
 OpenIDE-Module-Name=Python Editor
 OpenIDE-Module-Short-Description=Python Editor
-Templates/Python/pythonPackage=PythonPackage
 text/x-python=Python
-Templates/Other/PythonCompiledTemplate.pyc=Empty PythonCompiled file
-Templates/Python/ExecutableModule.py=Executable Module
-Templates/Python/Module.py=Empty Module
-Templates/Python/pythonPackage=Python Package
-Templates/Python/emptyPyFile=Empty Python File
+#Templates/Other/PythonCompiledTemplate.pyc=Empty PythonCompiled file
+Templates/Python/_main.py=Executable Module
+Templates/Python/_module.py=Module
+Templates/Python/_empty_module.py=Empty Module
+Templates/Python/_package=Python Package
+Templates/Python/_test.py=Unit Test
+Templates/Python/_init.py=Package __init__ File
 Services/MIMEResolver/PythonCompiledResolver.xml=PythonCompiled Files
 Services/MIMEResolver/PythonResolver.xml=Python Files
 
diff --git a/python.editor/src/org/netbeans/modules/python/editor/layer.xml 
b/python.editor/src/org/netbeans/modules/python/editor/layer.xml
--- a/python.editor/src/org/netbeans/modules/python/editor/layer.xml
+++ b/python.editor/src/org/netbeans/modules/python/editor/layer.xml
@@ -359,7 +359,7 @@
     <folder name="Templates">  
         <folder name="Python">           
             <attr name="position" intvalue="1403"/>
-            <file name="ExecutableModule.py" 
url="templates/ExecutableModule.template">
+            <file name="_main.py" url="templates/executable_module.py.ftl">
                 <attr name="position" intvalue="888"/>
                 <attr name="SystemFileSystem.icon" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/resources/pyNode25.png"/>
                 <attr name="SystemFileSystem.localizingBundle" 
stringvalue="org.netbeans.modules.python.editor.Bundle"/>                
@@ -367,7 +367,7 @@
                 <attr name="templateWizardURL" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/templates/ExecutableModule.html"/>
                 <attr name="javax.script.ScriptEngine" 
stringvalue="freemarker"/>
             </file>           
-            <file name="Module.py" url="templates/Module.template">
+            <file name="_module.py" url="templates/module.py.ftl">
                 <attr name="position" intvalue="900"/>
                 <attr name="templateCategory" stringvalue="python"/>
                 <attr name="template" boolvalue="true"/>
@@ -376,8 +376,26 @@
                 <attr name="SystemFileSystem.icon" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/resources/pyNode25.png"/>
                 <attr name="SystemFileSystem.localizingBundle" 
stringvalue="org.netbeans.modules.python.editor.Bundle"/>                
             </file>        
-            <!-- Missing init.htm
-            <file name="init.py" url="templates/init.template">
+            <file name="_empty_module.py" url="templates/emptymodule.py.ftl">
+                <attr name="position" intvalue="905"/>
+                <attr name="templateCategory" stringvalue="python"/>
+                <attr name="template" boolvalue="true"/>
+                <attr name="javax.script.ScriptEngine" 
stringvalue="freemarker"/>
+                <attr name="templateWizardURL" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/templates/EmptyModule.html"/>
+                <attr name="SystemFileSystem.icon" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/resources/pyNode25.png"/>
+                <attr name="SystemFileSystem.localizingBundle" 
stringvalue="org.netbeans.modules.python.editor.Bundle"/>
+            </file>
+            <file name="_test.py" url="templates/unittest.py.ftl">
+                <attr name="position" intvalue="920"/>
+                <attr name="templateCategory" stringvalue="python"/>
+                <attr name="template" boolvalue="true"/>
+                <attr name="javax.script.ScriptEngine" 
stringvalue="freemarker"/>
+                <attr name="templateWizardURL" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/templates/UnitTest.html"/>
+                <attr name="SystemFileSystem.icon" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/resources/pyNode25.png"/>
+                <attr name="SystemFileSystem.localizingBundle" 
stringvalue="org.netbeans.modules.python.editor.Bundle"/>
+                <attr name="templateNamePrefix" stringvalue="New"/>
+            </file>
+            <file name="_init.py" url="templates/init.py.ftl">
                 <attr name="position" intvalue="901"/>
                 <attr name="templateCategory" stringvalue="python"/>
                 <attr name="template" boolvalue="false"/>
@@ -386,10 +404,8 @@
                 <attr name="SystemFileSystem.icon" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/resources/pyNode25.png"/>
                 <attr name="SystemFileSystem.localizingBundle" 
stringvalue="org.netbeans.modules.python.editor.Bundle"/>                
             </file>
-            -->
-            
-            <file name="pythonPackage">
-                <attr name="position" intvalue="905"/>
+            <file name="_package">
+                <attr name="position" intvalue="908"/>
                 <attr name="SystemFileSystem.icon" 
urlvalue="nbresloc:/org/netbeans/modules/python/editor/wizards/pypackage/package.gif"/>
                 <attr name="SystemFileSystem.localizingBundle" 
stringvalue="org.netbeans.modules.python.editor.Bundle"/>
                 <attr name="instantiatingIterator" 
newvalue="org.netbeans.modules.python.editor.wizards.pypackage.PythonPackageWizardIterator"/>
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/EmptyModule.html
 
b/python.editor/src/org/netbeans/modules/python/editor/templates/EmptyModule.html
new file mode 100644
--- /dev/null
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/templates/EmptyModule.html
@@ -0,0 +1,4 @@
+
+<HTML><BODY>
+Creates a new empty Python module.
+</BODY></HTML>
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.html
 
b/python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.html
--- 
a/python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.html
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.html
@@ -7,6 +7,6 @@
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     </head>
     <body>
-        Creates a Module with execution hooks.
+        Creates a module with execution hooks.
     </body>
 </html>
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/UnitTest.html
 
b/python.editor/src/org/netbeans/modules/python/editor/templates/UnitTest.html
new file mode 100644
--- /dev/null
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/templates/UnitTest.html
@@ -0,0 +1,4 @@
+
+<HTML><BODY>
+Creates a new Python unit test.
+</BODY></HTML>
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/emptymodule.py.ftl
 
b/python.editor/src/org/netbeans/modules/python/editor/templates/emptymodule.py.ftl
new file mode 100644
--- /dev/null
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/templates/emptymodule.py.ftl
@@ -0,0 +1,8 @@
+<#-- This is a FreeMarker template -->
+<#-- You can change the contents of the license inserted into
+ #   each template by opening Tools | Templates and editing
+ #   Licenses | Default License  -->
+<#assign licensePrefix = "# ">
+<#include "../Licenses/license-${project.license}.txt">
+
+
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.template
 
b/python.editor/src/org/netbeans/modules/python/editor/templates/executable_module.py.ftl
rename from 
python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.template
rename to 
python.editor/src/org/netbeans/modules/python/editor/templates/executable_module.py.ftl
--- 
a/python.editor/src/org/netbeans/modules/python/editor/templates/ExecutableModule.template
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/templates/executable_module.py.ftl
@@ -1,5 +1,12 @@
 #! /usr/bin/python
 
+<#-- This is a FreeMarker template -->
+<#-- You can change the contents of the license inserted into
+ #   each template by opening Tools | Templates and editing
+ #   Licenses | Default License  -->
+<#assign licensePrefix = "# ">
+<#include "../Licenses/license-${project.license}.txt">
+
 __author__="${user}"
 __date__ ="$${date} ${time}$"
 
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/init.html 
b/python.editor/src/org/netbeans/modules/python/editor/templates/init.html
new file mode 100644
--- /dev/null
+++ b/python.editor/src/org/netbeans/modules/python/editor/templates/init.html
@@ -0,0 +1,4 @@
+
+<HTML><BODY>
+Creates a __init__.py file for a Python package
+</BODY></HTML>
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/init.template
 b/python.editor/src/org/netbeans/modules/python/editor/templates/init.py.ftl
rename from 
python.editor/src/org/netbeans/modules/python/editor/templates/init.template
rename to 
python.editor/src/org/netbeans/modules/python/editor/templates/init.py.ftl
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/Module.template
 
b/python.editor/src/org/netbeans/modules/python/editor/templates/module.py.ftl
rename from 
python.editor/src/org/netbeans/modules/python/editor/templates/Module.template
rename to 
python.editor/src/org/netbeans/modules/python/editor/templates/module.py.ftl
--- 
a/python.editor/src/org/netbeans/modules/python/editor/templates/Module.template
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/templates/module.py.ftl
@@ -1,6 +1,12 @@
+<#-- This is a FreeMarker template -->
+<#-- You can change the contents of the license inserted into
+ #   each template by opening Tools | Templates and editing
+ #   Licenses | Default License  -->
+<#assign licensePrefix = "# ">
+<#include "../Licenses/license-${project.license}.txt">
 
 __author__="${user}"
 __date__ ="$${date} ${time}$"
 
 if __name__ == "__main__":
-    print "Hello";
\ No newline at end of file
+    print "Hello World";
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/templates/unittest.py.ftl
 
b/python.editor/src/org/netbeans/modules/python/editor/templates/unittest.py.ftl
new file mode 100644
--- /dev/null
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/templates/unittest.py.ftl
@@ -0,0 +1,31 @@
+<#-- This is a FreeMarker template -->
+<#-- You can change the contents of the license inserted into
+ #   each template by opening Tools | Templates and editing
+ #   Licenses | Default License  -->
+<#assign licensePrefix = "# ">
+<#include "../Licenses/license-${project.license}.txt">
+
+import unittest
+
+<#assign clsname = name?cap_first?replace('TestCase$', '', 
'ri')?replace('Test$', '', 'ri')>
+
+class  ${clsname}TestCase(unittest.TestCase):
+    #def setUp(self):
+    #    self.foo = ${clsname?cap_first}()
+    #
+
+    #def tearDown(self):
+    #    self.foo.dispose()
+    #    self.foo = None
+
+    def test_${clsname?uncap_first}(self):
+        #assert x != y;
+        #self.assertEqual(x, y, "Msg");
+        # assert_equal("foo", bar)
+        self.fail("TODO: Write test")
+
+#suite = unittest.TestLoader().loadTestsFromTestCase(${clsname}TestCase)
+#unittest.TextTestRunner(verbosity=2).run(suite)
+if __name__ == '__main__':
+    unittest.main()
+
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/PythonPackageWizardIterator.java
 
b/python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/PythonPackageWizardIterator.java
--- 
a/python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/PythonPackageWizardIterator.java
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/PythonPackageWizardIterator.java
@@ -76,7 +76,7 @@
         final Set<FileObject> resultSet = new HashSet<FileObject>();
         FileObject template =
                 Repository.getDefault().getDefaultFileSystem().findResource(
-                "Templates/Python/init.py");
+                "Templates/Python/_init.py");
         FileObject dir = Templates.getTargetFolder(wizard);
         String targetName = Templates.getTargetName(wizard);
         File parent = FileUtil.toFile(dir);
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/pythonPackage.html
 
b/python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/pythonPackage.html
--- 
a/python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/pythonPackage.html
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/wizards/pypackage/pythonPackage.html
@@ -7,7 +7,7 @@
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   </head>
   <body>
-    Replace this with a description what your wizard is supposed to do. This
-    information will be displayed in the New Wizard Description area.
+    A Python package - a directory with an __init__.py file for package
+    initialization.
   </body>
 </html>
diff --git 
a/python.project/src/org/netbeans/modules/python/project/PythonProject.java 
b/python.project/src/org/netbeans/modules/python/project/PythonProject.java
--- 
a/python.project/src/org/netbeans/modules/python/project/PythonProject.java
+++ 
b/python.project/src/org/netbeans/modules/python/project/PythonProject.java
@@ -260,9 +260,11 @@
         };
         
         private static final String[] PRIVILEGED_NAMES = new String[] {
-            "Templates/Python/pythonPackage", // NOI18N
-            "Templates/Python/Module.py", //NOI18N
-            "Templates/Python/ExecutableModule.py", // NOI18N     
+            "Templates/Python/_package", // NOI18N
+            "Templates/Python/_module.py", //NOI18N
+            "Templates/Python/_main.py", // NOI18N
+            "Templates/Python/_empty_module.py", // NOI18N
+            "Templates/Python/_test.py", // NOI18N
         };
         
         public String[] getRecommendedTypes() {
diff --git 
a/python.project/src/org/netbeans/modules/python/project/templates/NewPythonProjectWizardIterator.java
 
b/python.project/src/org/netbeans/modules/python/project/templates/NewPythonProjectWizardIterator.java
--- 
a/python.project/src/org/netbeans/modules/python/project/templates/NewPythonProjectWizardIterator.java
+++ 
b/python.project/src/org/netbeans/modules/python/project/templates/NewPythonProjectWizardIterator.java
@@ -117,7 +117,7 @@
             // main file
             final String mainName = (String) 
descriptor.getProperty(NewPythonProjectWizardIterator.MAIN_FILE);        
             if (mainName != null) {            
-                
resultSet.add(createMainFile(Repository.getDefault().getDefaultFileSystem().findResource(
 "Templates/Python/Module.py"),
+                
resultSet.add(createMainFile(Repository.getDefault().getDefaultFileSystem().findResource(
 "Templates/Python/_module.py"),
                         sourceDir,mainName).getPrimaryFile());
             }
         }
diff --git 
a/python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.form
 
b/python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.form
--- 
a/python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.form
+++ 
b/python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.form
@@ -90,7 +90,7 @@
     </Component>
     <Component class="javax.swing.JTextField" name="mainFileTextField">
       <Properties>
-        <Property name="text" type="java.lang.String" value="Main"/>
+        <Property name="text" type="java.lang.String" value="main"/>
       </Properties>
       <AccessibilityProperties>
         <Property name="AccessibleContext.accessibleName" 
type="java.lang.String" 
editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
diff --git 
a/python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.java
 
b/python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.java
--- 
a/python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.java
+++ 
b/python.project/src/org/netbeans/modules/python/project/templates/PanelOptionsVisual.java
@@ -129,10 +129,11 @@
     }
     
     public void propertyChange (PropertyChangeEvent event) {
+        // The project name isn't very python'y
         if 
(NewPythonProjectWizardIterator.PROP_PROJECT_NAME.equals(event.getPropertyName()))
 {
             String newProjectName = (String) event.getNewValue();            
             this.mainFileTextField.setText (MessageFormat.format(
-                NbBundle.getMessage 
(PanelOptionsVisual.class,"TXT_MainFileName"), new Object[] {newProjectName}
+                NbBundle.getMessage 
(PanelOptionsVisual.class,"TXT_MainFileName"), new Object[] 
{newProjectName.toLowerCase()}
             ));
         }
         if 
(NewPythonProjectWizardIterator.PROP_PROJECT_LOCATION.equals(event.getPropertyName()))
 {
@@ -158,7 +159,7 @@
         createMainCheckBox.setSelected(true);
         org.openide.awt.Mnemonics.setLocalizedText(createMainCheckBox, 
org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_createMainCheckBox"));
 // NOI18N
 
-        mainFileTextField.setText("Main");
+        mainFileTextField.setText("main");
 
         setAsMainCheckBox.setSelected(true);
         org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox, 
org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_setAsMainCheckBox"));
 // NOI18N

[[nbpython-commits]] [hg] main/contrib: Template work: (1) Add a unit test template, ...

Tor Norbye 10/21/2010

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close