def test_generate_delta_cenreps(self): project_dir = abspath('gen_project') config = 'root2.confml' output_dir = abspath('temp/gen_output_deltacenrep') expected_dir = abspath('gen_expected_deltacenrep') self.remove_if_exists(output_dir) prj = api.Project(api.Storage.open(project_dir)) config = prj.get_configuration(config) gc = plugin.GenerationContext(configuration=config, output=output_dir) # Get refs from the last layer layer = config.get_configuration_by_index(-1) refs = utils.distinct_array(layer.list_leaf_datas()) impls = plugin.get_impl_set(config, 'crml$') impls = impls | plugin.get_impl_set(config, 'implml$') impls = impls.filter_implementations(refs=refs) gc.tags['crml'] = ['deltacenrep'] gc.changed_refs = refs gc.filtering_disabled = True impls.generate(gc) impls.post_generate(gc) output_dir = os.path.join(output_dir, 'deltacenreps') self.assert_dir_contents_equal(output_dir, expected_dir, ['.svn'])
def test_compare(self): conf1 = self._open_config('comp_project_1') conf2 = self._open_config('comp_project_2') crml_file = None repo_uid = None def entry(**kwargs): kwargs['file'] = crml_file kwargs['impl_type'] = 'crml' kwargs['id'] = repo_uid return plugin.FlatComparisonResultEntry(**kwargs) comparison_result = None crml_file = 'Layer1/implml/00000001_simple_keys.crml' impl_filter = '00000001_simple_keys.crml$' repo_uid = '0x00000001' impls1 = plugin.get_impl_set(conf1, impl_filter) impls2 = plugin.get_impl_set(conf2, impl_filter) actual_result = impls1.flat_compare(impls2) expected_mods = [ entry(sub_id='0x00000001', value_id='type', source_value='int', target_value='real'), entry(sub_id='0x00000002', value_id='backup', source_value=True, target_value=False), entry(sub_id='0x00000003', value_id='read_only', source_value=True, target_value=False), entry(sub_id='0x00000004', value_id='read_only', source_value=False, target_value=True), # Changing read-only changes also cap_wr entry(sub_id='0x00000003', value_id='cap_wr', source_value='AlwaysFail', target_value=None), entry(sub_id='0x00000004', value_id='cap_wr', source_value=None, target_value='AlwaysFail'), entry(sub_id='0x00000005', value_id='type', source_value='int', target_value='real'), entry(sub_id='0x00000006', value_id='name', source_value='Setting 6', target_value='Setting 6 (name changed)'), entry(sub_id='0x00000007', value_id='ref', source_value='SimpleKeys.Setting7', target_value='SimpleKeys.Setting7RefChanged'), entry(sub_id='0x00000008', value_id='cap_rd', source_value='ReadDeviceData', target_value='ReadUserData'), entry(sub_id='0x00000008', value_id='cap_wr', source_value='WriteDeviceData', target_value='WriteUserData'), entry(sub_id='0x00000008', value_id='sid_rd', source_value='0xAABBCCDD', target_value='0x11223344'), entry(sub_id='0x00000008', value_id='sid_wr', source_value='0xDDCCBBAA', target_value='0x44332211'), entry(sub_id='0x00000009', value_id='cap_rd', source_value='ReadDeviceData', target_value=None), entry(sub_id='0x00000009', value_id='cap_wr', source_value='WriteDeviceData', target_value=None), entry(sub_id='0x00000009', value_id='sid_rd', source_value='0xAABBCCDD', target_value=None), entry(sub_id='0x00000009', value_id='sid_wr', source_value='0xDDCCBBAA', target_value=None), ] expected_removed = [ entry(sub_id='0x10000001'), entry(sub_id='0x10000002'), ] expected_added = [ entry(sub_id='0x20000001'), entry(sub_id='0x20000002'), ] expected_result = plugin.FlatComparisonResult(modified=expected_mods, only_in_source=expected_removed, only_in_target=expected_added) self.assertEquals(actual_result, expected_result)
def test_impl_container_execute_pre_rules(self): project = api.Project( api.Storage.open(os.path.join(ROOT_PATH, 'ruleproject/rules'), "a")) config = project.get_configuration('root.confml') implcontainer = plugin.get_impl_set(config, 'ruleml$') ruleimpl = implcontainer.get_implementations_by_file( 'implml/container_with_rules.ruleml')[0] context = plugin.GenerationContext(configuration=config) context.phase = "pre" ruleimpl.generate(context) lastconfig = config.get_last_configuration() self.assertEquals(lastconfig.get_path(), plugin.AUTOCONFIG_CONFML) self.assertEquals(lastconfig.list_all_datas(), [ 'imakerapi', 'imakerapi.outputLocation', 'StringConcatenationTest', 'StringConcatenationTest.Result1', 'StringConcatenationTest.Result2' ]) self.assertEquals( lastconfig.get_data('imakerapi.outputLocation').get_ref(), 'outputLocation') self.assertEquals( lastconfig.get_data('imakerapi.outputLocation').get_value(), '2') project.close()
def test_rule_with_empty_value1(self): return project = api.Project( api.Storage.open(os.path.join(ROOT_PATH, 'ruleproject/rules'), "a")) config = project.get_configuration('root.confml') implcontainer = plugin.get_impl_set(config) implcontainer.generate() lastconfig = config.get_last_configuration() self.assertEquals(lastconfig.get_path(), ruleml.RuleImpl.AUTOCONFIGURATION_CONFML) self.assertEquals( lastconfig.get_data('imakerapi.outputLocation').get_ref(), 'outputLocation') self.assertEquals( lastconfig.get_data('imakerapi.outputLocation').get_value(), '2') self.assertEquals( lastconfig.get_data('imakerapi.outputLocationY').get_value(), 'hello') self.assertEquals( lastconfig.get_data('operations.minus').get_value(), '18') self.assertEquals( lastconfig.get_data('operations.minus1').get_value(), '35') self.assertEquals( lastconfig.get_data('operations.minus4').get_value(), '5') project.close()
def test_configuration_parse_and_filter_implementation_with_tags(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.content$') impls_rofs3 = impls.filter_implementations(tags={'target': ['rofs3']}) self.assertEquals(len(list(impls_rofs3)), 3)
def test_create_context_dict_and_list(self): config = self.load_config('create_dict_test.confml') impls = plugin.get_impl_set(config, r'^create_dict_test/implml/test\.templateml$') self.assertEquals(1, len(impls)) impl = iter(impls).next() context = impl.create_dict() feat_tree = context['feat_tree'] feat_list = context['feat_list'] self.assertEqual(context['configuration'], config) # Check the created dictionary expected_tree_file = os.path.join(ROOT_PATH, 'create_dict_test', 'expected_tree.txt') expected_tree = eval(self.read_data_from_file(expected_tree_file).replace('\r', '')) if feat_tree != expected_tree: dir = os.path.join(ROOT_PATH, "temp", "create_dict_test", "tree") self.create_dir(dir) filename = os.path.join(dir, "expected.txt") self.write_data_to_file(filename, self.feature_tree_to_str(expected_tree)) filename = os.path.join(dir, "actual.txt") self.write_data_to_file(filename, self.feature_tree_to_str(feat_tree)) self.fail("Feature tree is not what was expected, see the files in '%s'" % dir) # Check the created list expected_list_file = os.path.join(ROOT_PATH, 'create_dict_test', 'expected_list.txt') expected_list = eval(self.read_data_from_file(expected_list_file).replace('\r', '')) if feat_list != expected_list: dir = os.path.join(ROOT_PATH, "temp", "create_dict_test", "list") self.create_dir(dir) filename = os.path.join(dir, "expected.txt") self.write_data_to_file(filename, self.feature_list_to_str(expected_list)) filename = os.path.join(dir, "actual.txt") self.write_data_to_file(filename, self.feature_list_to_str(feat_list)) self.fail("Feature list is not what was expected, see the files in '%s'" % dir)
def test_rules_get_refs(self): project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "a" )) config = project.get_configuration('root.confml') implcontainer = plugin.get_impl_set(config, 'ruleml$') ruleimpl = implcontainer.get_implementations_by_file('implml/container_with_rules.ruleml')[0] self.assertEquals(ruleimpl.get_child_refs(), [u'imakerapi.PRODUCT_NAME', u'imaker.imagetarget']) self.assertEquals(len(ruleimpl.get_outputs()), 8) outputs = [output.name for output in ruleimpl.get_outputs()] self.assertEquals(outputs, [u'imakerapi.PRODUCT_NAME', u'imakerapi.outputLocation', u'StringConcatenationTest.Result1', u'StringConcatenationTest.Result2', u'StringConcatenationTest.Result3', u'StringConcatenationTest.Result4', u'StringConcatenationTest.Result5', u'StringConcatenationTest.Result6']) inputs = [] for output in ruleimpl.get_outputs(): inputs += output.implementation.get_refs() self.assertEquals(inputs, [u'imakerapi.PRODUCT_NAME', u'imaker.imagetarget']) impls_refs = [] for output in ruleimpl.get_outputs(): impls_refs.append("%s <= %s" % (output.name, output.implementation.implml.ref)) self.assertEquals(impls_refs, [u'imakerapi.PRODUCT_NAME <= implml/container_with_rules.ruleml', u'imakerapi.outputLocation <= implml/container_with_rules.ruleml', u'StringConcatenationTest.Result1 <= implml/container_with_rules.ruleml', u'StringConcatenationTest.Result2 <= implml/container_with_rules.ruleml', u'StringConcatenationTest.Result3 <= implml/container_with_rules.ruleml', u'StringConcatenationTest.Result4 <= implml/container_with_rules.ruleml', u'StringConcatenationTest.Result5 <= implml/container_with_rules.ruleml', u'StringConcatenationTest.Result6 <= implml/container_with_rules.ruleml'])
def test_generate(self): orig_workdir = os.getcwd() os.chdir(ROOT_PATH) try: OUTPUT_DIR = os.path.join(ROOT_PATH, 'output') self.remove_if_exists(OUTPUT_DIR) self.remove_if_exists(['hello.log', 'exec_in_output_test.log',]) fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') context = plugin.GenerationContext(configuration=config, output=OUTPUT_DIR) impls = plugin.get_impl_set(config,'file2\.commandml$') #impls.output = OUTPUT_DIR impls.generate(context) self.assert_file_content_equals('hello.log', "Hello" + os.linesep + "Cmd line args: ['-c', 'some_config.txt', '-d', 'some_dir', '-x']" + os.linesep) self.assert_file_content_equals('exec_in_output_test.log', os.path.normpath(OUTPUT_DIR) + os.linesep) # Check that the log file of the command that should not be # executed does not exist self.assertFalse(os.path.exists("should_not_be_created.log")) self.assertTrue(os.path.exists(os.path.join(OUTPUT_DIR,"helloworld.txt"))) self.assertEquals(len(context.generation_output), 1) self.assertEquals(utils.relpath(context.generation_output[0].name, OUTPUT_DIR), 'helloworld.txt') self.assertEquals(context.generation_output[0].implementation.ref, 'assets/s60/implml/file2.commandml') finally: os.chdir(orig_workdir)
def _get_impl_and_set(self, ref): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impl_set = plugin.get_impl_set(config, re.escape(ref) + '$') self.assertEquals(len(impl_set), 1) return iter(impl_set).next(), impl_set
def load_impl(self, resource_ref, config='root1.confml'): configuration = self.load_config(config) pattern = '^' + resource_ref.replace('.', r'\.') + '$' impls = plugin.get_impl_set(configuration, pattern) impls.output = self.output impl_list = impls.get_implementations_by_file(resource_ref) self.assertEquals(1, len(impl_list)) return (configuration,impl_list[0])
def _execute_rules(self, project_location): project = api.Project(api.Storage.open(os.path.join(ROOT_PATH, project_location))) config = project.get_configuration('root.confml') context = plugin.GenerationContext(configuration=config) implcontainer = plugin.get_impl_set(config, r'\.ruleml$') implcontainer.get_relation_container().execute(context) lastconfig = config.get_last_configuration() project.close()
def test_example_parse_and_generate_prj2(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('root1.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'Layer1/implml/feature1.gcfml')[0] impls.generate()
def test_predefined_contacts_parse_and_generate(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'assets/s60/implml/predefinedcontacts.gcfml')[0] impls.generate()
def test_implml_override(self): p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) config = p.get_configuration('root.confml') impl_set = plugin.get_impl_set(config) self.assertEquals([impl.ref for impl in impl_set], ['layer2/implml/test.implml']) impl_set = plugin.filtered_impl_set(config) self.assertEquals([impl.ref for impl in impl_set], ['layer2/implml/test.implml'])
def test_configuration_content_generate(self): config = self.load_config() impls = plugin.get_impl_set(config, '\.content$') context = plugin.GenerationContext(output=self.output) results = impls.generate(context) self.assertTrue(os.path.exists(impls.output)) self.assertTrue( os.path.exists( os.path.join(context.output, 'content/prodX/jee/ProdX_specific.txt')))
def _execute_rules(self, impl_filter): implcontainer = plugin.get_impl_set(self.config, impl_filter) context = plugin.GenerationContext(configuration=self.config) context.output = os.path.join(ROOT_PATH, 'temp/output') if not os.path.exists(context.output): os.makedirs(context.output) implcontainer.generate(context) return context.generation_output
def test_get_refs(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'assets/s60/implml/commsdatcreator_01.gcfml')[0] self.assertEquals(impl.get_refs(), ['APs.AP', 'WLAN_APs.WLAN_AP']) self.assertTrue(impl.has_ref(['APs.AP']))
def test_example_parse_prj(self): output_dir = os.path.join(temp_dir, "new_project2") if os.path.exists(output_dir): shutil.rmtree(output_dir) fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, r'file1\.convertprojectml$') self.assertEquals(1, len(impls)) impl = iter(impls).next() self.assertTrue(isinstance(impl, convertproject.ConvertProjectImpl))
def test_list_output_files(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'assets/s60/implml/predefinedcontacts.gcfml')[0] normalize_slash = lambda l: map(lambda p: p.replace('\\', '/'), l) self.assertEquals(normalize_slash(impl.list_output_files()), ['private/2000BEE5/predefinedcontacts.xml'])
def test_rule_with_empty_value2(self): return project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'rule/config_project/platforms/customsw'), "a" )) config = project.get_configuration('root.confml') implcontainer = plugin.get_impl_set(config) implcontainer.generate() lastconfig = config.get_last_configuration() self.assertEquals(lastconfig.get_data('operations.minus').get_value(),'18') self.assertEquals(lastconfig.get_data('operations.minus1').get_value(),'35') self.assertEquals(lastconfig.get_data('operations.minus4').get_value(),'5') self.assertEquals(lastconfig.get_data('operations.minus6').get_value(),'19') self.assertEquals(lastconfig.get_data('operations.string1').get_value(),'HelloWorld') project.close()
def test_has_ref(self): fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('product.confml') impls = plugin.get_impl_set(config, '\.gcfml$') impls.output = self.output impl = impls.get_implementations_by_file( 'assets/s60/implml/predefinedcontacts.gcfml')[0] self.assertEquals(impl.get_refs(), ['Contacts.Contact']) self.assertFalse(impl.has_ref(['ref1', 'ref2'])) self.assertTrue(impl.has_ref(['Contacts.Contact'])) self.assertTrue(impl.has_ref(['Contacts.Contact.FirstName'])) self.assertFalse(impl.has_ref(['Contacts.OtherSetting']))
def test_impl_container_execute_rules(self): project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "r" )) config = project.get_configuration('root.confml') implcontainer = plugin.get_impl_set(config, 'ruleml$') context = plugin.GenerationContext(configuration=config) implcontainer.generate(context) lastconfig = config.get_last_configuration() self.assertEquals(lastconfig.get_path(), plugin.AUTOCONFIG_CONFML) self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_ref(),'outputLocation') self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_value(),'2') project.close()
def validate_impls(configuration, filter='.*', validator_classes=None): """ Validate all implementations in the given configuration. @param filter: Regex for filtering the implementations to validate. @param validator_classes: The validator classes to use for the validation. If None, all validator classes will be used. """ # Set up the parse context to collect problems from the parsing phase context = ValidationParseContext() parsecontext.set_implml_context(context) impl_set = plugin.get_impl_set(configuration, filter=filter) problems = validate_impl_set(impl_set, configuration, validator_classes) return context.problems + problems
def test_get_impl_container(self): project = api.Project( api.Storage.open(os.path.join(ROOT_PATH, 'ruleproject/rules'))) config = project.get_configuration('root.confml') implcontainer = plugin.get_impl_set(config, 'ruleml$') impl = implcontainer.get_implementations_by_file( 'implml/rules.ruleml')[0] EXPECTED_REFS = sorted([ 'imaker.imagetarget', 'mms.imagesize', 'imakerapi.outputLocationY', 'operations.minus', 'operations.minus1', 'operations.minus4', 'operations.minus6', 'Foo.Bar' ]) self.assertEquals(EXPECTED_REFS, sorted(impl.get_child_refs())) self.assertEquals([], impl.list_output_files())
def test_generate_from_project(self): project_dir = abspath('testdata/generation/project') config = 'root.confml' output_dir = abspath('temp/generation/output') expected_dir = abspath('testdata/generation/expected') self.remove_if_exists(output_dir) prj = api.Project(api.Storage.open(project_dir)) config = prj.get_configuration(config) context = plugin.GenerationContext(configuration=config, output=output_dir) impls = plugin.get_impl_set(config) impls.generate(context) self.assert_dir_contents_equal(output_dir, expected_dir, ['.svn'])
def test_create_generator_from_project_and_generate_all(self): orig_workdir = os.getcwd() os.chdir(ROOT_PATH) try: output = os.path.join(ROOT_PATH, "temp/output_all") self.recreate_dir(output) prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject"))) config = prj.get_configuration('product.confml') context = plugin.GenerationContext(configuration=config, output=output) context.filtering_disabled = True impl_set = plugin.get_impl_set(config, 'imageml$') self.assertEquals(len(impl_set), 5) impl_set.generate(context) def check_gen(p): self.assert_exists_and_contains_something(os.path.join(output, p)) def check_not_gen(p): self.assertFalse(os.path.exists(os.path.join(output, p)), "'%s' exists when it should not!" % p) try: check_gen('startup.mbm') check_gen('startup_mif.mif') check_not_gen('optional1_mbm.mbm') check_gen('optional2_mbm.mbm') check_not_gen('optional3_mbm.mbm') check_not_gen('optional4_mbm.mbm') check_not_gen('optional1_mif.mif') check_gen('optional2_mif.mif') check_not_gen('optional3_mif.mif') check_not_gen('optional4_mif.mif') check_gen('resource/apps/startup.mif') check_gen('depth_from_ref_test_mbm.mbm') check_gen('depth_from_ref_test_mif.mif') except AssertionError, e: if ' ' in ROOT_PATH: self.fail("Known bug (#177): %s" % e) else: raise finally: os.chdir(orig_workdir)
def _run_gen_test(self, layer, ignores=[]): project_dir = abspath('project') config = 'root%s.confml' % layer output_dir = abspath('temp/gen_output%s' % layer) expected_dir = abspath('expected/root%s' % layer) self.remove_if_exists(output_dir) prj = api.Project(api.Storage.open(project_dir)) config = prj.get_configuration(config) context = plugin.GenerationContext(configuration=config, output=output_dir) context.filtering_disabled = True impls = plugin.get_impl_set(config, 'gcfml$') impls.generate(context) self.assert_dir_contents_equal(output_dir, expected_dir, ['.svn'] + ignores)
def test_rule_debug_messages(self): log_file, handler, logger = self._prepare_log('debug_msg_test.log') project = None try: project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "r" )) config = project.get_configuration('root.confml') implcontainer = plugin.get_impl_set(config, r'rules\.ruleml$') context = plugin.GenerationContext(configuration=config) implcontainer.generate(context) self.assert_file_contains(log_file, ["Set imakerapi.outputLocationY = 'hello' from ConfigureRelation(ref='implml/rules.ruleml', lineno=8)", "Set operations.minus = 18 from ConfigureRelation(ref='implml/rules.ruleml', lineno=9)", "Set SequenceTest.Sequence1 = [['foo', 1], ['bar', 2], ['baz', 3]] from ConfigureRelation(ref='implml/rules.ruleml', lineno=23)"]) finally: logger.removeHandler(handler) if project: project.close()
def test_generate(self): os.environ['ncp_version'] = 'platforms' os.environ['variants'] = 'variants' output_dir = os.path.join(temp_dir, "new_project") if os.path.exists(output_dir): shutil.rmtree(output_dir) expected_dir = os.path.join(ROOT_PATH, "expected/new_project") oldPath = os.path.join(ROOT_PATH, 'old_structure/epoc32/rom/config') fs = filestorage.FileStorage(oldPath) p = api.Project(fs) config = p.get_configuration('convert.confml') context = plugin.GenerationContext(configuration=config, output=output_dir) impls = plugin.get_impl_set(config, '\.convertprojectml$') context.filtering_disabled = True impls.generate(context) self.assert_dir_contents_equal(expected_dir, output_dir, ['.svn'])
def test_unicode_in_template_and_value(self): OUTPUT_DIR = os.path.join(ROOT_PATH, 'output', 'unicode_test') self.remove_if_exists(OUTPUT_DIR) fs = filestorage.FileStorage(testdata) p = api.Project(fs) config = p.get_configuration('root1.confml') impls = plugin.get_impl_set(config,'unicode_template_test\.templateml$') gc = plugin.GenerationContext(output=OUTPUT_DIR, configuration=config) impls.generate(gc) self.assert_exists_and_contains_something(os.path.join(OUTPUT_DIR, "unicode_template_test.txt")) # Check that the output exists and contains expected lines f = open(os.path.join(OUTPUT_DIR, "unicode_template_test.txt"), "rb") try: data = f.read().decode('utf-8') finally: f.close() self.assertTrue(data.find(u'Value of Feature1.UnicodeValueSetting: カタカナ') != -1) self.assertTrue(data.find(u'Unicode from template: ελληνικά') != -1)