Salome HOME
Add tests for clean command
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 23 May 2016 13:27:48 +0000 (15:27 +0200)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 23 May 2016 13:27:48 +0000 (15:27 +0200)
test/environ/test_environ.py
test/prepare/test_clean.py [new file with mode: 0644]
test/prepare/test_res.html [new file with mode: 0644]
test/run_all.sh

index 7677017707b29f104bd3c133e1b74efbdef0b7d5..f7820e1a5398547c5c3d16e84d72e24672da3812 100644 (file)
@@ -145,7 +145,7 @@ class TestSource(unittest.TestCase):
         OK = 'KO'
         
         appli = 'appli-test'
-        shell = 'batch'
+        shell = 'bat'
         file_env_name = 'env_launch.bat'
         
         sat = Sat()
diff --git a/test/prepare/test_clean.py b/test/prepare/test_clean.py
new file mode 100644 (file)
index 0000000..910899d
--- /dev/null
@@ -0,0 +1,210 @@
+#!/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
+
+# 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
+
+from salomeTools import Sat
+import HTMLTestRunner
+
+import src.product
+
+class TestClean(unittest.TestCase):
+    '''Test of the clean command
+    '''
+
+    def test_clean_no_args(self):
+        '''Test the clean command with no arguments (nothing to clean)
+        '''
+        OK = 'KO'
+
+        appli = 'appli-test'
+
+        sat = Sat()
+
+        # output redirection
+        my_out = outRedirection()
+        
+        sat.clean(appli)
+        
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+        
+        if "Nothing to suppress" in res:
+            OK = 'OK'
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_clean_sources(self):
+        '''Test the clean of sources
+        '''
+        OK = "KO"
+
+        appli = 'appli-test'
+        product_name = "PRODUCT_GIT"
+
+        sat = Sat()      
+        
+        # Make sure the sources exist
+        sat.prepare(appli + " -p " + product_name)
+        
+        # Call the command
+        sat.clean(appli + " -p " + product_name + " --sources", batch=True)
+           
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        
+        if not os.path.exists(expected_src_dir):
+            OK = "OK"
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+
+    def test_clean_build(self):
+        '''Test the clean of build
+        '''
+        OK = "KO"
+
+        appli = 'appli-test'
+        product_name = "PRODUCT_GIT"
+
+        sat = Sat()      
+        
+        # Make sure the build exists
+        sat.prepare(appli + " -p " + product_name)
+        sat.configure(appli + " -p " + product_name)
+        
+        # Call the command
+        sat.clean(appli + " -p " + product_name + " --build", batch=True)
+           
+        expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir
+        
+        if not os.path.exists(expected_build_dir):
+            OK = "OK"
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+
+    def test_clean_install(self):
+        '''Test the clean of install
+        '''
+        OK = "KO"
+
+        appli = 'appli-test'
+        product_name = "PRODUCT_GIT"
+
+        sat = Sat()      
+        
+        # Make sure the build exists
+        sat.prepare(appli + " -p " + product_name)
+        sat.configure(appli + " -p " + product_name)
+        
+        # Call the command
+        sat.clean(appli + " -p " + product_name + " --install", batch=True)
+           
+        expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
+        
+        if not os.path.exists(expected_install_dir):
+            OK = "OK"
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+
+    def test_clean_all(self):
+        '''Test the clean of all (build, src, install)
+        '''
+        OK = "KO"
+
+        appli = 'appli-test'
+        product_name = "PRODUCT_GIT"
+
+        sat = Sat()      
+        
+        # Make sure the build exists
+        sat.prepare(appli + " -p " + product_name)
+        sat.compile(appli + " -p " + product_name)
+        
+        # Call the command
+        sat.clean(appli + " -p " + product_name + " --all", batch=True)
+           
+        expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
+        expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        
+        if not os.path.exists(expected_install_dir) and not os.path.exists(expected_build_dir) and not os.path.exists(expected_src_dir):
+            OK = "OK"
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+
+    def test_clean_sources_without_dev(self):
+        '''Test the clean with sources_without_dev option
+        '''
+        OK = "KO"
+
+        appli = 'appli-test'
+        product_name = "PRODUCT_GIT"
+        product_name2 = "PRODUCT_DEV"
+
+        sat = Sat()      
+        
+        # Make sure the build exists
+        sat.prepare(appli + " -p " + product_name + "," + product_name2)
+        
+        # Call the command
+        sat.clean(appli + " -p " + product_name + " --sources_without_dev", batch=True)
+           
+        expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
+        expected_src_dir2 = src.product.get_product_config(sat.cfg, product_name2).source_dir
+        
+        if not os.path.exists(expected_src_dir) and os.path.exists(expected_src_dir2):
+            OK = "OK"
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+
+
+    def test_description(self):
+        '''Test the sat -h clean
+        '''        
+
+        OK = "KO"
+
+        import clean
+        
+        if "The clean command suppress the source, build, or install" in clean.description():
+            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_res.html b/test/prepare/test_res.html
new file mode 100644 (file)
index 0000000..7c1e13f
--- /dev/null
@@ -0,0 +1,12 @@
+No file to run: 'config/option_value.py'
+No file to run: 'config/option_value_2.py'
+No file to run: 'config/create_user_pyconf.py'
+No file to run: 'config/option_copy.py'
+No file to run: 'config/option_edit.py'
+No file to run: 'log/launch_browser.py'
+No file to run: 'log/launch_browser2.py'
+No file to run: 'prepare/test_source.py'
+No file to run: 'prepare/test_patch.py'
+No file to run: 'prepare/test_prepare.py'
+No file to run: 'prepare/test_clean.py'
+No file to run: 'environ/test_environ.py'
index 38b003a857f3cd24c577dc23c9575de91cfb87d2..2245059e89f8dc72920fc09c35b43c940acbf9cb 100755 (executable)
@@ -28,6 +28,7 @@ coverage run --source=../commands/config.py,../commands/log.py,../src/xmlManager
 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 run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../commands/clean.py,../src/product.py -a prepare/test_clean.py >> test_res.html
 coverage run --source=../commands/config.py,../commands/environ.py,../src/environment.py,../src/fileEnviron.py -a environ/test_environ.py >> test_res.html
 coverage html