0
|
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 |
"""
|
|
18 |
Test the configuration
|
|
19 |
"""
|
|
20 |
import unittest
|
|
21 |
import string
|
|
22 |
import StringIO
|
|
23 |
import sys,os
|
|
24 |
|
|
25 |
from cone.public import api,exceptions,settings
|
|
26 |
|
|
27 |
import ConfigParser
|
|
28 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
29 |
|
|
30 |
configdata = \
|
|
31 |
'''
|
|
32 |
[DEFAULT]
|
|
33 |
output_root=output
|
|
34 |
output_subdir=
|
|
35 |
plugin_output=
|
|
36 |
output=%(output_root)s/%(output_subdir)s/%(plugin_output)s
|
|
37 |
|
|
38 |
plugin_targets = 'rofs2','rofs3'
|
|
39 |
|
|
40 |
generate_targets = 'rofs3'
|
|
41 |
generate_layers = -1
|
|
42 |
generate_impls =
|
|
43 |
|
|
44 |
|
|
45 |
[CRML]
|
|
46 |
plugin_output=%(plugin_output)s/private/1234567
|
|
47 |
tags={target : [%(plugin_targets)s]}
|
|
48 |
|
|
49 |
[CONTENT]
|
|
50 |
tags={target : ['rofs2','rofs3','uda']}
|
|
51 |
|
|
52 |
[ROFS3]
|
|
53 |
output_subdir=rofs3
|
|
54 |
'''
|
|
55 |
|
|
56 |
imagedefault = \
|
|
57 |
'''
|
|
58 |
[DEFAULT]
|
|
59 |
subdir=content
|
|
60 |
foobar=fs/content
|
|
61 |
'''
|
|
62 |
|
|
63 |
class TestConfigParser(unittest.TestCase):
|
|
64 |
def tearDown(self):
|
|
65 |
settings.SettingsFactory.clear()
|
|
66 |
|
|
67 |
def test_config_parser_from_string(self):
|
|
68 |
config = ConfigParser.ConfigParser()
|
|
69 |
config.readfp(StringIO.StringIO(configdata))
|
|
70 |
config.readfp(StringIO.StringIO(imagedefault))
|
|
71 |
self.assertEquals(config.get('ROFS3','output'),'output/rofs3/')
|
|
72 |
self.assertEquals(config.get('CRML','tags'),"{target : ['rofs2','rofs3']}")
|
|
73 |
|
|
74 |
def test_get_parser(self):
|
|
75 |
settings.SettingsFactory.defaultconfig = os.path.join(ROOT_PATH,'test_defaults.cfg')
|
|
76 |
s = settings.SettingsFactory.cone_parser()
|
|
77 |
cs = settings.ConeSettings(s)
|
3
|
78 |
self.assertEquals(s.get('DEFAULT','output'),'//')
|
0
|
79 |
|
|
80 |
def test_cone_settings(self):
|
|
81 |
settings.SettingsFactory.defaultconfig = os.path.join(ROOT_PATH,'test_defaults.cfg')
|
|
82 |
s = settings.SettingsFactory.cone_parser()
|
|
83 |
cs = settings.ConeSettings(s)
|
3
|
84 |
self.assertEquals(cs.get('output'),'//')
|
0
|
85 |
self.assertEquals(cs.get('foobar'),None)
|
|
86 |
self.assertEquals(cs.get('foobar', 'test'),'test')
|
|
87 |
|
|
88 |
def test_cone_settings_with_invalid_section(self):
|
|
89 |
settings.SettingsFactory.defaultconfig = os.path.join(ROOT_PATH,'test_defaults.cfg')
|
|
90 |
settings.SettingsFactory.configsettings = None
|
|
91 |
s = settings.SettingsFactory.cone_parser()
|
|
92 |
cs = settings.ConeSettings(s,'FOOBAR')
|
3
|
93 |
self.assertEquals(cs.get('output'),'//')
|
0
|
94 |
self.assertEquals(cs.get('foobar'),None)
|
|
95 |
self.assertEquals(cs.get('foobar', 'test'),'test')
|
|
96 |
self.assertEquals(cs.get('output','',{'output_subdir':'content',
|
3
|
97 |
'output_subdir':'content'}),'/content/')
|
0
|
98 |
|
|
99 |
if __name__ == '__main__':
|
|
100 |
unittest.main()
|
|
101 |
|