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