Example #1
0
 def test_merge_both(self):
     self.run_command(
         '%s -p main_project --targetlayer assets/test/root.confml -r asset1_v1 --sourcelayer root.confml'
         % get_cmd('merge'))
     self.run_command(
         '%s -p main_project --targetlayer assets/test/root.confml -r asset2_v1 --sourcelayer root.confml'
         % get_cmd('merge'))
     self.assert_is_expected('both_merged')
Example #2
0
 def test_merge_and_update_asset1(self):
     self.run_command(
         '%s -p main_project --targetlayer assets/test/root.confml -r asset1_v1 --sourcelayer root.confml'
         % get_cmd('merge'))
     self.assert_is_expected('asset1_merged')
     self.run_command(
         '%s -p main_project --targetlayer assets/test/root.confml -r asset1_v2 --sourcelayer root.confml'
         % get_cmd('merge'))
     self.assert_is_expected('asset1_merged_and_updated')
Example #3
0
 def test_merge_cpf_last_layer_two_versions(self):
     project_dir, expected_dir = self._prepare_workdir_with_project(
         'last_layer_two_versions', 'last_layer_variant_v1_v2_expected.zip')
     cmd = '%s -p "%s" -r "%s" -c root5.confml -l -1' % (
         get_cmd('merge'), project_dir, TEST_VARIANT_CPF_V1)
     self.run_command(cmd)
     cmd = '%s -p "%s" -r "%s" -c root5.confml -l -1' % (
         get_cmd('merge'), project_dir, TEST_VARIANT_CPF_V2)
     self.run_command(cmd)
     self.assert_dir_contents_equal(expected_dir, project_dir)
