def test_read_hcrml_flag(self):
     xml = '<flags Uninitialised="0" Modifiable="0" Persistent="0"/>'
     etree = ElementTree.fromstring(xml)
     flag = self.reader.read_hrcml_flags(etree)
     self.assertEquals(flag.Uninitialised, '0')
     self.assertEquals(flag.Modifiable, '0')
     self.assertEquals(flag.Persistent, '0')
예제 #2
0
    def test_parse_template_filter_2(self):
        class DummyConfiguration(object):
            def get_resource(self, ref):
                class DummyResource(object):
                    def read(self): return ''
                    def close(self): return None
                return DummyResource()
            def get_default_view(self): return None
        reader = templatemlplugin.TemplatemlImplReader('foo/implml/bar.implml', DummyConfiguration())
        reader.fromstring(TEMPML_DOC4)
        
        filters1 = reader.filters
        filter2 = templatemlplugin.Filter()
        filter2.set_code(None)
        filter2.set_name("test_filter")
        filter2.set_path("../../filter/filter.py")
        temp1 = reader.parse_template(ElementTree.fromstring(TEMPML4))
        temp2 = templatemlplugin.TempFile()
        temp2.set_template('')
        temp2.set_path('')

        self.assertEqual(filters1[0].name, filter2.name)
        self.assertEqual(filters1[0].code, filter2.code)
        self.assertEqual(filters1[0].path, filter2.path)
        self.assertEqual(filters1[0], filter2)
        self.assertEqual(temp1.template, temp2.template)
        self.assertEqual(temp1.extensions, temp2.extensions)
        self.assertEqual(temp1.filters, temp2.filters)
        self.assertEqual(temp1, temp2)
 def _run_test_read_invalid_hcrml_output(self, xml, expected_exception):
     try:
         self.reader.doc = ElementTree.fromstring(xml)
         self.reader.read_hcrml_output()
         self.fail("Expected exception not raised!")
     except expected_exception:
         pass
 def _run_test_read_invalid_hcrml_setting(self, xml, expected_exception):
     try:
         etree = ElementTree.fromstring(xml)
         setting = self.reader.read_hcrml_setting(etree)
         self.fail("Expected exception not raised!")
     except expected_exception:
         pass
 def test_parse_subdir_with_definition(self):
     etree = ElementTree.fromstring(
         genconfgml_string.replace("target=\"output\"",
                                   "subdir=\"include\""))
     reader = genconfmlplugin.GenconfmlImplReader()
     subdir = reader.parse_subdir(etree)
     self.assertEquals(subdir, "include")
 def test_read_hcrml_setting(self):
     xml = '<setting ref="hcrexample.DebounceInterval" name="KElmGPIO_DebounceInterval" type="int32" id="0"/>'
     etree = ElementTree.fromstring(xml)
     setting = self.reader.read_hcrml_setting(etree)
     self.assertEquals(setting.ref, 'hcrexample.DebounceInterval')
     self.assertEquals(setting.name, 'KElmGPIO_DebounceInterval')
     self.assertEquals(setting.type, 'int32')
     self.assertEquals(setting.id, 0)
 def test_read_hcrml_output(self):
     xml = '<hcr xmlns="%s"><output file="some/test/file.h" type="header"/></hcr>' % NAMESPACE
     self.reader.doc = ElementTree.fromstring(xml)
     output = self.reader.read_hcrml_output()
     self.assertEquals(output.type, 'header')
     self.assertEquals(output.file, 'some/test/file.h')
     self.assertEquals(output.version, None)
     self.assertEquals(output.read_only, None)
     self.assertEquals(output.categories, [])
 def test_parse_rules(self):
     etree = ElementTree.fromstring(ruleml_string)
     reader = ruleml.RuleImplReader2(None, None)
     rules = reader.parse_rules("", etree)
     self.assertTrue(isinstance(rules[0], relations.ConfigureRelation))
     self.assertTrue(isinstance(rules[1], relations.ConfigureRelation))
     self.assertTrue(rules[0].has_ref('imaker.imagetarget'))
     self.assertFalse(rules[0].has_ref('imakerapi.imagename'))
     self.assertTrue(rules[0].has_ref('imakerapi.outputLocation'))
예제 #9
0
 def fromstring(self, xml_as_string):
     meta = Metadata()
     try:
         etree = ElementTree.fromstring(xml_as_string)
         for elem in etree.getiterator("{%s}property" % self.NAMESPACES[0]):
             (key, value) = self.get_property(elem)
             meta.data[key] = value
     except Exception, e:
         logging.getLogger('cone').warning(
             "Could not read metadata! Exception %s" % (e))
