3
|
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 |
#!/usr/bin/env python
|
|
17 |
##
|
|
18 |
# @author Teemu Rytkonen
|
|
19 |
|
4
|
20 |
import os, shutil
|
3
|
21 |
|
|
22 |
import unittest
|
|
23 |
from cone.action import configroot2flat
|
|
24 |
from cone.public import api
|
|
25 |
|
|
26 |
ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
|
|
27 |
|
|
28 |
|
|
29 |
class TestConfigRootFlat(unittest.TestCase):
|
|
30 |
def test_get_flat_configuration_with_empty_config(self):
|
|
31 |
conf = api.Configuration('foo.confml')
|
|
32 |
self.assertEquals(configroot2flat.get_flat_includes(conf), [])
|
|
33 |
|
|
34 |
def test_get_flat_configuration_with_single_config_hierarchy(self):
|
|
35 |
conf = api.Configuration('foo.confml')
|
|
36 |
conf.include_configuration('test1/root.confml')
|
|
37 |
conf.include_configuration('test2/root.confml')
|
|
38 |
conf.include_configuration('test3/root.confml')
|
|
39 |
self.assertEquals(configroot2flat.get_flat_includes(conf), ['test1/root.confml',
|
|
40 |
'test2/root.confml',
|
|
41 |
'test3/root.confml'])
|
|
42 |
|
|
43 |
def test_get_flat_configuration_with_two_level_config_hierarchy(self):
|
|
44 |
prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'temp'), 'w'))
|
|
45 |
rootconf1 = prj.create_configuration('product1_root.confml', True)
|
|
46 |
rootconf2 = prj.create_configuration('product2_root.confml', True)
|
|
47 |
prj.create_configuration('test/one/root.confml', True)
|
|
48 |
fooconf = prj.create_configuration('test/foo.confml', True)
|
|
49 |
rootconf1.create_configuration('layer1/root.confml')
|
|
50 |
rootconf1.create_configuration('layer2/root.confml')
|
|
51 |
rootconf1.create_configuration('layer3/root.confml')
|
|
52 |
fooconf.include_configuration('/product1_root.confml')
|
|
53 |
fooconf.include_configuration('/product2_root.confml')
|
|
54 |
fooconf.include_configuration('/test/one/root.confml')
|
|
55 |
rootconf1.create_configuration('layer5/root.confml')
|
|
56 |
rootconf1.create_configuration('layer6/root.confml')
|
|
57 |
prj.save()
|
|
58 |
self.assertEquals(configroot2flat.get_flat_includes(fooconf), ['layer1/root.confml',
|
|
59 |
'layer2/root.confml',
|
|
60 |
'layer3/root.confml',
|
|
61 |
'layer5/root.confml',
|
|
62 |
'layer6/root.confml',
|
|
63 |
'test/one/root.confml'])
|
4
|
64 |
|
|
65 |
def test_get_flat_configuration_with_nonexistent_files(self):
|
|
66 |
TEMP_DIR = os.path.join(ROOT_PATH,'temp2')
|
|
67 |
if os.path.exists(TEMP_DIR):
|
|
68 |
shutil.rmtree(TEMP_DIR)
|
|
69 |
|
|
70 |
# Create a configuration with some non-existent layers
|
|
71 |
prj = api.Project(api.Storage.open(TEMP_DIR, 'w'))
|
|
72 |
prj.create_configuration('test/one/root.confml', True)
|
|
73 |
|
|
74 |
rootconf1 = prj.create_configuration('product1_root.confml', True)
|
|
75 |
rootconf1.create_configuration('layer1/root.confml')
|
|
76 |
rootconf1.include_configuration('nonexistent1/root.confml')
|
|
77 |
|
|
78 |
rootconf2 = prj.create_configuration('product2_root.confml', True)
|
|
79 |
rootconf2.create_configuration('layer3/root.confml')
|
|
80 |
rootconf2.include_configuration('nonexistent2/root.confml')
|
|
81 |
|
|
82 |
fooconf = prj.create_configuration('test/foo.confml', True)
|
|
83 |
fooconf.include_configuration('/product1_root.confml')
|
|
84 |
fooconf.include_configuration('/product2_root.confml')
|
|
85 |
rootconf1.include_configuration('/nonexistent_product_root.confml')
|
|
86 |
fooconf.include_configuration('/test/one/root.confml')
|
|
87 |
fooconf.include_configuration('nonexistent3/root.confml')
|
|
88 |
prj.save()
|
|
89 |
prj.close()
|
|
90 |
|
|
91 |
action = configroot2flat.ConeConfigroot2FlatAction(
|
|
92 |
project=TEMP_DIR,
|
|
93 |
configs=['test/foo.confml'])
|
|
94 |
action.run()
|
|
95 |
|
|
96 |
prj = api.Project(api.Storage.open(TEMP_DIR, 'r'))
|
|
97 |
fooconf = prj.get_configuration('foo.confml')
|
|
98 |
self.assertEquals(fooconf.list_configurations(),
|
|
99 |
['layer1/root.confml',
|
|
100 |
'nonexistent1/root.confml',
|
|
101 |
'layer3/root.confml',
|
|
102 |
'nonexistent2/root.confml',
|
|
103 |
'test/one/root.confml',
|
|
104 |
'nonexistent3/root.confml'])
|
|
105 |
|