Salome HOME
Improve test procedure for source, patch and prepare commands sprint-03
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Fri, 18 Mar 2016 09:19:28 +0000 (10:19 +0100)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Fri, 18 Mar 2016 09:19:28 +0000 (10:19 +0100)
19 files changed:
commands/prepare.py
commands/source.py
complete_sat.sh
data/products/PRODUCT_ARCHIVE.pyconf
data/products/PRODUCT_CVS.pyconf
data/products/PRODUCT_DEV.pyconf [new file with mode: 0644]
data/products/PRODUCT_FIXED.pyconf
data/products/PRODUCT_GIT.pyconf [new file with mode: 0644]
data/products/PRODUCT_SVN.pyconf
data/products/PRODUCT_UNKNOWN.pyconf [new file with mode: 0644]
src/product.py
test/_testTools/tools.py
test/config/option_value_2.py
test/log/launch_browser.py
test/log/launch_browser2.py [new file with mode: 0644]
test/prepare/test_patch.py [new file with mode: 0644]
test/prepare/test_prepare.py
test/prepare/test_source.py [new file with mode: 0644]
test/run_all.sh

index f46d4b0a2965d64e3d3fa8ab2490de3789f5383b..ece313e64882ca14bcbf0c978ea8f9af2e1c48ec 100644 (file)
@@ -27,6 +27,8 @@ parser.add_option('', 'no_sample', 'boolean', 'no_sample',
     _("do not prepare sample products."))
 parser.add_option('f', 'force', 'boolean', 'force', 
     _("force to prepare the products in development mode."))
+parser.add_option('f', 'force_patch', 'boolean', 'force_patch', 
+    _("force to apply patch to the products in development mode."))
 
 def get_products_list(options, cfg, logger):
     '''method that gives the product list with their informations from 
@@ -83,8 +85,8 @@ def description():
     :return: The text to display for the prepare command description.
     :rtype: str
     '''