Example #4
0
 def test_print_active_root(self):
     cmd = '%s -p "%s" --print-active-root' % (get_cmd('info'), testproject)
     out = self.run_command(cmd)
     self.assertTrue('Active root: root5.confml' in out)
     
     project = os.path.join(ROOT_PATH,'test_variant.cpf')
     cmd = '%s -p "%s" --print-active-root' % (get_cmd('info'), project)
     out = self.run_command(cmd)
     self.assertTrue('Active root: root.confml' in out)
     
     project = os.path.join(ROOT_PATH, 'testdata/info/no_active_root.cpf')
     cmd = '%s -p "%s" --print-active-root' % (get_cmd('info'), project)
     out = self.run_command(cmd)
     self.assertTrue('No active root.' in out)
 def test_export_with_include_content_filter_help(self):
     # test help update
     cmd = '%s -h' % get_cmd('export')
     out = self.run_command(cmd)
     lines = out.split(os.linesep)
     self.assertTrue(
         '    --include-content-filter=INCLUDE_CONTENT_FILTER' in lines)
    def test_write_what_out(self):
        self.remove_if_exists(self.OUTPUT)

        cmd = [
            '%(cone_cmd)s',
            '-p "%(project)s"',
            '-c root.confml',
            '--what="%(what_file)s"',
            '--output "%(output)s"',
            '--log-file="%(log_file)s"',
            '--all-layers',
        ]
        cmd = ' '.join(cmd) % {
            'cone_cmd': get_cmd('generate'),
            'project': self.PROJECT,
            'what_file': self.WHAT_FILE,
            'output': self.OUTPUT,
            'log_file': self.LOG
        }
        self.run_command(cmd)

        cmp_what_out_fh = open(self.CMP_FILE, 'r')
        cmp_files = []
        try:
            cmp_files = cmp_what_out_fh.readlines()
        finally:
            cmp_what_out_fh.close()

        self.assert_exists_and_contains_something(self.WHAT_FILE)
        self.assert_file_contains(self.WHAT_FILE,
                                  [self._flip(c.strip()) for c in cmp_files])
    def test_set_tempvar_value_from_cmdline(self):
        PROJECT = os.path.join(ROOT_PATH, 'generation_test_project')

        OUTPUT_ROOT = os.path.join(ROOT_PATH, 'temp/gen_tvs/')
        OUTPUT = os.path.join(OUTPUT_ROOT, 'out')
        LOG = os.path.join(OUTPUT_ROOT, 'cone.log')
        self.remove_if_exists(OUTPUT)

        cmd = [
            '%(cone_cmd)s',
            '-p "%(project)s"',
            '-c root.confml',
            '--output "%(output)s"',
            '--log-file="%(log_file)s"',
            '--impl simple_tempvar',
            '--set "TempFeature.String=testing from cmdline"',
            '--set "TempFeature.Int=8090"',
            '--set "TempFeature.Real=-5.75"',
        ]
        cmd = ' '.join(cmd) % {
            'cone_cmd': get_cmd('generate'),
            'project': PROJECT,
            'output': OUTPUT,
            'log_file': LOG
        }
        #print cmd
        self.run_command(cmd)

        self.assert_file_contains(
            os.path.join(OUTPUT, 'content', 'simple_tempvars_test.txt'), [
                'TempFeature.String:  testing from cmdline and more testing',
                'TempFeature.Int:     8091', 'TempFeature.Real:    -5.5'
            ])
    def _run_layer_filtering_test(self, name, filter, expected):
        PROJECT = os.path.join(ROOT_PATH,
                               'testdata/generate/layer_filtering_project')

        OUTPUT_ROOT = os.path.join(ROOT_PATH, 'temp/gen_lf/', name)
        OUTPUT = os.path.join(OUTPUT_ROOT, 'out')
        LOG = os.path.join(OUTPUT_ROOT, 'cone.log')
        self.remove_if_exists(OUTPUT)

        cmd = '%s -p "%s" --output "%s" --log-file="%s" %s' % (
            get_cmd('generate'), PROJECT, OUTPUT, LOG, filter)
        #print cmd
        self.run_command(cmd)

        self.assert_exists_and_contains_something(OUTPUT)

        expected_files = sorted([x + '.txt' for x in expected])
        actual_files = sorted(os.listdir(OUTPUT))

        # Ignore the rule output txt files
        for f in ('rule_test_v2.txt', 'rule_test_v3.txt'):
            if f in actual_files: del actual_files[actual_files.index(f)]
        self.assertEquals(expected_files, actual_files)

        # Check that the correct rules have been executed
        expected_str = ' ' + ' '.join(sorted(expected)) + ' x'
        self.assert_file_content_equals(
            os.path.join(OUTPUT, 'rule_test_v2.txt'), expected_str)
        self.assert_file_content_equals(
            os.path.join(OUTPUT, 'rule_test_v3.txt'), expected_str)
    def test_generate_all_impls_on_last_layer_on_file_storage_with_report(
            self):
        project_dir = os.path.join(ROOT_PATH, "generation_test_project")
        self.assert_exists_and_contains_something(project_dir)

        # Create a temp workdir and go there to run the test
        orig_workdir = os.getcwd()
        workdir = self._prepare_workdir('temp/gen_ll3')
        os.chdir(workdir)

        try:
            cmd = '%s -p "%s" --output output --layer -1 --add-setting-file imaker_variantdir.cfg --report report.html' % (
                get_cmd('generate'), project_dir)
            self.run_command(cmd)
        finally:
            os.chdir(orig_workdir)

        ACTUAL_REPORT = os.path.join(ROOT_PATH, 'temp/gen_ll3/report.html')
        EXPECTED_REPORT = os.path.join(
            ROOT_PATH, "testdata/generate/expected_report.html")

        ignores = [
            r'<tr>\s*<td>Report generated</td>\s*<td>.*</td>\s*</tr>',
            r'<tr>\s*<td>Generation duration</td>\s*<td>.*</td>\s*</tr>',
            r'<a href=".*">',
            r'<tr>\s*<td align="left">Project</td>\s*<td align="left">.*</td>\s*</tr>',
            r'<tr>\s*<td align="left">Working directory</td>\s*<td align="left">.*</td>\s*</tr>',
        ]

        self.assert_file_contents_equal(ACTUAL_REPORT, EXPECTED_REPORT,
                                        ignores)
    def test_export_with_include_content_filter_project_to_cpf(self):
        # test cpf export
        source = os.path.join(TEMP_DIR, "layers")
        remote = os.path.join(TEMP_DIR, 'layers.cpf')
        self.remove_if_exists(remote)

        unzip_file(EXPORT_TEST_PROJECT, source, delete_if_exists=True)

        cmd = '%s -p "%s" -c "root4.confml" -r "%s" --include-content-filter="%s"' % (
            get_cmd('export'), TEST_PROJECT_CPF, remote, ".*layer1.*")
        out = self.run_command(cmd)

        # layer1 content
        self.assert_zip_entry_exists(remote, "root4.confml")
        self.assert_zip_entry_exists(remote, "Layer1/content/default_file.txt")
        self.assert_zip_entry_exists(remote,
                                     "Layer1/content/seq/def1_file.txt")

        # filtered content
        self.assert_zip_entry_exists_not(remote,
                                         "Layer2/content/layer2_file.txt")
        self.assert_zip_entry_exists_not(remote,
                                         "Layer3/content/seq/layer3_file.txt")
        self.assert_zip_entry_exists_not(remote,
                                         "Layer4/content/seq/layer4_file.txt")
