configurationengine/source/plugins/common/integration-test/unittest_generate.py
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
child 4 0951727b8815
--- a/configurationengine/source/plugins/common/integration-test/unittest_generate.py	Fri Mar 12 08:30:17 2010 +0200
+++ b/configurationengine/source/plugins/common/integration-test/unittest_generate.py	Tue Aug 10 14:29:28 2010 +0300
@@ -18,7 +18,7 @@
 # @author Lasse Salo
 
 import sys, os, shutil, unittest
-import __init__
+
 from testautomation.base_testcase import BaseTestCase
 from testautomation import zip_dir
 
@@ -27,7 +27,7 @@
 if sys.platform == "win32":
     CONE_SCRIPT = "cone.cmd"
 else:
-    CONE_SCRIPT = "cone.sh"
+    CONE_SCRIPT = "cone"
 
 def get_cmd(action='generate'):
     """Return the command used to run the ConE sub-action"""
@@ -42,6 +42,17 @@
         cmd = 'python "%s" %s' % (os.path.normpath(os.path.join(SOURCE_ROOT, 'scripts/cone_tool.py')), action)
         return cmd
 
+def get_uses_layer_test_project():
+    # If running from the working copy
+    dir1 = os.path.normpath(os.path.join(ROOT_PATH, '../ConeRulePlugin/ruleplugin/evals/tests/layer_filtering_project'))
+    if os.path.isdir(dir1): return dir1
+    
+    # If running from standalone
+    dir2 = os.path.normpath(os.path.join(ROOT_PATH, 'testdata/uses_layer_test_project'))
+    if os.path.isdir(dir2): return dir2
+    
+    raise RuntimeError("layers_used() test project found neither in '%s' nor '%s'!" % (dir1, dir2))
+
 class TestCommonGenerateAllImplsOnLastLayer(BaseTestCase):
     
     def _prepare_workdir(self, workdir):
@@ -67,6 +78,133 @@
         self.assert_exists_and_contains_something(project_zip)
         
         self._run_test_generate_all_impls_on_last_layer('temp/gen_ll2', project_zip)
