def test_create_configuration_with_sequence_and_set_value_via_column(self):
        fea= api.FeatureSequence("foo")
        fea.add_feature(api.Feature('child1'))
        fea.add_feature(api.Feature('child2'))
        fea.add_feature(api.Feature('child3'))
        config = api.Configuration('foo.confml')
        config.add_feature(fea)
        dview = config.get_default_view()
        foofea = dview.get_feature('foo')
        # Test adding a data row with array
        foofea.value = [['1','2','3'],['4','5','6'],['7','8','9']]
        self.assertEquals(foofea.get_value(), [['1','2','3'],
                                               ['4','5','6'],
                                               ['7','8','9']
                                               ])

        api.set_column_value(foofea, 'child1', ['0','0','0'])
        self.assertEquals(foofea.get_value(), [['0','2','3'],
                                               ['0','5','6'],
                                               ['0','8','9']
                                               ])
        self.assertRaises(exceptions.ConeException, api.set_column_value, foofea, 'child2', 'over')
        self.assertRaises(exceptions.ConeException, api.set_column_value, foofea, 'child2', ['0','0','0', 'over'])
        foofea.child3.value = ['0','0','0'] 
        self.assertEquals(foofea.get_value(), [['0','2','0'],
                                               ['0','5','0'],
                                               ['0','8','0']
                                               ])