Example #11
0
 def test_runtime_info_logged(self):
     # This test makes sure that runtime info is always logged
     # in the log file
     
     TEST_DIR = os.path.join(ROOT_PATH, "temp", "log_test")
     self.recreate_dir(TEST_DIR)
     
     orig_workdir = os.getcwd()
     os.chdir(TEST_DIR)
     try:
         cmd = '%s' % get_cmd('info')
         self.run_command(cmd)
         
         # Check that the default log file has been created
         self.assertTrue(os.path.exists('cone.log'))
         
         # Check that it contains the runtime info that should
         # always be logged
         f = open('cone.log', 'r')
         try:        data = f.read()
         finally:    f.close()
         self.assertTrue('DEBUG   : cone' in data)
         self.assertTrue('sys.path contents:' in data)
         self.assertTrue('PATH:' in data)
         self.assertTrue('PYTHONPATH:' in data)
     finally:
         os.chdir(orig_workdir)
    def test_export_multiple_configurations(self):
        remote = os.path.join(TEMP_DIR, 'test2')
        self.remove_if_exists(remote)

        self.set_modification_reference_time(TEST_PROJECT_CPF)
        cmd = '%s -p "%s" -c "root2.confml" -c "root3.confml" -c "root5.confml" -r "%s"' % (
            get_cmd('export'), TEST_PROJECT_CPF, remote)
        out = self.run_command(cmd)
        #print out
        lines = out.split(os.linesep)
        self.assertTrue('Export root2.confml to %s done!' % remote in lines)
        self.assertTrue('Export root3.confml to %s done!' % remote in lines)
        self.assertTrue('Export root5.confml to %s done!' % remote in lines)

        self.assertEquals(
            set(os.listdir(remote)),
            set([
                "Layer1", "Layer2", "Layer3", "Layer4", "Layer5", ".metadata",
                "root2.confml", "root3.confml", "root5.confml"
            ]))

        def fp(p):  # fp = full_path
            return os.path.join(remote, p)

        self.assert_exists_and_contains_something(fp("Layer1"))
        self.assert_exists_and_contains_something(fp("Layer2"))
        self.assert_exists_and_contains_something(fp("Layer3"))
        self.assert_exists_and_contains_something(fp("Layer4"))
        self.assert_exists_and_contains_something(fp("Layer5"))
        self.assert_exists_and_contains_something(fp("root2.confml"))
        self.assert_exists_and_contains_something(fp("root3.confml"))
        self.assert_exists_and_contains_something(fp("root5.confml"))

        self.assert_not_modified(TEST_PROJECT_CPF)
    def test_add_data_to_cpf(self):
        # Copy from the test data
        cpf = os.path.join(ROOT_PATH,
                           "temp/metadata/add_data_test_project.cpf")
        self.remove_if_exists(cpf)
        self.create_dir_for_file_path(cpf)
        shutil.copy2(TEST_PROJECT_CPF, cpf)

        CONFIG = 'root3.confml'

        def get_setting_value(project_location, ref):
            prj = api.Project(api.Storage.open(project_location, 'r'))
            try:
                config = prj.get_configuration(CONFIG)
                dview = config.get_default_view()
                feature = dview.get_feature(ref)
                return feature.get_value()
            finally:
                prj.close()

        self.assertEquals(get_setting_value(cpf, 'Feature1.BooleanSetting'),
                          False)

        self.set_modification_reference_time(cpf)
        cmd = '%s -p "%s" -c %s --add-data Feature1.BooleanSetting=true' % (
            get_cmd('update'), cpf, CONFIG)
        self.run_command(cmd)
        self.assert_modified(cpf)

        self.assertEquals(get_setting_value(cpf, 'Feature1.BooleanSetting'),
                          True)