예제 #10
0
 def test_parse_template_from_xinclude(self):
     try:
         reader = templatemlplugin.TemplatemlImplReader()
         reader.fromstring(TEMPML_DOC2)
         
         temp1 = reader.parse_template(ElementTree.fromstring(TEMPML2))
         temp2 = templatemlplugin.TempFile()
         temp2.set_template("include AABBCC")
     except exceptions.ParseError, e:
         self.fail("Known bug: ticket #2007")
 def test_parse_outputs(self):
     etree = ElementTree.fromstring(contentml2_string)
     reader = contentmlparser.Content2Parser()
     outputs = reader.parse_outputs(etree)
     self.assertEquals(outputs[0].dir, 'content')
     self.assertEquals(len(outputs[0].inputs), 1)
     self.assertEquals(outputs[0].inputs[0].dir, 'test')
     self.assertEquals(outputs[0].inputs[0].include, {'pattern': ['prod']})
     self.assertEquals(outputs[1].inputs[0].dir, '${features.inputref}')
     self.assertEquals(outputs[1].dir, '${features.outputref}')
 def fromstring(self, xml_as_string):
     etree = ElementTree.fromstring(xml_as_string)
     # Loop through parsers and try to find a match
     (namespace, elemname) = get_elemname(etree.tag)
     pclass = self.PARSERS.get(namespace, None)
     self.parser = pclass()
     self.desc = self.parser.parse_desc(etree)
     self.outputs = self.parser.parse_outputs(etree)
     self.phase = self.parser.parse_phase(etree)
     self.tags = self.parser.parse_tags(etree)
     return
예제 #13
0
 def test_parse_template(self):
     reader = templatemlplugin.TemplatemlImplReader()
     reader.fromstring(TEMPML_DOC1)
     
     temp1 = reader.parse_template(ElementTree.fromstring(TEMPML1))
     temp2 = templatemlplugin.TempFile()
     temp2.set_template("ABCDF")
     
     self.assertEqual(temp1.template, temp2.template)
     self.assertEqual(temp1.extensions, temp2.extensions)
     self.assertEqual(temp1.filters, temp2.filters)
     self.assertEqual(temp1, temp2)
 def test_parse_inputs_with_files(self):
     etree = ElementTree.fromstring(input_files)
     reader = imageml.ImageImplReader()
     inputs = reader.parse_inputs(etree)
     self.assertEquals(inputs[0].path,'UI/graphics/icon1.bmb')
     self.assertEquals(inputs[0].depth,'8')
     self.assertEquals(inputs[1].path,'UI/graphics/icon2.bmb')
     self.assertEquals(inputs[1].depth,'8')
     self.assertEquals(inputs[2].path,'UI/graphics/icon3.bmb')
     self.assertEquals(inputs[2].depth,'8')
     self.assertEquals(inputs[3].path,'UI/graphics/icon4.bmb')
     self.assertEquals(inputs[3].depth,'8')
 def test_parse_inputs_with_dir(self):
     etree = ElementTree.fromstring(input_dir)
     reader = imageml.ImageImplReader()
     inputs = reader.parse_inputs(etree)
     self.assertEquals(inputs[0].path,'UI/Start-up Animation')
     self.assertEquals(inputs[0].type,'dir')
     self.assertEquals(inputs[0].include, ['bmb$'])
     self.assertEquals(inputs[0].exclude, ['.svn'])
     self.assertEquals(inputs[0].depth,'8')
     self.assertEquals(inputs[0].test,'foo')
     self.assertEquals(inputs[1].path,'UI/Start-up Animation/masks')
     self.assertEquals(inputs[1].depth,'2')