Ejemplo n.º 2
0
 def test_view_add_features_and_get_matching_features(self):
     view = api.View("view1")
     view.add_feature(api.Feature("feature1"))
     view.add_feature(api.Feature("feature2"), "com.nokia.s60")
     view.com.nokia.s60.feature2.add_feature(api.Feature("feature21"))
     self.assertEquals(view.get_feature("com.nokia.s60.feature2"),
                       view.com.nokia.s60.feature2)
 def test_create_configuration_with_sequence_and_add_sequence_value_directly(self):
     fea= api.FeatureSequence("foo")
     fea.add_feature(api.Feature('child1'))
     fea.add_feature(api.Feature('child2'))
     fea.add_feature(api.Feature('child3'))
     config = api.Configuration('foo.confml')
     config.add_feature(fea)
     dview = config.get_default_view()
     foofea = dview.get_feature('foo')
     # Test adding a data row with array
     foofea.set_value([['1','2','3'],
                      ['4','5','6'],
                      ['7','8','9']
                      ])
     self.assertEquals(len(foofea.get_data()), 3)
     self.assertEquals(foofea.get_value(), [['1','2','3'],
                                            ['4','5','6'],
                                            ['7','8','9']
                                            ])
     
     # Check the data element values
     data_elem_values = [(d.fqr, d.value) for d in config._traverse(type=api.Data)]
     self.assertEquals(data_elem_values,
         [('foo', None),
          ('foo.child1', '1'),
          ('foo.child2', '2'),
          ('foo.child3', '3'),
          ('foo', None),
          ('foo.child1', '4'),
          ('foo.child2', '5'),
          ('foo.child3', '6'),
          ('foo', None),
          ('foo.child1', '7'),
          ('foo.child2', '8'),
          ('foo.child3', '9'),])
 def test_get_set_template_single_data_level(self):
     # Create a sequence feature with only a single level of sub-features
     # (i.e. no sub-sub-features)
     config = api.Configuration('foo.confml')
     seq = api.FeatureSequence("seq")
     seq.add_feature(api.Feature('child1'))
     seq.add_feature(api.Feature('child2'))
     seq.add_feature(api.Feature('child3'))
     config.add_feature(seq)
     
     # Add a template for the sequence with the data elements under it
     # in a different order than what the features were defined in
     template_data = api.Data(ref='seq', template=True)
     template_data.add(api.Data(ref='child2', value='foo2'))
     template_data.add(api.Data(ref='child3', value='foo3'))
     template_data.add(api.Data(ref='child1', value='foo1'))
     config.add_data(template_data)
     
     # Get the template data (should be in order)
     dview = config.get_default_view()
     seq = dview.get_feature('seq')
     self.assertEquals(seq.get_template(), ['foo1', 'foo2', 'foo3'])
     
     seq.set_template(['x1', 'x2', 'x3'])
     self.assertEquals(seq.get_template(), ['x1', 'x2', 'x3'])
     
     seq.set_template(None)
     self.assertEquals(seq.get_template(), None)
     
     # Test attempting to set invalid template data
     self.assertRaises(TypeError, seq.set_template, 'foo')
     self.assertRaises(ValueError, seq.set_template, [])
     self.assertRaises(ValueError, seq.set_template, ['foo', 'bar'])
     self.assertRaises(ValueError, seq.set_template, [['foo', 'x'], 'bar'])
    def test_sequence_add_data_and_set_template(self):
        # Create a simple configuration with a sequence feature
        config = api.Configuration('foo.confml')
        fea = api.Feature('fea')
        config.add_feature(fea)
        seq = api.FeatureSequence("seq")
        fea.add_feature(seq)
        seq.add_feature(api.Feature('child1'))
        seq.add_feature(api.Feature('child2'))
        
        sequence = config.get_default_view().get_feature('fea.seq')
        
        # Check that initially the sequence is empty
        self.assertEquals(sequence.get_template(), None)
        self.assertEquals(sequence.value, [])
        
        # Add some data and check again
        sequence.add_sequence(['row1', 'foo'])
        sequence.add_sequence(['row2', 'foo']) 
        self.assertEquals(sequence.get_template(), None)
        self.assertEquals(sequence.value, [['row1', 'foo'],
                                           ['row2', 'foo']])

        # Setting the template should not affect the data
        sequence.set_template(['t1', 't2'])
        self.assertEquals(sequence.get_template(), ['t1', 't2'])
        self.assertEquals(sequence.value, [['row1', 'foo'],
                                           ['row2', 'foo']])
        
        sequence.set_template(['T1', 'T2'])
        sequence.add_sequence(['row3', 'foo'])
        self.assertEquals(sequence.get_template(), ['T1', 'T2'])
        self.assertEquals(sequence.value, [['row1', 'foo'],
                                           ['row2', 'foo'],
                                           ['row3', 'foo']])
    def test_create_feature_seq_and_access_feature_value_with_property(self):
        config = api.Configuration('foo.confml')
        fea= api.FeatureSequence("foo")
        fea.add_feature(api.Feature('child1'))
        fea.add_feature(api.Feature('child11'),'child1')
        fea.add_feature(api.Feature('child2'))
        fea.add_feature(api.Feature('child3'))
        config.add_feature(fea)
        dview = config.get_default_view()
        foofea = dview.get_feature('foo')
        # Test adding a data row with array
        foofea.set_value([[['1'],'2','3'],
                         [['4'],'5','6'],
                         [['7'],'8','9']
                         ])
        self.assertEquals(foofea.value, [[['1'],'2','3'],
                                         [['4'],'5','6'],
                                         [['7'],'8','9']
                                        ])

        foofea.value = [[['1'],'2','3'],
                         [['7'],'8','9']
                        ]
        
        self.assertEquals(foofea.data[0].value,[['1'],'2','3'])
        self.assertEquals(foofea.data[1].value,[['7'],'8','9'])
        self.assertEquals(foofea.data[1][1].value,'8')
        self.assertEquals(foofea.get_value(), [[['1'],'2','3'],
                                               [['7'],'8','9']
                                               ])
        self.assertEquals(foofea.child1.child11.value,['1','7'])
        self.assertEquals(foofea.child1.value,[['1'],['7']])