Example #14
0
 def test_impl_report(self):
     EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/impl_report.html')
     REPORT_FILE = os.path.join(temp_dir, 'impl_report.html')
     self.remove_if_exists(REPORT_FILE)
     cmd = '%s -p "%s" -c root3.confml --report-type impl --report "%s"' % (get_cmd('info'), testproject, REPORT_FILE)
     out = self.run_command(cmd)
     
     self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
Example #15
0
 def _run_test_value_report(self, output, expected, args, rep_type='value'):
     EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/%s' % expected)
     REPORT_FILE = os.path.join(temp_dir, output)
     self.remove_if_exists(REPORT_FILE)
     cmd = '%s -p "%s" %s --report-type %s --report "%s"' \
         % (get_cmd('info'), VALUE_REPORT_PROJECT, args, rep_type, REPORT_FILE)
     out = self.run_command(cmd)
     
     self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
Example #16
0
 def test_impl_report_with_impl_containers(self):
     PROJECT = os.path.join(ROOT_PATH, 'generation_test_project')
     EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/impl_report_with_containers.html')
     REPORT_FILE = os.path.join(temp_dir, 'impl_report_with_containers.html')
     self.remove_if_exists(REPORT_FILE)
     cmd = '%s -p "%s" -c root.confml --report-type impl --report "%s"' % (get_cmd('info'), PROJECT, REPORT_FILE)
     out = self.run_command(cmd)
     
     self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
 def _run_test(self, args, expected_return_code, expected_msg):
     if not isinstance(args, basestring):
         args = ' '.join(args)
     
     cmd = get_cmd('packvariant') + ' ' + args
     out = self.run_command(cmd, expected_return_code = None)
     
     self.assertTrue(expected_msg in out,
                     "Expected message '%s' not in output ('%s')" % (expected_msg, out))
    def test_generate(self):
        self.set_modification_reference_time(testproject)
        OUTPUT_DIR = os.path.join(ROOT_PATH, 'temp/gen1/output')
        self.remove_if_exists(OUTPUT_DIR)
        cmd = '%s -p "%s" -c "%s" -o "%s"' % (get_cmd('generate'), testproject,
                                              rootconf, OUTPUT_DIR)
        out = self.run_command(cmd)
        self.assert_exists_and_contains_something(OUTPUT_DIR)

        self.assert_not_modified(testproject)
Example #19
0
 def test_ctr_report_html(self):
     EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/ctr_report.html')
     REPORT_FILE = os.path.join(temp_dir, 'ctr_report.html')
     self.remove_if_exists(REPORT_FILE)
     cmd = '%s -p "%s" --report "%s" --report-type ctr --config-wildcard product_customisation_root*' \
         % (get_cmd('info'), CTR_REPORT_PROJECT, 
                             REPORT_FILE)
     out = self.run_command(cmd)
     
     self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
