buildframework/helium/tools/common/python/lib/cpythontest/test_buildmodel.py
changeset 179 d8ac696cc51f
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
       
     1 #============================================================================ 
       
     2 #Name        : test_buildmodel.py 
       
     3 #Part of     : Helium 
       
     4 
       
     5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     6 #All rights reserved.
       
     7 #This component and the accompanying materials are made available
       
     8 #under the terms of the License "Eclipse Public License v1.0"
       
     9 #which accompanies this distribution, and is available
       
    10 #at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    11 #
       
    12 #Initial Contributors:
       
    13 #Nokia Corporation - initial contribution.
       
    14 #
       
    15 #Contributors:
       
    16 #
       
    17 #Description:
       
    18 #===============================================================================
       
    19 
       
    20 """ Test build.model module. """
       
    21 
       
    22 import os
       
    23 import sys
       
    24 import tempfile
       
    25 import unittest
       
    26 
       
    27 import build.model
       
    28 import configuration
       
    29 import ccm
       
    30 import amara
       
    31 import logging
       
    32 
       
    33 _logger = logging.getLogger('test.bom')
       
    34 
       
    35 database = "to1tobet"
       
    36 
       
    37 class BOMMockFolder:    
       
    38     def __init__(self, name, instance, description, tasks):
       
    39         self.name = name
       
    40         self.instance = instance
       
    41         self.description = description
       
    42         self.tasks = tasks
       
    43         
       
    44 class BOMMockProject:
       
    45     def __init__(self, name):
       
    46         self.name = name
       
    47     
       
    48     def __str__(self):
       
    49         return self.name
       
    50     
       
    51     @property
       
    52     def tasks(self):
       
    53         return []
       
    54     
       
    55     @property
       
    56     def folders(self):
       
    57         return [BOMMockFolder('5856', 'tr1s60', "all completed tasks for release ABS_domain/abs.mcl for collaborative projects", [])] 
       
    58     
       
    59 class BOMMock:
       
    60     
       
    61     def __init__(self):
       
    62         self.config = {}
       
    63         self.config['build.id'] = "mock"
       
    64     
       
    65     @property
       
    66     def projects(self):    
       
    67         return [BOMMockProject('ABS_domain-abs.mcl_200843:project:tr1s60#1')] 
       
    68 
       
    69     def all_baselines(self):
       
    70         return []
       
    71 
       
    72 # Refactor required: See http://delivery.nmp.nokia.com/trac/helium/ticket/1517
       
    73 class BOMTest(unittest.TestCase):
       
    74     """ Test BOM and related classes. """
       
    75     
       
    76 # TODO - removed until non-Synergy dependent tests can be provided.
       
    77 
       
    78 #    def test_bom_output(self):
       
    79 #        """ Test basic BOM execution. Only new spec format will be covered!"""
       
    80 #        try:
       
    81 #            session = ccm.open_session(database=database)
       
    82 #        except ccm.CCMException:
       
    83 #            print "Skipping BOMTest test cases."
       
    84 #            return
       
    85 #            
       
    86 #        project = session.create('helium-helium_0.1:project:vc1s60p1#1')
       
    87 #        config_dict = {'delivery': 'tests/data/test_delivery.xml',
       
    88 #                       'prep.xml': 'tests/data/test_prep.xml',
       
    89 #                       'build.id': "test_0.0",
       
    90 #                       'ccm.database': session.database()}
       
    91 #        config = configuration.Configuration(config_dict)
       
    92 #        bom = build.model.BOM_new_spec_config(config, project)
       
    93 #        writer = build.model.BOMHTMLWriter(bom)
       
    94 #        writer.write("bom2.html")
       
    95 #        session.close()
       
    96 #        os.remove("bom2.html")
       
    97 #        os.remove("bom2.html.xml")
       
    98 
       
    99     def test_bom_delta(self):
       
   100         """ Testing BOM delta creation... """
       
   101         delta = build.model.BOMDeltaXMLWriter(BOMMock(), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/build_model_bom.xml'))
       
   102         delta.write(os.path.join(os.environ['HELIUM_HOME'], 'build','delta.xml'))
       
   103         xml = amara.parse(open(os.path.join(os.environ['HELIUM_HOME'], 'build','delta.xml'), 'r'))
       
   104         assert xml.bomDelta[0].buildFrom[0] == "ido_raptor_mcl_abs_MCL.52.57"
       
   105         assert xml.bomDelta[0].buildTo[0] == "mock"
       
   106 
       
   107         print "baselines: ", len(xml.bomDelta.content.baseline)
       
   108         print "folders: ", len(xml.bomDelta.content.folder)
       
   109         print "tasks: ", len(xml.bomDelta.content.task)
       
   110         print "baseline[@overridden='false']:", len(xml.bomDelta.content.xml_xpath("baseline[@overridden='false']"))
       
   111         print "baseline[@overridden='true']: ", len(xml.bomDelta.content.xml_xpath("baseline[@overridden='true']"))
       
   112         print "folder[@status='deleted']: ", len(xml.bomDelta.content.xml_xpath("folder[@status='deleted']"))
       
   113         print "task[@status='deleted']: ", len(xml.bomDelta.content.xml_xpath("task[@status='deleted']"))
       
   114 
       
   115         assert len(xml.bomDelta.content.baseline) == 156
       
   116         assert len(xml.bomDelta.content.folder) == 1
       
   117         assert len(xml.bomDelta.content.task) == 1
       
   118         assert len(xml.bomDelta.content.xml_xpath("baseline[@overridden='false']")) == 155
       
   119         assert len(xml.bomDelta.content.xml_xpath("baseline[@overridden='true']")) == 1
       
   120 
       
   121         assert len(xml.bomDelta.content.xml_xpath("folder[@status='deleted']")) == 1
       
   122 
       
   123         assert len(xml.bomDelta.content.xml_xpath("task[@status='deleted']")) == 1
       
   124         
       
   125     def test_validate_bom_delta(self):
       
   126         """ Testing BOM delta validation... """
       
   127         bom_delta_validate = build.model.BOMDeltaXMLWriter((os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml')), (os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml')))
       
   128         delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml'))
       
   129         self.assertEqual(True, delta_bom_content_validity) 
       
   130         delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_104_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml'))
       
   131         self.assertEqual(False, delta_bom_content_validity) 
       
   132         delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_103_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_103_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml'))
       
   133         self.assertEqual(None, delta_bom_content_validity) 
       
   134 
       
   135     def test_BOMXMLWriter(self):
       
   136         config_data = {'delivery': 'tests/data/test_delivery.xml', 'prep.xml': 'tests/data/test_prep.xml', 'build.id': 'buildid', 'symbian_rel_week': r'${symbian.version.week}', 'symbian_rel_ver': r'${symbian.version}', 'symbian_rel_year': r'${symbian.version.year}', 's60_version': r'${s60.version}', 's60_release': r'${s60.release}', 'currentRelease.xml': "tests/data/symrec/generated_release_metadata.xml"}
       
   137         bom = build.model.BOM(configuration.Configuration(config_data))
       
   138         xml_writer = build.model.BOMXMLWriter(bom)
       
   139         (_, filename) = tempfile.mkstemp()
       
   140         xml_writer.write(filename)
       
   141         #_logger.info(open(filename).read())