예제 #16
0
 def test_read_outputs(self):
     data = """<?xml version="1.0" encoding="UTF-8"?>
             <printml xmlns="%s">
                 <output file="test1.txt" encoding="UTF-16-LE">Test 1</output>
                 <output file="test2.txt">Test 2</output>
                 <output file="test3.txt"/>
             </printml>""" % self.NAMESPACE
     outputs = self.reader._read_outputs(ElementTree.fromstring(data))
     self.assertEquals(outputs, [
         Output('test1.txt', 'UTF-16-LE', 'Test 1'),
         Output('test2.txt', 'UTF-8', 'Test 2'),
         Output('test3.txt', 'UTF-8', '')
     ])
    def post_process_flattening(self, element):
        """
        Pick just data element and build document out of it
        """

        data_element = element.find("data")
        if data_element == None:
            self.logger.warning('No data to generate!!')
            new_doc = "<?xml version=\"1.0\"?><configuration>" + "</configuration>"
        else:
            new_doc = "<?xml version=\"1.0\"?><configuration>" + ElementTree.tostring(
                data_element) + "</configuration>"
        return ElementTree.fromstring(new_doc)
    def test_read_hcrml_output_with_include(self):
        config = DummyConfiguration()
        resource_ref = 'layer4/hcr_dat.hcrml'

        self.reader = HcrmlReader(resource_ref, config)
        self.reader.doc = ElementTree.fromstring(
            config.get_resource(resource_ref).read())
        output = self.reader.read_hcrml_output()
        self.assertEquals(output.type, 'hcr')
        self.assertEquals(output.file, 'some/test/hcr.dat')
        self.assertEquals(
            sorted([cat.category_uid for cat in output.categories]),
            sorted([0, 1, 2, 3]))
    def test_write_element_fo_file(self):
        '''
        Fix this
        '''
        OUTFILE = os.path.join(ROOT_PATH, 'temp/elementfile.xml')
        if not os.path.exists(os.path.join(ROOT_PATH, 'temp')):
            os.makedirs(os.path.join(ROOT_PATH, 'temp'))
        #fs = filestorage.FileStorage(testdata)
        #p = api.Project(fs)
        #config = p.get_configuration('product.confml')
        #genconfml_plugin = genconfmlplugin.GenconfmlImpl(None, config)
        element = ElementTree.fromstring('<test>kfkadl</test>')

        genconfmlplugin.write_element(element, OUTFILE)
        self.assertTrue(os.path.exists(OUTFILE))
예제 #20
0
    def test_read_output(self):
        data = """<output file="test1.txt" encoding="UTF-16">Test</output>"""
        self.assert_read_output_equals(data,
                                       Output('test1.txt', 'UTF-16', 'Test'))

        data = """<output file="test2.txt">Test</output>"""
        self.assert_read_output_equals(data,
                                       Output('test2.txt', 'UTF-8', 'Test'))

        data = """<output file="test3.txt"/>"""
        self.assert_read_output_equals(data, Output('test3.txt', 'UTF-8', ''))

        data = """<output/>"""
        self.assertRaises(exceptions.ParseError, self.reader._read_output_elem,
                          ElementTree.fromstring(data))
 def test_parse_outputs(self):
     etree = ElementTree.fromstring(imageml_string)
     reader = imageml.ImageImplReader()
     outputs = reader.parse_outputs(etree)
     self.assertEquals(outputs[0].outputpath,'startup.mbm')
     self.assertEquals(outputs[0].extraparams, '/V2')
     self.assertEquals(outputs[0].inputs[0].path,'UI/Start-up Animation')
     self.assertEquals(outputs[0].inputs[0].type,'dir')
     self.assertEquals(outputs[0].inputs[0].include,['bmb$'])
     self.assertEquals(outputs[0].inputs[0].exclude,['.svn'])
     self.assertEquals(outputs[1].outputpath,'shutdown.mbm')
     self.assertEquals(outputs[1].inputs[0].type,'file')
     self.assertEquals(outputs[1].inputs[0].path,'UI/graphics/icon1.bmb')
     self.assertEquals(outputs[1].inputs[1].type,'file')
     self.assertEquals(outputs[1].inputs[1].path,'UI/graphics/icon2.bmb')
     self.assertEquals(outputs[1].inputs[2].type,'file')
     self.assertEquals(outputs[1].inputs[2].path,'UI/graphics/icon3.bmb')
     self.assertEquals(outputs[1].inputs[3].type,'file')
     self.assertEquals(outputs[1].inputs[3].path,'UI/graphics/icon4.bmb')
    def test_read_hcrml_output_with_overlapping_includes(self):
        config = DummyConfiguration()
        resource_ref = 'layer4/hcr_dat.hcrml'

        XML = """<hcr xmlns="%s">
            <output file="hcr.dat" type="hcr">
                <include ref="dummy.hcrml"/>
                <include ref="dummy2.hcrml"/>
                <include ref="layer1/*.hcrml"/>
            </output>
        </hcr>
        """ % NAMESPACE

        self.reader = HcrmlReader(resource_ref, config)
        self.reader.doc = ElementTree.fromstring(XML)
        output = self.reader.read_hcrml_output()
        self.assertEquals(output.type, 'hcr')
        self.assertEquals(output.file, 'hcr.dat')
        self.assertEquals(
            sorted([cat.category_uid for cat in output.categories]),
            sorted([0, 1, 2]))
