configurationengine/source/scripts/tests/unittest_info.py
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     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 sys
       
    23 import os
       
    24 import subprocess
       
    25 import __init__
       
    26 from testautomation.base_testcase import BaseTestCase
       
    27 from scripttest_common import get_cmd
       
    28 
       
    29 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    30 testproject = os.path.join(ROOT_PATH,'test_project.cpf')
       
    31 temp_dir    = os.path.join(ROOT_PATH, 'temp/info')
       
    32 VALUE_REPORT_PROJECT = os.path.join(ROOT_PATH, 'testdata/info/value_report_project')
       
    33 
       
    34 class TestInfo(BaseTestCase):
       
    35     
       
    36     def test_get_help(self):
       
    37         cmd = '%s -h' % get_cmd('info')
       
    38         out = self.run_command(cmd)
       
    39         lines = out.split('\r\n')
       
    40         self.assertTrue('Options:' in lines)
       
    41         self.assertTrue('  Info options:' in lines)
       
    42     
       
    43 
       
    44     def test_get_project_info(self):
       
    45         self.set_modification_reference_time(testproject)
       
    46         cmd = '%s -p "%s"' % (get_cmd('info'), testproject)
       
    47         out = self.run_command(cmd)
       
    48         
       
    49         lines = out.split('\r\n')
       
    50         self.assertTrue('Configurations in the project.' in lines)
       
    51         self.assertTrue('root1.confml' in lines)
       
    52         self.assertTrue('root2.confml' in lines)
       
    53         self.assertTrue('root3.confml' in lines)
       
    54         self.assertTrue('root4.confml' in lines)
       
    55         self.assertTrue('root5.confml' in lines)
       
    56         
       
    57         self.assert_not_modified(testproject)
       
    58     
       
    59     def test_api_report(self):
       
    60         EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/api_report.html')
       
    61         REPORT_FILE = os.path.join(temp_dir, 'api_report.html')
       
    62         self.remove_if_exists(REPORT_FILE)
       
    63         cmd = '%s -p "%s" -c root3.confml --report-type api --report "%s"' % (get_cmd('info'), testproject, REPORT_FILE)
       
    64         out = self.run_command(cmd)
       
    65         
       
    66         # Ignore the file links, because their value depends on the current directory
       
    67         ignores= [r'<td><a href="file://.*">.*</a></td>']
       
    68         self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE, ignores)
       
    69     
       
    70     def test_impl_report(self):
       
    71         EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/impl_report.html')
       
    72         REPORT_FILE = os.path.join(temp_dir, 'impl_report.html')
       
    73         self.remove_if_exists(REPORT_FILE)
       
    74         cmd = '%s -p "%s" -c root3.confml --report-type impl --report "%s"' % (get_cmd('info'), testproject, REPORT_FILE)
       
    75         out = self.run_command(cmd)
       
    76         
       
    77         self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
       
    78     
       
    79     def test_impl_report_with_impl_containers(self):
       
    80         PROJECT = os.path.join(ROOT_PATH, 'generation_test_project')
       
    81         EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/impl_report_with_containers.html')
       
    82         REPORT_FILE = os.path.join(temp_dir, 'impl_report_with_containers.html')
       
    83         self.remove_if_exists(REPORT_FILE)
       
    84         cmd = '%s -p "%s" -c root.confml --report-type impl --report "%s"' % (get_cmd('info'), PROJECT, REPORT_FILE)
       
    85         out = self.run_command(cmd)
       
    86         
       
    87         self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
       
    88     
       
    89     def test_content_report(self):
       
    90         EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/content_report.html')
       
    91         REPORT_FILE = os.path.join(temp_dir, 'content_report.html')
       
    92         self.remove_if_exists(REPORT_FILE)
       
    93         cmd = '%s -p "%s" -c root5.confml --report-type content --report "%s"' % (get_cmd('info'), testproject, REPORT_FILE)
       
    94         out = self.run_command(cmd)
       
    95         
       
    96         self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
       
    97     
       
    98     # --------------------------------------------------
       
    99     # Tests for invalid configuration argument detection
       
   100     # --------------------------------------------------
       
   101     
       
   102     def _run_test_invalid_configuration_args(self, config_args, expected_msg):
       
   103         REPORT_FILE = os.path.join(temp_dir, "dummy_report.html")
       
   104         self.remove_if_exists(REPORT_FILE)
       
   105         cmd = '%s -p "%s" %s --report "%s"' \
       
   106             % (get_cmd('info'), VALUE_REPORT_PROJECT, config_args, REPORT_FILE)
       
   107         # Note: The following run_command() should really expect the
       
   108         #       return code 2, but for some reason when running from the
       
   109         #       standalone test set, the return value is 0
       
   110         out = self.run_command(cmd, expected_return_code = None)
       
   111         self.assertFalse(os.path.exists(REPORT_FILE))
       
   112         
       
   113         self.assertTrue(expected_msg in out,
       
   114                         "Expected message '%s' not in output ('%s')" % (expected_msg, out))
       
   115     
       
   116     def test_invalid_single_configuration(self):
       
   117         self._run_test_invalid_configuration_args(
       
   118             '--configuration nonexistent_root.confml',
       
   119             "No such configuration: nonexistent_root.confml")
       
   120         
       
   121     def test_invalid_multi_configuration(self):
       
   122         self._run_test_invalid_configuration_args(
       
   123             '--configuration product_root.confml --configuration nonexistent_root.confml',
       
   124             "No such configuration: nonexistent_root.confml")
       
   125     
       
   126     def test_invalid_wildcard_configuration(self):
       
   127         self._run_test_invalid_configuration_args(
       
   128             '--config-wildcard nonexistent*.confml',
       
   129             "No matching configurations for wildcard(s) and/or pattern(s).")
       
   130     
       
   131     def test_invalid_regex_configuration(self):
       
   132         self._run_test_invalid_configuration_args(
       
   133             '--config-regex nonexistent.*\\.confml',
       
   134             "No matching configurations for wildcard(s) and/or pattern(s).")
       
   135     
       
   136     def test_invalid_view_file(self):
       
   137         self._run_test_invalid_configuration_args(
       
   138             '-c product_root.confml --view-file nonexistent.confml',
       
   139             "No such file: nonexistent.confml")
       
   140     
       
   141     
       
   142     # ----------------------
       
   143     # Tests for value report
       
   144     # ----------------------
       
   145     
       
   146     def _run_test_value_report(self, output, expected, args, rep_type='value'):
       
   147         EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/%s' % expected)
       
   148         REPORT_FILE = os.path.join(temp_dir, output)
       
   149         self.remove_if_exists(REPORT_FILE)
       
   150         cmd = '%s -p "%s" %s --report-type %s --report "%s"' \
       
   151             % (get_cmd('info'), VALUE_REPORT_PROJECT, args, rep_type, REPORT_FILE)
       
   152         out = self.run_command(cmd)
       
   153         
       
   154         self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
       
   155     
       
   156     def test_value_report_configs_with_wildcard(self):
       
   157         self._run_test_value_report(
       
   158             output   = 'value_report_langpacks_wildcard.html',
       
   159             expected = 'value_report_langpacks.html',
       
   160             args     = '--config-wildcard product_langpack_*_root.confml')
       
   161     
       
   162     def test_value_report_configs_with_regex(self):
       
   163         self._run_test_value_report(
       
   164             output   = 'value_report_langpacks_regex.html',
       
   165             expected = 'value_report_langpacks.html',
       
   166             args     = '--config-regex product_langpack_\\d{2}_root.confml')
       
   167     
       
   168     def test_value_report_multi_config(self):
       
   169         self._run_test_value_report(
       
   170             output   = 'value_report_langpacks_regex.html',
       
   171             expected = 'value_report_langpacks.html',
       
   172             args     = '-c product_langpack_01_root.confml '\
       
   173                        '-c product_langpack_02_root.confml '\
       
   174                        '-c product_langpack_03_root.confml')
       
   175     
       
   176     def test_value_report_single_config(self):
       
   177         self._run_test_value_report(
       
   178             output   = 'value_report_single.html',
       
   179             expected = 'value_report_single.html',
       
   180             args     = '--configuration product_root.confml')
       
   181     
       
   182     def test_value_report_multi_config_mixed_args(self):
       
   183         self._run_test_value_report(
       
   184             output   = 'value_report_multi_mixed.html',
       
   185             expected = 'value_report_multi_mixed.html',
       
   186             args     = '-c product_root.confml --config-wildcard product_langpack_*_root.confml')
       
   187     
       
   188     def test_value_report_single_config_with_view(self):
       
   189         VIEW_FILE = os.path.join(ROOT_PATH, 'testdata/info/test_view.confml')
       
   190         self._run_test_value_report(
       
   191             output   = 'value_report_single_with_view.html',
       
   192             expected = 'value_report_single_with_view.html',
       
   193             args     = '--configuration product_root.confml --view-file "%s"' % VIEW_FILE)
       
   194     
       
   195     def test_value_report_single_config_with_included_view(self):
       
   196         VIEW_FILE = os.path.join(ROOT_PATH, 'testdata/info/include_test_view.confml')
       
   197         self._run_test_value_report(
       
   198             output   = 'value_report_single_with_included_view.html',
       
   199             expected = 'value_report_single_with_view.html',
       
   200             args     = '--configuration product_root.confml --view-file "%s"' % VIEW_FILE)
       
   201     
       
   202     def test_value_report_csv(self):
       
   203         self._run_test_value_report(
       
   204             output   = 'value_report.csv',
       
   205             expected = 'value_report.csv',
       
   206             args     = '--config-wildcard product_langpack_*_root.confml',
       
   207             rep_type = 'value_csv')
       
   208     
       
   209     def test_value_report_csv_with_special_chars(self):
       
   210         self._run_test_value_report(
       
   211             output   = 'value_report_special_chars.csv',
       
   212             expected = 'value_report_special_chars.csv',
       
   213             args     = '--configuration csv_test_root.confml',
       
   214             rep_type = 'value_csv')
       
   215     
       
   216     def test_value_report_custom_template(self):
       
   217         TEMPLATE_FILE = os.path.join(ROOT_PATH, 'testdata/info/custom_value_report_template.html')
       
   218         EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/value_report_custom.html')
       
   219         REPORT_FILE = os.path.join(temp_dir, 'value_report_custom.html')
       
   220         self.remove_if_exists(REPORT_FILE)
       
   221         cmd = '%s -p "%s" --template "%s" --report "%s" -c product_root.confml' \
       
   222             % (get_cmd('info'), VALUE_REPORT_PROJECT, TEMPLATE_FILE, REPORT_FILE)
       
   223         out = self.run_command(cmd)
       
   224         
       
   225         self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
       
   226 
       
   227 if __name__ == '__main__':
       
   228       unittest.main()