Example #20
0
 def test_initvariant_do_not_set_active_root(self):
     PROJECT_DIR, EXPECTED_DIR = self._prepare_workdir('var2', 'test_project.zip', 'expected2.zip')
     
     self.assertEquals(self._get_active_configuration(PROJECT_DIR), None)
     
     cmd = '%s -p "%s" -r "%s" -c foovariant.confml --variant-id 321' % (get_cmd('initvariant'), PROJECT_DIR, TEST_VARIANT_CPF)
     self.run_command(cmd)
     
     self.assert_dir_contents_equal(PROJECT_DIR, EXPECTED_DIR, ['.svn', '.metadata'])
     self.assertEquals(self._get_active_configuration(PROJECT_DIR), None)
    def test_packvariant_project_does_not_exist(self):
        PROJECT_DIR = os.path.join(ROOT_PATH, TESTDATA_DIR, 'project_does_not_exist')
        REMOTE_ZIP = os.path.join(ROOT_PATH, TEMP_DIR, 'output/packvariant.zip')

        self.remove_if_exists(REMOTE_ZIP)
        cmd = '%s -p "%s" -c "%s" -r "%s"' % (get_cmd('packvariant'),PROJECT_DIR,rootconf,REMOTE_ZIP)
        
        self._run_test(
           cmd, 2,
           "Could not create Zip archive: The given data folder for storage does not exist!")
Example #22
0
 def test_api_report(self):
     EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/api_report.html')
     REPORT_FILE = os.path.join(temp_dir, 'api_report.html')
     self.remove_if_exists(REPORT_FILE)
     cmd = '%s -p "%s" -c root3.confml --report-type api --report "%s"' % (get_cmd('info'), testproject, REPORT_FILE)
     out = self.run_command(cmd)
     
     # Ignore the file links, because their value depends on the current directory
     ignores= [r'<td><a href="file://.*">.*</a></td>']
     self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE, ignores)
    def test_packvariant_project_is_not_a_folder(self):
        PROJECT_DIR = os.path.join(ROOT_PATH, TESTDATA_DIR, 'packvariant/project/testprod_custvariant_root.confml')
        REMOTE_ZIP = os.path.join(ROOT_PATH, TEMP_DIR, 'output/packvariant.zip')

        self.remove_if_exists(REMOTE_ZIP)
        cmd = '%s -p "%s" -c "%s" -r "%s"' % (get_cmd('packvariant'),PROJECT_DIR,rootconf,REMOTE_ZIP)
        
        self._run_test(
           cmd, 1,
           "ERROR: --Project must be a directory. Terminating the program.")
 def _run_test_invalid_args(self, args, expected_msg):
     cmd = '%s -p "%s" %s' \
         % (get_cmd('export'), TEST_PROJECT_CPF, args)
     # Note: The following run_command() should really expect the
     #       return code 2, but for some reason when running from the
     #       standalone test set, the return value is 0
     out = self.run_command(cmd, expected_return_code=None)
     self.assertTrue(
         expected_msg in out,
         "Expected message '%s' not in output.\nOutput:\n%s" %
         (expected_msg, out))
 def test_packvariant_configuration_does_not_exist(self):
     PROJECT_DIR = os.path.join(ROOT_PATH, TESTDATA_DIR, 'project')
     REMOTE_ZIP = os.path.join(ROOT_PATH, TEMP_DIR, 'output', 'packvariant.zip')
     rootconf = 'root_does_not_exist.confml'
     expected_msg = "Could not create Zip archive: Child root_does_not_exist_confml not found from Project"
     
     self.remove_if_exists(REMOTE_ZIP)
     cmd = '%s -p "%s" -c "%s" -r "%s"' % (get_cmd('packvariant'),PROJECT_DIR,rootconf,REMOTE_ZIP)
     out = self.run_command(cmd, None)
     
     self.assertTrue(expected_msg in out,
             "Expected message '%s' not in output ('%s')" % (expected_msg, out))
 def test_generate_with_absolute_path(self):
     self.set_modification_reference_time(testproject)
     tempdir = os.path.join(tempfile.gettempdir(), 'cone_output')
     (drive, OUTPUT_DIR) = os.path.splitdrive(os.path.abspath(tempdir))
     LOGFILE = os.path.join(OUTPUT_DIR, 'cone_temp.log')
     self.remove_if_exists(OUTPUT_DIR)
     cmd = '%s -p "%s" -c "%s" -o "%s" --log-file "%s"' % (
         get_cmd('generate'), testproject, rootconf, OUTPUT_DIR, LOGFILE)
     out = self.run_command(cmd)
     self.assert_exists_and_contains_something(OUTPUT_DIR)
     self.assertTrue(os.path.exists(LOGFILE))
     self.assert_not_modified(testproject)