Ejemplo n.º 7
0
    def test_dumps_and_loads_configuration_hierarchy_with_data(self):
        root = api.Configuration("root.confml")
        layer = api.Configuration("layer1")
        conf = api.Configuration("test")
        conf.add_feature(api.Feature("feature1"))
        conf.add_feature(api.Feature("feature2"))
        conf.feature1.add_feature(api.Feature("feature11"))
        conf.feature1.add_feature(api.Feature("feature12"))
        conf.feature1.set_value(1)
        conf.feature2.set_value(2)
        layer.add_configuration(conf)
        root.add_configuration(layer)
        root.add_configuration(api.Configuration("layer2"))
        root.get_default_view().feature1.feature11.set_value("testing11")
        root.get_default_view().feature1.set_value("test1")
        dumped = persistentdictionary.DictWriter().dumps(root)
        root2 = persistentdictionary.DictReader().loads(dumped)
        self.assertEquals(root.list_all_features(), root2.list_all_features())
        self.assertEquals(root2.get_default_view().feature1.get_value(),
                          "test1")
        self.assertEquals(root2.get_default_view().feature2.get_value(), 2)
        self.assertEquals(
            root2.get_default_view().feature1.feature11.get_value(),
            "testing11")

        self.assertEquals([
            data.find_parent(type=api.Configuration).get_path()
            for data in root2.get_all_datas()
        ], ['test', 'test', 'layer2', 'layer2'])
    def test_create_configuration_with_sequence_and_mapping_properties(self):
        fea = api.FeatureSequence("SequenceSetting", mapKey='KeySubSetting', mapValue="ValueSubSetting")
        fea.add_feature(api.Feature('KeySubSetting'))
        fea.add_feature(api.Feature('ValueSubSetting'))
        
        config = api.Configuration('foo.confml')
        config.add_feature(fea)
        dview = config.get_default_view()
        seqfea = dview.get_feature("SequenceSetting")

        self.assertEquals(seqfea.mapKey, "KeySubSetting")
        self.assertEquals(seqfea.mapValue, "ValueSubSetting")
        #add item 1
        data = api.Data(ref='SequenceSetting')
        data._add(api.Data(ref='KeySubSetting',value='Default'))
        data._add(api.Data(ref='ValueSubSetting',value='Default value'))
        seqfea.add_data(data)
        
        #add item 2
        data1 = api.Data(ref='SequenceSetting', policy='append')
        data1._add(api.Data(ref='KeySubSetting',value='Key 1'))
        data1._add(api.Data(ref='ValueSubSetting',value='Value 1'))
        seqfea.add_data(data1)
        
        self.assertEquals(len(seqfea.get_data()), 2)
Ejemplo n.º 9
0
 def test_create_featuresequence_and_get_empty_data(self):
     conf = api.Configuration("foo/foo.confml")
     conf.add_feature(api.FeatureSequence('feature1'))
     conf.add_feature(api.Feature('child1'), 'feature1')
     conf.add_feature(api.Feature('child2'), 'feature1')
     conf.add_feature(api.Feature('child3'), 'feature1')
     self.assertEquals(conf.get_feature('feature1').get_data(), [])
     self.assertEquals(conf.get_feature('feature1').get_value(), [])
 def test_create_feature_seq_get_sequence_parent(self):
     fea= api.FeatureSequence("foo")
     fea.add_feature(api.Feature('child1'))
     fea.add_feature(api.Feature('child11'),'child1')
     fea.add_feature(api.Feature('child2'))
     fea.add_feature(api.Feature('child3'))
     self.assertEquals(fea.child1.get_sequence_parent(), fea)
     self.assertEquals(fea.child1.child11.get_sequence_parent(), fea)
 def test_create_subfeature_and_get_namespace(self):
     fea= api.Feature("foo")
     fea.add_feature(api.Feature("bar"))
     bar = fea.get_feature("bar")        
     self.assertTrue(bar)
     self.assertEquals(bar.get_ref(),"bar")
     self.assertEquals(bar.namespace,"foo")
     self.assertEquals(bar.fqr,"foo.bar")
 def test_clone_feature_sequence(self):
     fea= api.FeatureSequence("foo")
     fea.add_feature(api.Feature('child1'))
     fea.add_feature(api.Feature('child2'))
     fea.add_feature(api.Feature('child3'))
     fea2 = fea._clone(recursion=True)
     self.comparefeatures(fea,fea2)
     self.assertEquals(fea.list_features(),fea2.list_features())
 def test_create_feature_with_children(self):
     fea= api.FeatureSequence("foo")
     fea.add_feature(api.Feature('child1'))
     fea.add_feature(api.Feature('child2'))
     fea.add_feature(api.Feature('child3'))
     self.assertEquals(fea.list_features(),['child1','child2','child3'])
     self.assertEquals(fea.get_column_features()[0].ref,'child1')
     self.assertEquals(fea.get_column_features()[1].ref,'child2')
     self.assertEquals(fea.get_column_features()[2].ref,'child3')
 def test_create_configuration_with_sequence_and_get_default_view(self):
     fea= api.FeatureSequence("foo")
     fea.add_feature(api.Feature('child1'))
     fea.add_feature(api.Feature('child2'))
     fea.add_feature(api.Feature('child3'))
     config = api.Configuration('foo.confml')
     config.add_feature(fea)
     dview = config.get_default_view()
     self.assertEquals(dview.list_all_features(),['foo','foo.child1','foo.child2','foo.child3'])