-    return _("The prepare command apply the patches on the sources of "
-             "the application products if there is any")
+    return _("The prepare command gets the sources of "
+             "the application products and apply the patches if there is any.")
   
 def run(args, runner, logger):
     '''method that is called when salomeTools is called with prepare parameter.
@@ -112,9 +114,6 @@ def run(args, runner, logger):
         for p_name, __ in products_infos:
             args_product_opt += ',' + p_name
     
-    if args_product_opt == '--product ':
-        args_product_opt = ''
-    
     args_sample = ''
     if options.no_sample:
         args_sample = ' --no_sample'
@@ -139,12 +138,12 @@ def run(args, runner, logger):
 
     # Construct the option to pass to the patch command
     ldev_products = [p for p in products_infos if src.product.product_is_dev(p[1])]
-    if len(ldev_products) > 0:
+    if len(ldev_products) > 0 and not options.force_patch:
         msg = _("Ignoring the following products "
                 "in development mode\n")
         logger.write(src.printcolors.printcWarning(msg), 1)
         for i, (product_name, __) in enumerate(ldev_products):
-            args_product_opt.replace(',' + product_name, '')
+            args_product_opt = args_product_opt.replace(',' + product_name, '')
             end_text = ', '
             if i+1 == len(ldev_products):
                 end_text = '\n'
@@ -154,10 +153,14 @@ def run(args, runner, logger):
         msg = _("Use the --force_patch option to apply the patches anyway\n\n")
         logger.write(src.printcolors.printcWarning(msg), 1)
             
-    
-    args_patch = args_appli + args_product_opt + args_sample
-    
-    # Call the source command that gets the source
-    res_patch = runner.patch(args_patch)
+    if args_product_opt == '--product ':
+        msg = _("Nothing to patch\n")
+        logger.write(msg)
+        res_patch = 0
+    else:
+        args_patch = args_appli + args_product_opt + args_sample
+        
+        # Call the source command that gets the source
+        res_patch = runner.patch(args_patch)
     
     return res_source + res_patch
\ No newline at end of file
index 5e58afaf4aaebbba80befa461717a5339b76d5eb..70d756435ececd679ef9381683e62b7a295ccf12 100644 (file)
@@ -51,6 +51,11 @@ def get_source_for_dev(config, product_info, source_dir, force, logger, pad):
     # get it in checkout mode, else, do not do anything
     # unless the force option is invoked
     if not os.path.exists(product_info.source_dir) or force:
+        # If the source path exists (it means that force option is invoked)
+        # remove the source path
+        if source_dir.exists():
+            source_dir.rm()
+            
         # Call the function corresponding to get the sources with True checkout
         retcode = get_product_sources(config, 
                                      product_info, 
@@ -303,14 +308,9 @@ def get_product_sources(config,
         # skip
         logger.write('%s ...' % _("fixed (ignored)"), 3, False)
         return True  
-    
-    if len(product_info.get_source) == 0:
-        # skip
-        logger.write('%s ...' % _("ignored"), 3, False)
-        return True
 
-    # if the get_source is not in [git, archive, cvs, svn, dir]
-    logger.write(_("Unknown get_mehtod %(get)s for product %(product)s") % \
+    # if the get_source is not in [git, archive, cvs, svn, fixed, native]
+    logger.write(_("Unknown get source method \"%(get)s\" for product %(product)s") % \
         { 'get': product_info.get_source, 'product': product_info.name }, 3, False)
     logger.write(" ... ", 3, False)
     logger.flush()
index b76855511531e8855774b33093b8a6479a573a1e..ac6f8e0a92f37726bf521b2b31c6a72b89945214 100755 (executable)
@@ -150,7 +150,7 @@ _salomeTools_complete()
             return 0
             ;;
         prepare)
-            opts="--product --no_sample --force"
+            opts="--product --no_sample --force --force_patch"
             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
             return 0
             ;;
index 64a9a149e06a8a13659df84e6076b7f795b563b5..04250d8a1df455800ca2df3e9cc6b0c6082696ad 100644 (file)
@@ -1,16 +1,35 @@
-MODULE_ARCHIVE :
+PRODUCT_ARCHIVE :
 {
-       name : "MODULE_ARCHIVE"
+       name : "PRODUCT_ARCHIVE"
     build_source : "cmake"
-    get_source : "archive"
-    git_info:
+    get_source : "native"
+    archive_info:
+    {
+               archive_name : $VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'test-product-4.4.2.tar.gz'
+    }
+    environ :
     {
-        repo : "http://git.salome-platform.org/gitpub/modules/kernel.git"
-        repo_dev : $SITE.prepare.default_git_server_dev + $VARS.sep + $name
+        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
+        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
+            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
+            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
     }
+    depend : []
+    opt_depend : []
+    type : "sample"
+    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    patches : ['/home/salome/salomeTools-4.3.7/data/compil_scripts/patches/scipy.patch', '/export/home/serioja/MODULE_ARCHIVE.patch']
+}
+
+PRODUCT_ARCHIVE_4_4_2 :
+{
+       name : "PRODUCT_ARCHIVE"
+    build_source : "cmake"
+    get_source : "archive"
     archive_info:
     {
-               archive_name : '/data/tmpsalome/salome/prerequis/archives/tclx8.4.tar.bz2'
+               archive_name : $VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'test-product-4.4.2.tar.gz'
     }
     environ :
     {
@@ -24,5 +43,5 @@ MODULE_ARCHIVE :
     type : "sample"
     source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
     build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
-    patches : ['/home/salome/salomeTools-4.3.7/data/compil_scripts/patches/scipy.patch', '/export/home/serioja/MODULE_ARCHIVE.patch']
+    patches : []
 }
\ No newline at end of file
index 17e956fb4c5bf0706c57fe0ff7298b190cb52d8f..a7f6e12f088b901ad3347cc457afe545e18517b9 100644 (file)
@@ -1,4 +1,4 @@
-MODULE_CVS_V6_7_0 :
+PRODUCT_CVS_V6_7_0 :
 {
        name : "MODULE_CVS"
     build_source : "cmake"
diff --git a/data/products/PRODUCT_DEV.pyconf b/data/products/PRODUCT_DEV.pyconf
new file mode 100644 (file)
index 0000000..7666c90
--- /dev/null
@@ -0,0 +1,24 @@
+PRODUCT_DEV :
+{
+       name : "PRODUCT_DEV"
+    build_source : "cmake"
+    get_source : "git"
+    git_info:
+    {
+        repo : $VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'test-product.git'
+        repo_dev : $repo
+    }
+    environ :
+    {
+        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
+        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
+            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
+            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+    }
+    depend : []
+    opt_depend : []
+    type : "sample"
+    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    patches : [$VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'mypatch.patch']
+}
\ No newline at end of file
index 362fea2ea9aa5788899960a31befbf5fad367cc5..4bfc5acfbada8e9c2ce6d8f9e2d91c83fb4235c7 100644 (file)
@@ -1,6 +1,6 @@
-MODULE_FIXED :
+PRODUCT_FIXED :
 {
-       name : "MODULE_FIXED"
+       name : "PRODUCT_FIXED"
        get_source : "fixed"
     environ :
     {
diff --git a/data/products/PRODUCT_GIT.pyconf b/data/products/PRODUCT_GIT.pyconf
new file mode 100644 (file)
index 0000000..e611198
--- /dev/null
@@ -0,0 +1,24 @@
+PRODUCT_GIT :
+{
+       name : "PRODUCT_GIT"
+    build_source : "cmake"
+    get_source : "git"
+    git_info:
+    {
+        repo : $VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'test-product.git'
+        repo_dev : $repo
+    }
+    environ :
+    {
+        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
+        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
+            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
+            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+    }
+    depend : []
+    opt_depend : []
+    type : "sample"
+    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+    patches : []
+}
\ No newline at end of file
index 4856e999ce1d17c2434fbe4f1c1864d8d7487b68..9a657b9506d449e4e9c0c7bf43750155a3826463 100644 (file)
@@ -1,6 +1,6 @@
-MODULE_SVN :
+PRODUCT_SVN :
 {
-       name : "MODULE_SVN"
+       name : "PRODUCT_SVN"
     build_source : "cmake"
     get_source : "svn"
     git_info:
diff --git a/data/products/PRODUCT_UNKNOWN.pyconf b/data/products/PRODUCT_UNKNOWN.pyconf
new file mode 100644 (file)
index 0000000..6821d4b
--- /dev/null
@@ -0,0 +1,18 @@
+PRODUCT_UNKNOWN :
+{
+       name : "PRODUCT_UNKNOWN"
+    build_source : "cmake"
+    get_source : "unknown"
+    environ :
+    {
+        "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
+        "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib"
+            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}"
+            "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"]
+    }
+    depend : []
+    opt_depend : []
+    type : "sample"
+    source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name
+    build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name
+}
\ No newline at end of file
index 6ac6ee9d36c59dd7aa63b298608066cc61f9fbae..ec2f7547758ef3eab496c6f104b15a077959ee15 100644 (file)
@@ -152,8 +152,11 @@ def product_is_sample(product_info):
     :return: True if the product has the sample type, else False
     :rtype: boolean
     '''
