configurationengine/source/plugins/common/ConeCommandPlugin/commandplugin/tests/unittest_commandml_plugin.py
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 import unittest, os, shutil
       
    18 
       
    19 import __init__	
       
    20 from cone.public import exceptions,plugin,api
       
    21 from cone.storage import filestorage
       
    22 from cone.confml import implml
       
    23 from testautomation.base_testcase import BaseTestCase
       
    24 from commandplugin import commandml
       
    25 
       
    26 # Hardcoded value of testdata folder that must be under the current working dir
       
    27 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    28 temp_dir  = os.path.join(ROOT_PATH, "temp")
       
    29 testdata  = os.path.join(ROOT_PATH,'project')
       
    30 
       
    31 class TestCommandPlugin(BaseTestCase):    
       
    32     def test_example_parse_prj(self):
       
    33         fs = filestorage.FileStorage(testdata)
       
    34         p = api.Project(fs)
       
    35         config = p.get_configuration('product.confml')
       
    36         impls = plugin.get_impl_set(config,'\.commandml$')
       
    37         
       
    38     def test_generate(self):
       
    39         orig_workdir = os.getcwd()
       
    40         os.chdir(ROOT_PATH)
       
    41         try:
       
    42             OUTPUT_DIR = os.path.join(ROOT_PATH, 'output')
       
    43             self.remove_if_exists(OUTPUT_DIR)
       
    44             
       
    45             fs = filestorage.FileStorage(testdata)
       
    46             p = api.Project(fs)
       
    47             config = p.get_configuration('product.confml')
       
    48             impls = plugin.get_impl_set(config,'file2\.commandml$')
       
    49             impls.output = OUTPUT_DIR
       
    50             impls.generate()
       
    51             
       
    52             self.assert_file_content_equals('hello.log',
       
    53                 "Hello\r\n" +
       
    54                 "Cmd line args: ['-c', 'some_config.txt', '-d', 'some_dir', '-x']\r\n" +
       
    55                 "Env: {'MYVAR': '123'}\r\n")
       
    56             
       
    57             self.assert_file_content_equals('exec_in_output_test.log',
       
    58                 os.path.normpath(OUTPUT_DIR) + '\r\n')
       
    59             
       
    60             # Check that the log file of the command that should not be
       
    61             # executed does not exist
       
    62             self.assertFalse(os.path.exists("should_not_be_created.log"))
       
    63         finally:
       
    64             os.chdir(orig_workdir)
       
    65         
       
    66 if __name__ == '__main__':
       
    67   unittest.main()