+
+    def test_uses_layers_rule(self):
+        project_dir = get_uses_layer_test_project()
+        self.assert_exists_and_contains_something(project_dir)
+        
+        orig_workdir = os.getcwd()
+        workdir = self._prepare_workdir("temp/uses_layers_test")
+        os.chdir(workdir)
+        
+        try:
+            cmd = '%s -p "%s" --output output --add-setting-file imaker_variantdir.cfg' % (get_cmd(), project_dir)
+            self.run_command(cmd)
+            
+            self.assert_file_contents_equal(
+                os.path.join(ROOT_PATH, "testdata/uses_layers_test_expected.txt"),
+                "output/uses_layers_test.txt",
+                ignore_endline_style=True)
+        finally:
+            os.chdir(orig_workdir)
+            
+    def test_override_templateml_outputattribs_from_cmd_line(self):
+        project_dir = os.path.join(ROOT_PATH, 'testdata', 'templateml_test_project')
+        
+        #Added because of known bug #1018 (test data missing)
+        # Remove after fix ->
+        if os.path.isdir(project_dir):
+            if len(os.listdir(project_dir)) == 0:
+                self.fail("Path '%s' exists (is a directory) but does not contain anything)" % project_dir)
+        elif os.path.isfile(project_dir):
+            if os.stat(project_dir).st_size == 0:
+                self.fail("Path '%s' exists (is a file) but does not contain anything)" % project_dir)
+        else:
+            self.fail("Known bug #1018: Test data missing. Path '%s' does not exist" % project_dir)
+        # Remove after fix <-
+        
+        self.assert_exists_and_contains_something(project_dir)
+        
+        workdir = os.getcwd()
+        workdir = self._prepare_workdir(os.path.join('temp','gen_tmplml_out_from_cmd_line'))
+        
+        logfile = os.path.join(workdir, 'cone.log')
+        
+        file1 = os.path.join(workdir,'setdir','setfile1.txt')
+        file2 = os.path.join(workdir,'setdir','setfile2.txt')        
+        
+        cmd = ['%(cone_cmd)s',
+               '-p "%(project)s"',
+               '-c root.confml',
+               '--output "%(output)s"',
+               '--log-file="%(log_file)s"',
+               '--all-layers',
+               '--set=Tempfeature.Outputfile1=setfile1.txt',
+               '--set=Tempfeature.Outputfile2=setfile2.txt',
+               '--set=Tempfeature.Outputdir=setdir',
+               '--set=Tempfeature.Encoding=UTF-16',
+               '--set=Tempfeature.BOM=false',
+               '--set=Tempfeature.Newline=unix',]
+        cmd = ' '.join(cmd) % {'cone_cmd':      get_cmd(),
+                               'project':       project_dir,
+                               'output':        workdir,
+                               'log_file':      logfile}
+
+        self.run_command(cmd)
+        
+        self.assert_exists_and_contains_something(os.path.join(workdir,'setdir'))
+        self.assert_file_contains(file1, ['TempFeature.Outputfile1:  setfile1.txt',
+                                          'TempFeature.Outputdir:    setdir',
+                                          'TempFeature.Encoding:     UTF-16',
+                                          'TempFeature.BOM:          false',
+                                          'TempFeature.Newline:      unix'],
+                                          encoding='UTF-16')
+        self.assert_file_contains(file2, ['TempFeature.Outputfile2:  setfile2.txt',
+                                          'TempFeature.Outputdir:    setdir',
+                                          'TempFeature.Encoding:     UTF-8',
+                                          'TempFeature.BOM:          true',
+                                          'TempFeature.Newline:      win'])
+        
+
+    def test_set_tempvariables_as_templateml_outputattribs(self):
+        project_dir = os.path.join(ROOT_PATH, 'testdata', 'templateml_test_project')
+        
+        #Added because of known bug #1018 (test data missing)
+        # Remove after fix ->
+        if os.path.isdir(project_dir):
+            if len(os.listdir(project_dir)) == 0:
+                self.fail("Path '%s' exists (is a directory) but does not contain anything)" % project_dir)
+        elif os.path.isfile(project_dir):
+            if os.stat(project_dir).st_size == 0:
+                self.fail("Path '%s' exists (is a file) but does not contain anything)" % project_dir)
+        else:
+            self.fail("Known bug #1018: Test data missing. Path '%s' does not exist" % project_dir)
+        # Remove after fix <-
+        
+        self.assert_exists_and_contains_something(project_dir)
+        
+        workdir = os.getcwd()
+        workdir = self._prepare_workdir(os.path.join('temp','gen_tmplml_out_from_ref'))
+        
+        logfile = os.path.join(workdir, 'cone.log')
+        
+        file1 = os.path.join(workdir,'origdir','orig1.txt')
+        file2 = os.path.join(workdir,'origdir','orig2.txt')
+        
+        cmd = ['%(cone_cmd)s',
+               '-p "%(project)s"',
+               '-c root.confml',
+               '--output "%(output)s"',
+               '--log-file="%(log_file)s"',
+               '--all-layers',]
+        cmd = ' '.join(cmd) % {'cone_cmd':      get_cmd(),
+                               'project':       project_dir,
+                               'output':        workdir,
+                               'log_file':      logfile}
+
+        self.run_command(cmd)
+        
+        self.assert_exists_and_contains_something(os.path.join(workdir,'origdir'))
+        self.assert_file_contains(file1, ['TempFeature.Outputfile1:  orig1.txt',
+                                          'TempFeature.Outputdir:    origdir',
+                                          'TempFeature.Encoding:     ASCII',
+                                          'TempFeature.BOM:          true',
+                                          'TempFeature.Newline:      win'])
+        self.assert_file_contains(file2, ['TempFeature.Outputfile2:  orig2.txt',
+                                          'TempFeature.Outputdir:    origdir',
+                                          'TempFeature.Encoding:     UTF-8',
+                                          'TempFeature.BOM:          true',
+                                          'TempFeature.Newline:      win'])
     
     def _run_test_generate_all_impls_on_last_layer(self, workdir, project):
         # Create a temp workdir and go there to run the test
@@ -83,5 +221,8 @@
         finally:
             os.chdir(orig_workdir)
 
+
+
+
 if __name__ == '__main__':
       unittest.main()