-    ptype = product_info.type
-    return ptype.lower() == 'sample'
+    if 'type' in product_info:
+        ptype = product_info.type
+        return ptype.lower() == 'sample'
+    else:
+        return False
 
 def product_is_fixed(product_info):
     '''Know if a product is fixed
index 61de6cfdc9ca1c08380f08a686b02100dcf1d085..a518644559ded66862f9eb2fa1abeb15f4530fa0 100644 (file)
@@ -19,6 +19,7 @@
 import tempfile
 import sys
 import subprocess
+import time
 
 class outRedirection():
     '''redirection of standart output
@@ -62,4 +63,15 @@ def check_proc_existence_and_kill(regex):
         pid = line2[1]
         kill9(pid)
         return pid
-    return 0 
\ No newline at end of file
+    return 0
+
+def check_proc_existence_and_kill_multi(regex, nb_kills, time_between_to_checks = 1):
+    found = False
+    i = 0
+    while not found and i < nb_kills :
+        found = check_proc_existence_and_kill(regex)
+        if found:
+            return found
+        time.sleep(time_between_to_checks)
+        i+=1
+    return 0
\ No newline at end of file
index 20d80eb81ec4232d8c6b7e019da692ba3047ec36..d70ea1f5992a29ddf8041638ba35d0fd48a22cb1 100644 (file)
@@ -60,6 +60,31 @@ class TestConfig(unittest.TestCase):
         # pyunit method to compare 2 str
         self.assertEqual(OK, 'OK')
 
+    def test_option_schema(self):
+        '''Test the display of the right value of "sat config -s"
+        '''
+        
+        OK = 'KO'
+
+        # output redirection
+        my_out = outRedirection()
+
+        # The command to test
+        sat = Sat('')
+        sat.config('-s')
+
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+        
+        
+        if 'INTERNAL' in res:
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
 
 # test launch
 if __name__ == '__main__':