Ejemplo n.º 15
0
    def test_dumps_and_loads(self):
        conf = api.Configuration("test.confml")
        conf.add_feature(api.Feature("feature1"))
        conf.add_feature(api.Feature("feature2"))
        conf.feature1.add_feature(api.Feature("feature11"))
        conf.feature1.add_feature(api.Feature("feature12"))
        dumped = persistentdictionary.DictWriter().dumps(conf)

        conf2 = persistentdictionary.DictReader().loads(dumped)
        self.assertEquals(conf.list_all_features(), conf2.list_all_features())
 def test_create_subfeature_and_get_namespace_with_config(self):
     conf =  api.Configuration("test.confml", namespace="com.nokia.s60")
     conf.add_feature(api.Feature("foo"))
     fea= conf.get_feature("foo")
     fea.add_feature(api.Feature("bar"))
     bar = fea.get_feature("bar")        
     self.assertTrue(bar)
     self.assertEquals(bar.get_ref(),"bar")
     self.assertEquals(bar.namespace,"com.nokia.s60.foo")
     self.assertEquals(bar.fqr,"com.nokia.s60.foo.bar")
Ejemplo n.º 17
0
 def test_add_features_and_remove_all(self):
     conf = api.Configuration("foo/foo.confml")
     fea = api.Feature('feature1')
     conf.add_feature(fea)
     conf.add_feature(api.Feature('feature2'))
     conf.add_feature(api.Feature('feature3'))
     conf.add_feature(api.Feature('feature4'))
     for fearef in conf.list_features():
         conf.remove_feature(fearef)
     self.assertEquals(conf.list_all_features(), [])
Ejemplo n.º 18
0
    def test_add_feature_hierarchy_and_get_default_view(self):
        root = api.Configuration("data/simple.confml")
        conf = api.Configuration("test/root.confml")
        root.add_configuration(conf)
        conf2 = api.Configuration("test2/root.confml", namespace="com.nokia")
        root.add_configuration(conf2)
        conf.add_feature(api.Feature("group1"))
        conf.add_feature(api.Feature("group2"))
        conf.add_feature(api.Feature("feature1"))
        conf.group1.add_feature(api.Feature("group21"))
        conf.group1.group21.add_feature(api.Feature("feature211"))
        conf.group1.group21.add_feature(api.Feature("feature212"))
        conf.feature1.add_feature(api.Feature("feature11"))
        conf2.add_feature(api.Feature("wlan"))
        conf2.add_feature(api.Feature("bluetooth"))
        self.assertEquals(conf.list_all_features(), [
            'group1', 'group1.group21', 'group1.group21.feature211',
            'group1.group21.feature212', 'group2', 'feature1',
            'feature1.feature11'
        ])
        dview = conf.get_default_view()
        self.assertEquals(dview.list_features(),
                          ['group1', 'group2', 'feature1'])

        self.assertEquals(dview.list_groups(), ['com'])
        self.assertEquals(dview.list_all_features(), [
            'group1', 'group1.group21', 'group1.group21.feature211',
            'group1.group21.feature212', 'group2', 'feature1',
            'feature1.feature11', 'com.nokia.wlan', 'com.nokia.bluetooth'
        ])