Example #27
0
 def test_value_report_custom_template(self):
     TEMPLATE_FILE = os.path.join(ROOT_PATH, 'testdata/info/custom_value_report_template.html')
     EXPECTED_FILE = os.path.join(ROOT_PATH, 'testdata/info/expected/value_report_custom.html')
     REPORT_FILE = os.path.join(temp_dir, 'value_report_custom.html')
     self.remove_if_exists(REPORT_FILE)
     cmd = '%s -p "%s" --template "%s" --log-file="%s" --report "%s" -c product_root.confml' \
         % (get_cmd('info'), VALUE_REPORT_PROJECT, 
                             TEMPLATE_FILE, 
                             os.path.join(temp_dir, 'value_report_custom_cone.log'),
                             REPORT_FILE)
     out = self.run_command(cmd)
     
     self.assert_file_contents_equal(EXPECTED_FILE, REPORT_FILE)
    def test_generate_with_report(self):
        self.set_modification_reference_time(testproject)
        OUTPUT_DIR = os.path.join(ROOT_PATH, 'temp/gen2/output')
        REPORT_FILE = os.path.join(ROOT_PATH, 'temp/gen2/report.html')
        self.remove_if_exists([OUTPUT_DIR, REPORT_FILE])
        cmd = '%s -p "%s" -c "%s" -o "%s" -r "%s"' % (get_cmd('generate'),
                                                      testproject, rootconf,
                                                      OUTPUT_DIR, REPORT_FILE)
        out = self.run_command(cmd)
        self.assert_exists_and_contains_something(OUTPUT_DIR)
        self.assert_exists_and_contains_something(REPORT_FILE)

        self.assert_not_modified(testproject)
Example #29
0
    def test_merge_cpf_last_layer_to_project(self):
        project_dir, expected_dir = self._prepare_workdir_with_project(
            'last_layer_from_cpf', 'last_layer_expected.zip')

        self.set_modification_reference_time(project_dir)
        self.set_modification_reference_time(TEST_VARIANT_CPF)
        cmd = '%s -p "%s" -r "%s" -c root5.confml -l -1 -v 5' % (
            get_cmd('merge'), project_dir, TEST_VARIANT_CPF)
        self.run_command(cmd)

        self.assert_modified(project_dir)
        self.assert_not_modified(TEST_VARIANT_CPF)
        self.assert_dir_contents_equal(expected_dir, project_dir)
Example #30
0
 def _run_test_invalid_configuration_args(self, config_args, expected_msg):
     REPORT_FILE = os.path.join(temp_dir, "dummy_report.html")
     self.remove_if_exists(REPORT_FILE)
     cmd = '%s -p "%s" %s --report "%s"' \
         % (get_cmd('info'), VALUE_REPORT_PROJECT, config_args, REPORT_FILE)
     # Note: The following run_command() should really expect the
     #       return code 2, but for some reason when running from the
     #       standalone test set, the return value is 0
     out = self.run_command(cmd, expected_return_code = None)
     self.assertFalse(os.path.exists(REPORT_FILE))
     
     self.assertTrue(expected_msg in out,
                     "Expected message '%s' not in output ('%s')" % (expected_msg, out))