index 793e433bb5c26159670767dab29a05005608a52a..c7f910406596cd921902a1e46e1b0b7d2270a83e 100644 (file)
@@ -41,28 +41,7 @@ sleep_time = 2
 class TestLog(unittest.TestCase):
     '''Test of log command: launch of browser
     '''
-    
-    def test_launch_browser(self):
-        '''Test the launch of browser when invoking the log command
-        '''
-
-        OK = "KO"
-
-        sat = Sat("-oUSER.browser='konqueror'")
-        time.sleep(sleep_time)
-        cmd_log = threading.Thread(target=sat.log, args=('',))
-        cmd_log.start()
-
-        time.sleep(sleep_time)
-
-        browser = sat.cfg.USER.browser
-        pid = check_proc_existence_and_kill(browser + ".*" + "hat\.xml")
-
-        if pid:
-            OK = "OK"
-        # pyunit method to compare 2 str
-        self.assertEqual(OK, "OK")
-        
+           
     def test_write_xmllog(self):
         '''Test the write of xml log when invoking a command
         '''
@@ -241,7 +220,7 @@ class TestLog(unittest.TestCase):
         
         # pyunit method to compare 2 str
         self.assertEqual(OK, "OK")
-
+    
     def test_option_last(self):
         '''Test the option --last
         '''
@@ -268,7 +247,7 @@ class TestLog(unittest.TestCase):
         
         # pyunit method to compare 2 str
         self.assertEqual(OK, "OK")
-
+    
     def test_option_clean(self):
         '''Test the option --clean
         '''
@@ -321,7 +300,8 @@ class TestLog(unittest.TestCase):
         
         # pyunit method to compare 2 str
         self.assertEqual(OK, "OK")
-
+    
+    """
     def test_option_full(self):
         '''Test the option --full
         '''
@@ -348,7 +328,7 @@ class TestLog(unittest.TestCase):
 
         # pyunit method to compare 2 str
         self.assertEqual(OK, "OK")
-
+    """
     def test_description(self):
         '''Test the sat -h log
         '''        
