configurationengine/source/plugins/example/ConeExamplePlugin/examplemlplugin/tests/unittest_exampleml_impl.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 sys, os, unittest
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
import __init__
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
from cone.public import plugin, api
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
from examplemlplugin.exampleml_reader import ExamplemlReader
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
from examplemlplugin.exampleml_model import Output
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
class TestExamplemlImpl(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
        project_dir = os.path.join(ROOT_PATH, 'project')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
        self.project = api.Project(api.Storage.open(project_dir))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
        self.config = self.project.get_configuration('root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
    def get_impl(self, ref, index):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
        impl_list = plugin.ImplFactory.get_impls_from_file(ref, self.config)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
        return impl_list[index]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
    def test_has_ref(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
        impl = self.get_impl('Layer/implml/test.exampleml', 0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
        self.assertTrue(impl.has_ref(['TestFeature.Value1']))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
        self.assertFalse(impl.has_ref(['TestFeature.Foo']))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
        self.assertFalse(impl.has_ref(['Foo.Bar']))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
    def test_list_output_files(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
        def oj( p2): # oj = output_join
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
            return os.path.normpath(os.path.join('output', p2))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
        impl = self.get_impl('Layer/implml/test.exampleml', 0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
        self.assertEquals(impl.list_output_files(), [oj('test.txt'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
                                                     oj('some/dir/out1.txt'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
                                                     oj('some/dir2/out2.txt')])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
        impl = self.get_impl('Layer/implml/multitest.implml', 0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
        self.assertEquals(impl[0].list_output_files(), [oj('multitest1_1.txt'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
                                                     oj('multitest1_2.txt')])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
        impl = self.get_impl('Layer/implml/multitest.implml', 0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
        self.assertEquals(impl[1].list_output_files(), [oj('multitest2_1.txt'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
                                                     oj('multitest2_2.txt')])