Ejemplo n.º 19
0
 def test_dumps_root_configuration(self):
     root = api.Configuration("root", namespace="com.nokia")
     conf = root.create_configuration("foo/root.confml")
     conf.add_feature(api.Feature("feature1"))
     conf.add_feature(api.Feature("feature2"))
     conf.feature1.add_feature(api.Feature("feature11"))
     conf.feature1.add_feature(api.Feature("feature12"))
     dumped = persistentdictionary.DictWriter().dumps(root)
     dict = dumped['Configuration']['dict']
     self.assertEquals(dict['ref'], 'root')
     self.assertEquals(dict['namespace'], 'com.nokia')
Ejemplo n.º 20
0
 def test_add_features_and_add_data_via_features(self):
     conf = api.Configuration("foo/foo.confml")
     conf.add_feature(api.Feature('feature1'))
     conf.add_feature(api.Feature('feature2'))
     conf.add_feature(api.Feature('feature3'))
     conf.add_feature(api.Feature('feature4'))
     conf.add_feature(api.Feature('feature12'), 'feature1')
     conf.feature1.set_value(123)
     conf.feature1.feature12.set_value("test")
     self.assertEquals(conf.feature1.get_value(), 123)
     self.assertEquals(conf.feature1.feature12.get_value(), "test")
 def test_compare_features(self):
     fea1= api.Feature("foo")
     fea2= api.Feature("foo")
     fea3= api.Feature("foo", type='boolean')
     fea4= api.Feature("foo", bar='yes')
     fea5= api.Feature("foo", bar='yes')
     self.assertTrue(fea1._compare(fea2))
     self.assertFalse(fea1._compare(fea3))
     self.assertTrue(fea1._compare(fea4))
     self.assertTrue(fea5._compare(fea4, ['bar']))
     self.assertTrue(fea1._compare(fea2, ['bar']))
 def test_clone_feature_with_options(self):
     fea= api.Feature("foo")
     fea.add_feature(api.Feature("child1",type='selection'))
     fea.add_feature(api.Feature("child2",type='int'))
     fea.child1.create_option('one','1')
     fea.child1.create_option('two','2')
     fea.child1.create_option('three','3')
     fea2 = fea._clone(recursion=True)
     self.comparefeatures(fea,fea2)
     self.comparefeatures(fea.get_feature('child1'),fea2.get_feature('child1'))
     self.assertEquals(fea.child1.list_options(),fea2.child1.list_options())
Ejemplo n.º 23
0
 def test_view_get_matching_features_with_list(self):
     view = api.View("view1")
     view.add_feature(api.Feature("feature1", type='boolean'))
     view.add_feature(api.Feature("feature2"))
     view.add_feature(api.Feature("feature11", type='boolean'), "feature1")
     view.add_feature(api.Feature("feature12"), "feature1")
     self.assertEquals(view.get_features(["feature2", "feature1"]),
                       [view.feature2, view.feature1])
     self.assertEquals(
         view.get_features(["feature2", "feature1.*"]),
         [view.feature2, view.feature1.feature11, view.feature1.feature12])
     self.assertEquals(view.get_features([""]), [])
 def test_create_feature_seq_and_access_empty_data(self):
     config = api.Configuration('foo.confml')
     fea= api.FeatureSequence("foo")
     fea.add_feature(api.Feature('child1'))
     fea.add_feature(api.Feature('child11'),'child1')
     fea.add_feature(api.Feature('child2'))
     fea.add_feature(api.Feature('child3'))
     config.add_feature(fea)
     dview = config.get_default_view()
     foofea = dview.get_feature('foo')
     foofea.value = []
     self.assertEquals(foofea.value, [])
 def test_create_feature_proxy(self):
     fea= api.Feature("foo", name="foo bar")
     feaproxy = api._FeatureProxy("foo",fea)
     self.assertTrue(feaproxy.get_ref(),"foo")
     self.assertEquals(feaproxy.namespace,"")
     self.assertEquals(feaproxy.fqr,"foo")
     self.assertEquals(feaproxy.name,"foo bar")
     feaproxy.add_feature(api.Feature("bar", name="bar man"))
     self.assertTrue(feaproxy.bar.get_ref(),"bar")
     self.assertEquals(feaproxy.bar.namespace,"foo")
     self.assertEquals(feaproxy.bar.fqr,"foo.bar")
     self.assertEquals(feaproxy.bar.name,"bar man")