diff --git a/test/log/launch_browser2.py b/test/log/launch_browser2.py
new file mode 100644 (file)
index 0000000..0f70b38
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+#  Copyright (C) 2010-2012  CEA/DEN
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+import unittest
+import os
+import sys
+import threading
+import time
+
+# get execution path
+testdir = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(testdir, '..', '..'))
+sys.path.append(os.path.join(testdir, '..', '_testTools'))
+sys.path.append(os.path.join(testdir, '..', '..','commands'))
+
+from salomeTools import Sat
+from tools import check_proc_existence_and_kill_multi
+import HTMLTestRunner
+
+sleep_time = 2
+
+class TestLog(unittest.TestCase):
+    '''Test of log command: launch of browser
+    '''
+    def test_launch_browser(self):
+        '''Test the launch of browser when invoking the log command
+        '''
+
+        OK = "KO"
+
+        sat = Sat("-oUSER.browser='konqueror'")
+        time.sleep(sleep_time)
+        cmd_log = threading.Thread(target=sat.log, args=('',))
+        cmd_log.start()
+
+        time.sleep(sleep_time)
+
+        browser = sat.cfg.USER.browser
+        pid = check_proc_existence_and_kill_multi(browser + ".*" + "hat\.xml", 10)
+
+        if pid:
+            OK = "OK"
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+
+# test launch
+if __name__ == '__main__':
+    HTMLTestRunner.main()
diff --git a/test/prepare/test_patch.py b/test/prepare/test_patch.py
new file mode 100644 (file)
index 0000000..eb014be
--- /dev/null
@@ -0,0 +1,191 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+#  Copyright (C) 2010-2012  CEA/DEN
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+import unittest
+import os
+import sys
+import shutil
+
+# get execution path
+testdir = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(testdir, '..', '..'))
+sys.path.append(os.path.join(testdir, '..', '_testTools'))
+sys.path.append(os.path.join(testdir, '..', '..','commands'))
+
+from tools import outRedirection
+
+import src.product
+
+from salomeTools import Sat
+import HTMLTestRunner
+
+class TestPatch(unittest.TestCase):
+    '''Test of the patch command
+    '''
+
+    def test_patch_dev(self):
+        '''Test the patch command with a product in dev mode
+        '''
+        OK = 'KO'
+
+        appli = 'appli-test'
+        product_name = 'PRODUCT_DEV'
+
+        sat = Sat("-oUSER.output_level=2")
+               
+        sat.config(appli)
+        
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
+        expected_text = 'HELLO WORLD\n'
+        
+        if os.path.exists(expected_src_dir):
+            shutil.rmtree(expected_src_dir)
+        
+        sat.source(appli + ' --product ' + product_name)
+        
+        f = open(expected_file_path, 'r')
+        text = f.readlines()[0]
+        OK1 = 'KO'
+        if text == expected_text:
+            OK1 = 'OK'
+       
+        sat.patch(appli + ' --product ' + product_name)
+        
+        new_expected_text = 'HELLO WORLD MODIFIED\n'
+        f = open(expected_file_path, 'r')
+        text = f.readlines()[0]
+        
+        OK2 = 'KO'
+        if text == new_expected_text:
+            OK2 = 'OK'         
+
+        if (OK1, OK2)==('OK', 'OK'):
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_no_sources_found(self):
+        '''Test the patch command with a product with no sources found
+        '''
+        OK = 'KO'
+
+        appli = 'appli-test'
+        product_name = 'PRODUCT_DEV'
+
+        sat = Sat('')
+        sat.config(appli)
+        
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        
+        if os.path.exists(expected_src_dir):
+            shutil.rmtree(expected_src_dir)
+               
+        # output redirection
+        my_out = outRedirection()
+        
+        sat.patch(appli + ' --product ' + product_name)
+        
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+        
+        if "No sources found for the " + product_name +" product" in res:
+            OK = 'OK'
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_no_patch(self):
+        '''Test the patch command with a product without patch
+        '''
+        OK = 'KO'
+
+        appli = 'appli-test'
+        product_name = 'PRODUCT_ARCHIVE'
+
+        sat = Sat()
+                      
+        sat.source(appli + ' --product ' + product_name)
+               
+        # output redirection
+        my_out = outRedirection()
+        
+        sat.patch(appli + ' --product ' + product_name)
+        
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+        
+        if "No patch for the " + product_name +" product" in res:
+            OK = 'OK'
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_invalid_patch(self):
+        '''Test the patch command with a product with a not valid patch
+        '''
+        OK = 'KO'
+
+        appli = 'appli-test'
+        product_name = 'PRODUCT_DEV'
+
+        sat = Sat("-oPRODUCTS.PRODUCT_DEV.patches=['/']")
+                      
+        sat.source(appli + ' --product ' + product_name)
+               
+        # output redirection
+        my_out = outRedirection()
+        
+        sat.patch(appli + ' --product ' + product_name)
+        
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+        
+        if "Not a valid patch" in res:
+            OK = 'OK'
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_description(self):
+        '''Test the sat -h patch
+        '''        
+
+        OK = "KO"
+
+        import patch
+        
+        if "The patch command apply the patches on the sources of" in patch.description():
+            OK = "OK"
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+
+# test launch
+if __name__ == '__main__':
+    HTMLTestRunner.main()
index 64c2c86002fc8d8d3009596ec06c78fbc329273d..f03b6c895b3990407fe9675d81fa315ddbc89c65 100644 (file)
@@ -19,7 +19,7 @@
 import unittest
 import os
 import sys
-import io
+import shutil
 
 # get execution path
 testdir = os.path.dirname(os.path.realpath(__file__))
@@ -27,33 +27,106 @@ sys.path.append(os.path.join(testdir, '..', '..'))
 sys.path.append(os.path.join(testdir, '..', '_testTools'))
 sys.path.append(os.path.join(testdir, '..', '..','commands'))
 
+import src
+
+from tools import outRedirection
+
 from salomeTools import Sat
 import HTMLTestRunner
 
-sleep_time = 3
-
-class TestLog(unittest.TestCase):
+class TestPrepare(unittest.TestCase):
     '''Test of the prepare command
     '''