예제 #23
0
    def get_xinclude_list(self, confml_file_data):
        """
        Read the XInlude element list from a ConfML file and assert that.
        @param confml_file_data: The raw binary data of the ConfML file.
        """
        root_elem = ElementTree.fromstring(confml_file_data)

        # Make sure that we have a ConfML file
        self.assertTrue(
            root_elem.tag
            in ("{http://www.s60.com/xml/confml/1}configuration",
                "{http://www.s60.com/xml/confml/2}configuration"),
            "The root element is not a ConfML configuration element (tag is '%s')"
            % root_elem.tag)

        # Read the xi:include list
        result = []
        for elem in root_elem.findall(
                "{http://www.w3.org/2001/XInclude}include"):
            result.append(elem.get("href"))

        return result
 def test_get_property_with_only_key(self):
     etree = ElementTree.fromstring('<property name="test"/>')
     (key,value) = metadata.MetadataReader().get_property(etree)
     self.assertEquals(key,'test')
     self.assertEquals(value,'')
예제 #25
0
 def assert_read_output_equals(self, data, expected):
     etree = ElementTree.fromstring(data)
     output = self.reader._read_output_elem(etree)
     self.assertEquals(expected, output)
 def test_parse_input_include(self):
     etree = ElementTree.fromstring(input_dir)
     input = etree.find("{%s}input" % 'http://www.s60.com/xml/imageml/1')
     reader = imageml.ImageImplReader()
     include = reader.parse_input_include(input)
     self.assertEquals(include,{'pattern': ['bmb$']})
 def test_parse_output(self):
     etree = ElementTree.fromstring(imageml_string)
     reader = imageml.ImageImplReader()
     outgens = reader.parse_outputs(etree)
     self.assertEquals(outgens[0].outputpath,'startup.mbm')
    def _run_test_add_meta_to_multiple_roots_in_filesystem_project(
            self, project, args, updated_configs):
        TEST_PROJECT_DIR = os.path.join(ROOT_PATH, 'temp/update', project)
        unzip_file.unzip_file(TEST_PROJECT_CPF,
                              TEST_PROJECT_DIR,
                              delete_if_exists=True)
        self.assert_exists_and_contains_something(TEST_PROJECT_DIR)

        self.set_modification_reference_time(TEST_PROJECT_DIR)
        cmd = ('%(cmd)s '\
            '--project "%(project)s" %(args)s '\
            '--add-meta owner="test person" '\
            '--add-meta product="test product" '\
            '--add-cpf-meta product_type="XYZ-123" '\
            '--add-cpf-meta platform="Platform X" '\
            '--add-desc "Testing description"')\
            % {'cmd'    : get_cmd('update'),
               'project': TEST_PROJECT_DIR,
               'args'   : args}
        out = self.run_command(cmd)
        #print out
        self.assert_modified(TEST_PROJECT_DIR)

        # Check that the metadata is correct for all roots
        project = api.Project(api.Storage.open(TEST_PROJECT_DIR, 'r'))
        for config in project.list_configurations():
            config_file_path = os.path.join(TEST_PROJECT_DIR, config)
            root_elem = ElementTree.fromstring(
                self.read_data_from_file(config_file_path))

            if config in updated_configs:
                try:
                    desc_elem = root_elem.find(
                        "{http://www.s60.com/xml/confml/2}desc")
                    self.assertNotEquals(desc_elem, None)
                    self.assertEquals(desc_elem.text, "Testing description")

                    meta_elem = root_elem.find(
                        "{http://www.s60.com/xml/confml/2}meta")
                    self.assertEquals(self._get_meta_entry(meta_elem, 'owner'),
                                      'test person')
                    self.assertEquals(
                        self._get_meta_entry(meta_elem, 'product'),
                        'test product')
                    self.assertEquals(
                        self._get_cpf_meta_entry(meta_elem, 'product_type'),
                        'XYZ-123')
                    self.assertEquals(
                        self._get_cpf_meta_entry(meta_elem, 'platform'),
                        'Platform X')
                except AssertionError:
                    self.fail(
                        "Root '%s' was not updated when it should have been!" %
                        config)
            else:
                try:
                    desc_elem = root_elem.find(
                        "{http://www.s60.com/xml/confml/2}desc")
                    self.assertEquals(desc_elem, None)

                    meta_elem = root_elem.find(
                        "{http://www.s60.com/xml/confml/2}meta")
                    self.assertEquals(meta_elem, None)
                except AssertionError:
                    self.fail(
                        "Root '%s' was updated when it should not have been!" %
                        config)
    def _run_test_add_and_remove_meta_in_project(self, project,
                                                 root_file_reader):
        """
        Run test for adding and removing metadata in a project.
        
        @param project: Path to the project that is being modified.
        @param root_file_reader: Function that will be called to read the raw binary
            data of the configuration project's root ConfML file.
        """
        # -------------------------------------
        # Step 1: Add metadata and description
        # -------------------------------------
        self.set_modification_reference_time(project)
        cmd = ('%s '\
            '--project "%s" --configuration root5.confml '\
            '--add-meta owner="test person" '\
            '--add-meta product="test product" '\
            '--add-meta date="2009-05-11" '\
            '--add-cpf-meta product_type="XYZ-123" '\
            '--add-cpf-meta platform="Platform X" '\
            '--add-cpf-meta platform_version="1.0.0" '\
            '--add-desc "Testing description"') % (get_cmd('update'), project)
        out = self.run_command(cmd)
        #print out
        self.assert_modified(project)

        # Check that the metadata is correct
        root_elem = ElementTree.fromstring(root_file_reader())

        desc_elem = root_elem.find("{http://www.s60.com/xml/confml/2}desc")
        self.assertEquals(desc_elem.text, "Testing description")

        meta_elem = root_elem.find("{http://www.s60.com/xml/confml/2}meta")
        self.assertEquals(self._get_meta_entry(meta_elem, 'owner'),
                          'test person')
        self.assertEquals(self._get_meta_entry(meta_elem, 'product'),
                          'test product')
        self.assertEquals(self._get_meta_entry(meta_elem, 'date'),
                          '2009-05-11')
        self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'product_type'),
                          'XYZ-123')
        self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'platform'),
                          'Platform X')
        self.assertEquals(
            self._get_cpf_meta_entry(meta_elem, 'platform_version'), '1.0.0')

        # -----------------------------------------------
        # Step 2: Remove and modify some of the metadata
        # -----------------------------------------------
        self.set_modification_reference_time(project)
        cmd = ('%s '\
            '--project "%s" --configuration root5.confml '\
            '--add-meta product="Prod-1" '\
            '--remove-meta date '\
            '--add-cpf-meta platform_version=1.0.1 '\
            '--remove-meta product_type ') % (get_cmd('update'), project)
        out = self.run_command(cmd)
        #print out
        self.assert_modified(project)

        # Check that the metadata is correct
        root_elem = ElementTree.fromstring(root_file_reader())

        desc_elem = root_elem.find("{http://www.s60.com/xml/confml/2}desc")
        self.assertEquals(desc_elem.text, "Testing description")

        meta_elem = root_elem.find("{http://www.s60.com/xml/confml/2}meta")
        self.assertEquals(self._get_meta_entry(meta_elem, 'owner'),
                          'test person')
        self.assertEquals(self._get_meta_entry(meta_elem, 'product'), 'Prod-1')
        self.assertEquals(self._get_meta_entry(meta_elem, 'date'), None)
        self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'product_type'),
                          None)
        self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'platform'),
                          'Platform X')
        self.assertEquals(
            self._get_cpf_meta_entry(meta_elem, 'platform_version'), '1.0.1')

        # ------------------------------------------------------------
        # Step 3: Remove the description and the rest of the metadata
        # ------------------------------------------------------------
        self.set_modification_reference_time(project)
        cmd = ('%s '\
            '--project "%s" --configuration root5.confml '\
            '--remove-meta owner '\
            '--remove-meta product '\
            '--remove-meta platform '\
            '--remove-meta platform_version '\
            '--remove-desc ') % (get_cmd('update'), project)
        out = self.run_command(cmd)
        #print out
        self.assert_modified(project)

        # Check that the metadata is correct
        root_elem = ElementTree.fromstring(root_file_reader())

        desc_elem = root_elem.find("{http://www.s60.com/xml/confml/2}desc")
        self.assertEquals(desc_elem, None)

        meta_elem = root_elem.find("{http://www.s60.com/xml/confml/2}meta")
        self.assertEquals(0, len(meta_elem.getchildren()))
 def fromstring(self, xml_as_string):
     etree = ElementTree.fromstring(xml_as_string)
     self.parse_thememl(etree)