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