-    
+
+    def test_prepare_dev(self):
+        '''Test the prepare command with a product in dev mode
+        '''
+        OK = 'KO'
+
+        appli = 'appli-test'
+        product_name = 'PRODUCT_DEV'
+
+        sat = Sat()
+               
+        sat.config(appli)
+        
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
+        expected_text = 'HELLO WORLD\n'
+        
+        if os.path.exists(expected_src_dir):
+            shutil.rmtree(expected_src_dir)
+        
+        sat.prepare(appli + ' --product ' + product_name)
+        
+        f = open(expected_file_path, 'r')
+        text = f.readlines()[0]
+        if text == expected_text:
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
     def test_prepare_all(self):
-        '''Test the prepare command with many ways to prepare
+        '''Test the prepare command with all products
         '''
-       
-        OK = "KO"
+        OK = 'KO'
+
+        appli = 'appli-test'
+        product_name = 'PRODUCT_DEV'
 
         sat = Sat()
+        sat.config(appli)
+        
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
+        expected_text = 'HELLO WORLD\n'
+        
+        if os.path.exists(expected_src_dir):
+            shutil.rmtree(expected_src_dir)
+        
+        sat.prepare(appli)
+        
+        f = open(expected_file_path, 'r')
+        text = f.readlines()[0]
+        if text == expected_text:
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
 
+    def test_prepare_option_sample_and_force(self):
+        '''Test the prepare command with all products
+        '''
+        OK = 'KO'
+
+        appli = 'appli-test'
+
+        sat = Sat()
+        sat.config(appli)
+       
         try:
-            sat.prepare('appli-test')
-            OK = "OK"
+            sat.prepare(appli + " --no_sample --force")
+            OK = 'OK'
         except:
             pass
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_description(self):
+        '''Test the sat -h prepare
+        '''        
+
+        OK = "KO"
+
+        import prepare
         
+        if "The prepare command gets the sources" in prepare.description():
+            OK = "OK"
 
         # pyunit method to compare 2 str
         self.assertEqual(OK, "OK")
-        
 
 # test launch
 if __name__ == '__main__':
diff --git a/test/prepare/test_source.py b/test/prepare/test_source.py
new file mode 100644 (file)
index 0000000..12831ef
--- /dev/null
@@ -0,0 +1,266 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+#  Copyright (C) 2010-2012  CEA/DEN
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+import unittest
+import os
+import sys
+import shutil
+
+# get execution path
+testdir = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(testdir, '..', '..'))
+sys.path.append(os.path.join(testdir, '..', '_testTools'))
+sys.path.append(os.path.join(testdir, '..', '..','commands'))
+
+from tools import outRedirection
+
+import src.product
+
+from salomeTools import Sat
+import HTMLTestRunner
+
+class TestSource(unittest.TestCase):
+    '''Test of the source command
+    '''
+    
+    def test_source_archive(self):
+        '''Test the source command with archive product
+        '''
+        appli = 'appli-test'
+        product_name = 'PRODUCT_ARCHIVE'
+
+        sat = Sat()
+        sat.source(appli + ' --product ' + product_name)
+
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
+        expected_text = 'HELLO WORLD\n'
+
+        f = open(expected_file_path, 'r')
+        text = f.read()
+
+        # pyunit method to compare 2 str
+        self.assertEqual(text, expected_text)
+        
+    def test_source_git(self):
+        '''Test the source command with git product
+        '''
+        appli = 'appli-test'
+        product_name = 'PRODUCT_GIT'
+
+        sat = Sat()
+        sat.source(appli + ' --product ' + product_name)
+
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
+        expected_text = 'HELLO WORLD\n'
+
+        f = open(expected_file_path, 'r')
+        text = f.read()
+
+        # pyunit method to compare 2 str
+        self.assertEqual(text, expected_text)
+
+    def test_source_cvs(self):
+        '''Test the source command with cvs product
+        '''
+        appli = 'appli-test'
+        product_name = 'PRODUCT_CVS'
+
+        sat = Sat()
+        sat.source(appli + ' --product ' + product_name)
+
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_file_path = os.path.join(expected_src_dir, 'README.FIRST.txt')
+        expected_text = 'Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE\n'
+
+        f = open(expected_file_path, 'r')
+        text = f.readlines()[0]
+
+        # pyunit method to compare 2 str
+        self.assertEqual(text, expected_text)
+    
+    """
+    def test_source_svn(self):
+        '''Test the source command with svn product
+        '''
+        OK = 'KO'
+        
+        appli = 'appli-test'
+        product_name = 'PRODUCT_SVN'
+
+        sat = Sat()
+        sat.source(appli + ' --product ' + product_name)
+
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_file_path = os.path.join(expected_src_dir, 'scripts', 'README')
+        expected_text = 'this directory contains scripts used by salomeTool'
+
+        f = open(expected_file_path, 'r')
+        text = f.readlines()[0]
+        
+        if expected_text in text:
+            OK = 'OK'
+         
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+    """
+
+    def test_source_native(self):
+        '''Test the source command with native product
+        '''
+        OK = 'KO'
+        
+        appli = 'appli-test'
+        product_name = 'PRODUCT_NATIVE'
+
+        sat = Sat()
+        sat.source(appli + ' --product ' + product_name)
+
+        expected_src_dir = os.path.join(sat.cfg.APPLICATION.out_dir, 'SOURCES', product_name)
+        if not os.path.exists(expected_src_dir):
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_source_fixed(self):
+        '''Test the source command with fixed product
+        '''
+        OK = 'KO'
+        
+        appli = 'appli-test'
+        product_name = 'PRODUCT_FIXED'
+
+        sat = Sat()
+        sat.source(appli + ' --product ' + product_name)
+
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
+
+        if os.path.exists(expected_src_dir):
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+        
+    def test_source_unknown(self):
+        '''Test the source command with unknown product
+        '''
+        OK = 'KO'
+
+        # output redirection
+        my_out = outRedirection()
+
+        appli = 'appli-test'
+        product_name = 'PRODUCT_UNKNOWN'
+
+        sat = Sat()
+        sat.source(appli + ' --product ' + product_name)
+
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+
+        if "Unknown get source method" in res:
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_source_dev(self):
+        '''Test the source command with a product in dev mode
+        '''
+        OK = 'KO'
+
+        appli = 'appli-test'
+        product_name = 'PRODUCT_DEV'
+
+        sat = Sat()
+               
+        sat.config(appli)
+        
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
+        expected_text = 'HELLO WORLD\n'
+        
+        if os.path.exists(expected_src_dir):
+            shutil.rmtree(expected_src_dir)
+        
+        sat.source(appli + ' --product ' + product_name)
+        
+        f = open(expected_file_path, 'r')
+        text = f.readlines()[0]
+        OK1 = 'KO'
+        if text == expected_text:
+            OK1 = 'OK'
+
+        # output redirection
+        my_out = outRedirection()
+        
+        sat.source(appli + ' --product ' + product_name)
+        
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+
+        OK2 = 'KO'
+        if "source directory already exists" in res:
+            OK2 = 'OK'        
+
+        # output redirection
+        my_out = outRedirection()
+        
+        sat.source(appli + ' --product ' + product_name + ' --force')
+        
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+
+        OK3 = 'KO'
+        if "source directory already exists" not in res:
+            OK3 = 'OK'         
+
+        if (OK1, OK2, OK3)==('OK', 'OK', 'OK'):
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_description(self):
+        '''Test the sat -h source
+        '''        
+
+        OK = "KO"
+
+        import source
+        
+        if "gets the sources of the application" in source.description():
+            OK = "OK"
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+
+# test launch
+if __name__ == '__main__':
+    HTMLTestRunner.main()
index 3de79953dee0d39f3d03961459e5a8485c36a1b2..bec400b6124024eab27bc528e30d54962d3eb39d 100755 (executable)
 #  License along with this library; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
+rm -rf .coverage htmlcov
+
 coverage run --source=../commands/config.py    config/option_value.py > test_res.html
 coverage run --source=../commands/config.py -a config/option_value_2.py >> test_res.html
 coverage run --source=../commands/config.py -a config/create_user_pyconf.py >> test_res.html
 coverage run --source=../commands/config.py -a config/option_copy.py >> test_res.html
 coverage run --source=../commands/config.py -a config/option_edit.py >> test_res.html
 coverage run --source=../commands/config.py,../commands/log.py,../src/xmlManager.py,../src/logger.py -a log/launch_browser.py >> test_res.html
+coverage run --source=../commands/config.py,../commands/log.py,../src/xmlManager.py,../src/logger.py -a log/launch_browser2.py >> test_res.html
+coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../src/product.py -a prepare/test_source.py >> test_res.html
+coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../src/product.py -a prepare/test_patch.py >> test_res.html
 coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../src/product.py -a prepare/test_prepare.py >> test_res.html
 coverage html
+
+#firefox test_res.html htmlcov/index.html