Ejemplo n.º 26
0
 def test_view_add_features_with_view_add_feature(self):
     view = api.View("view1")
     view.add_feature(api.Feature("feature1"))
     view.add_feature(api.Feature("feature2"), "com.nokia.s60")
     view.com.nokia.s60.feature2.add_feature(api.Feature("feature21"))
     self.assertEquals(
         sorted(view.list_all_features()),
         sorted([
             'feature1',
             'com.nokia.s60.feature2',
             'com.nokia.s60.feature2.feature21',
         ]))
Ejemplo n.º 27
0
 def test_add_features_and_remove_one(self):
     conf1 = api.Configuration("foo/foo.confml")
     fea = api.Feature('feature1')
     fea2 = api.Feature('feature12')
     fea2.add_feature(api.Feature('feature121'))
     fea.add_feature(api.Feature('feature11'))
     fea.add_feature(fea2)
     conf1.add_feature(fea)
     conf1.remove_feature('feature1.feature12')
     self.assertEquals(conf1.list_all_features(),
                       ['feature1', 'feature1.feature11'])
     fea.remove_feature('feature11')
     self.assertEquals(conf1.list_all_features(), ['feature1'])
 def test_set_value_method_for_sequence(self):
     config = api.Configuration('foo.confml')
     fea = api.Feature('Some')
     config.add_feature(fea)
     seq = api.FeatureSequence("Sequence")
     fea.add_feature(seq)
     seq.add_feature(api.Feature('Feature'))
     
     seq = config.get_default_view().get_feature('Some.Sequence')
     value = [['foo'], ['bar']]
     seq.set_value(value)
     
     self.assertEquals(seq.value, [['foo'], ['bar']])
     self.assertEquals(seq.Feature.value, ['foo', 'bar'])
Ejemplo n.º 29
0
    def test_add_feature_normal_and_get_default_view(self):
        conf = api.Configuration("simple.confml")
        conf.add_feature(api.Feature("feature1"))
        conf.add_feature(api.Feature("feature2"))
        conf.add_feature(api.Feature("feature11"), 'feature1')
        view = conf.get_default_view()

        self.assertEquals(view.list_all_features(), [
            'feature1',
            'feature1.feature11',
            'feature2',
        ])
        self.assertEquals(
            view.get_feature('feature1.feature11')._obj._parent, conf.feature1)
Ejemplo n.º 30
0
 def test_add_features_feature_hiararchy_and_then_to_configurations(self):
     conf1 = api.Configuration("foo/foo.confml")
     fea = api.Feature('feature1')
     fea2 = api.Feature('feature12')
     fea2.add_feature(api.Feature('feature121'))
     fea.add_feature(api.Feature('feature11'))
     fea.add_feature(fea2)
     self.assertEquals(fea.list_all_features(),
                       ['feature11', 'feature12', 'feature12.feature121'])
     conf1.add_feature(fea)
     self.assertEquals(conf1.list_all_features(), [
         'feature1', 'feature1.feature11', 'feature1.feature12',
         'feature1.feature12.feature121'
     ])