configurationengine/source/plugins/common/ConeCommandPlugin/commandplugin/tests/unittest_commandml_plugin.py
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
    14 # Description: 
    14 # Description: 
    15 #
    15 #
    16 
    16 
    17 import unittest, os, shutil
    17 import unittest, os, shutil
    18 
    18 
    19 import __init__	
    19 # import __init__	
    20 from cone.public import exceptions,plugin,api
    20 from cone.public import plugin, api, utils
    21 from cone.storage import filestorage
    21 from cone.storage import filestorage
    22 from cone.confml import implml
       
    23 from testautomation.base_testcase import BaseTestCase
    22 from testautomation.base_testcase import BaseTestCase
    24 from commandplugin import commandml
       
    25 
    23 
    26 # Hardcoded value of testdata folder that must be under the current working dir
    24 # Hardcoded value of testdata folder that must be under the current working dir
    27 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    25 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    28 temp_dir  = os.path.join(ROOT_PATH, "temp")
    26 temp_dir  = os.path.join(ROOT_PATH, "temp")
    29 testdata  = os.path.join(ROOT_PATH,'project')
    27 testdata  = os.path.join(ROOT_PATH,'project')
    39         orig_workdir = os.getcwd()
    37         orig_workdir = os.getcwd()
    40         os.chdir(ROOT_PATH)
    38         os.chdir(ROOT_PATH)
    41         try:
    39         try:
    42             OUTPUT_DIR = os.path.join(ROOT_PATH, 'output')
    40             OUTPUT_DIR = os.path.join(ROOT_PATH, 'output')
    43             self.remove_if_exists(OUTPUT_DIR)
    41             self.remove_if_exists(OUTPUT_DIR)
       
    42             self.remove_if_exists(['hello.log', 'exec_in_output_test.log',])
    44             
    43             
    45             fs = filestorage.FileStorage(testdata)
    44             fs = filestorage.FileStorage(testdata)
    46             p = api.Project(fs)
    45             p = api.Project(fs)
    47             config = p.get_configuration('product.confml')
    46             config = p.get_configuration('product.confml')
       
    47             context = plugin.GenerationContext(configuration=config,
       
    48                                                output=OUTPUT_DIR)
    48             impls = plugin.get_impl_set(config,'file2\.commandml$')
    49             impls = plugin.get_impl_set(config,'file2\.commandml$')
    49             impls.output = OUTPUT_DIR
    50             #impls.output = OUTPUT_DIR
    50             impls.generate()
    51             impls.generate(context)
    51             
    52             
    52             self.assert_file_content_equals('hello.log',
    53             self.assert_file_content_equals('hello.log',
    53                 "Hello\r\n" +
    54                 "Hello" + os.linesep +
    54                 "Cmd line args: ['-c', 'some_config.txt', '-d', 'some_dir', '-x']\r\n" +
    55                 "Cmd line args: ['-c', 'some_config.txt', '-d', 'some_dir', '-x']" + os.linesep)
    55                 "Env: {'MYVAR': '123'}\r\n")
       
    56             
    56             
    57             self.assert_file_content_equals('exec_in_output_test.log',
    57             self.assert_file_content_equals('exec_in_output_test.log',
    58                 os.path.normpath(OUTPUT_DIR) + '\r\n')
    58                 os.path.normpath(OUTPUT_DIR) + os.linesep)
    59             
    59             
    60             # Check that the log file of the command that should not be
    60             # Check that the log file of the command that should not be
    61             # executed does not exist
    61             # executed does not exist
    62             self.assertFalse(os.path.exists("should_not_be_created.log"))
    62             self.assertFalse(os.path.exists("should_not_be_created.log"))
       
    63             self.assertTrue(os.path.exists(os.path.join(OUTPUT_DIR,"helloworld.txt")))
       
    64             
       
    65             self.assertEquals(len(context.generation_output), 1)
       
    66             self.assertEquals(utils.relpath(context.generation_output[0].name, OUTPUT_DIR), 'helloworld.txt')
       
    67             self.assertEquals(context.generation_output[0].implementation.ref, 'assets/s60/implml/file2.commandml')
    63         finally:
    68         finally:
    64             os.chdir(orig_workdir)
    69             os.chdir(orig_workdir)
       
    70 
    65         
    71         
    66 if __name__ == '__main__':
    72 if __name__ == '__main__':
    67   unittest.main()
    73   unittest.main()