def __init__(self, in_file_paths): super(MakeQualifiedNamesWriter, self).__init__(None) assert len( in_file_paths ) <= 2, 'MakeQualifiedNamesWriter requires at most 2 in files, got %d.' % len( in_file_paths) if len(in_file_paths) == 2: self.tags_in_file = InFile.load_from_files([in_file_paths.pop(0)], self.defaults, self.valid_values, self.default_parameters) else: self.tags_in_file = None self.attrs_in_file = InFile.load_from_files([in_file_paths.pop()], self.defaults, self.valid_values, self.default_parameters) self.namespace = self._parameter('namespace') self._outputs = { (self.namespace + "Names.h"): self.generate_header, (self.namespace + "Names.cpp"): self.generate_implementation, } self._template_context = { 'namespace': self.namespace, 'tags': self.tags_in_file.name_dictionaries if self.tags_in_file else [], 'attrs': self.attrs_in_file.name_dictionaries, }
def __init__(self, in_file_paths): super(MakeQualifiedNamesWriter, self).__init__(None) assert len(in_file_paths) <= 2, 'MakeQualifiedNamesWriter requires at most 2 in files, got %d.' % len(in_file_paths) if len(in_file_paths) == 2: self.tags_in_file = InFile.load_from_files([in_file_paths.pop(0)], self.defaults, self.valid_values, self.default_parameters) else: self.tags_in_file = None self.attrs_in_file = InFile.load_from_files([in_file_paths.pop()], self.defaults, self.valid_values, self.default_parameters) self.namespace = self._parameter('namespace') namespace_prefix = self._parameter('namespacePrefix') or self.namespace.lower() namespace_uri = self._parameter('namespaceURI') use_namespace_for_attrs = self.attrs_in_file.parameters['attrsNullNamespace'] is None self._outputs = { (self.namespace + "Names.h"): self.generate_header, (self.namespace + "Names.cpp"): self.generate_implementation, } self._template_context = { 'namespace': self.namespace, 'namespace_prefix': namespace_prefix, 'namespace_uri': namespace_uri, 'use_namespace_for_attrs': use_namespace_for_attrs, 'tags': self.tags_in_file.name_dictionaries if self.tags_in_file else [], 'attrs': self.attrs_in_file.name_dictionaries, }
def __init__(self, in_file_paths, enabled_conditions): super(MakeQualifiedNamesWriter, self).__init__(None, enabled_conditions) assert len(in_file_paths) <= 2, 'MakeQualifiedNamesWriter requires at most 2 in files, got %d.' % len(in_file_paths) if len(in_file_paths) == 2: self.tags_in_file = InFile.load_from_files([in_file_paths.pop(0)], self.defaults, self.valid_values, self.default_parameters) else: self.tags_in_file = None self.attrs_in_file = InFile.load_from_files([in_file_paths.pop()], self.defaults, self.valid_values, self.default_parameters) self.namespace = self._parameter('namespace') namespace_prefix = self._parameter('namespacePrefix') or self.namespace.lower() namespace_uri = self._parameter('namespaceURI') use_namespace_for_attrs = self.attrs_in_file.parameters['attrsNullNamespace'] is None self._outputs = { (self.namespace + "Names.h"): self.generate_header, (self.namespace + "Names.cpp"): self.generate_implementation, } self._template_context = { 'namespace': self.namespace, 'namespace_prefix': namespace_prefix, 'namespace_uri': namespace_uri, 'use_namespace_for_attrs': use_namespace_for_attrs, 'tags': self.tags_in_file.name_dictionaries if self.tags_in_file else [], 'attrs': self.attrs_in_file.name_dictionaries, }
def test_with_parameters(self): contents = """namespace=TestNamespace fruit name1 arg=value, arg2=value2, arg2=value3 name2 """ lines = contents.split("\n") defaults = { 'arg': None, 'arg2': [], } default_parameters = { 'namespace': '', 'fruit': False, } in_file = InFile(['test_with_parameters.in'], lines, defaults, default_parameters=default_parameters) expected_parameters = { 'namespace': 'TestNamespace', 'fruit': True, } self.assertEquals(in_file.parameters, expected_parameters)
def __init__(self, in_files): if isinstance(in_files, basestring): in_files = [in_files] if in_files: self.in_file = InFile.load_from_files(in_files, self.defaults, self.valid_values, self.default_parameters) else: self.in_file = None self._outputs = {} # file_name -> generator
def __init__(self, in_files, enabled_conditions): if isinstance(in_files, basestring): in_files = [in_files] self.in_file = InFile.load_from_files(in_files, self.defaults, self.valid_values, self.default_parameters) self._enabled_conditions = enabled_conditions self._outputs = {} # file_name -> generator
def __init__(self, in_files): super(Writer, self).__init__(in_files) if isinstance(in_files, basestring): in_files = [in_files] if in_files: self.in_file = InFile.load_from_files(in_files, self.defaults, self.valid_values, self.default_parameters) else: self.in_file = None
def test_assertion_for_non_in_files(self): in_files = ['some_sample_file.json'] assertion_thrown = False try: in_file = InFile.load_from_files(in_files, None, None, None) except AssertionError: assertion_thrown = True except: pass self.assertTrue(assertion_thrown)
def parse_features_file(features_text): valid_values = { 'status': ['stable', 'experimental', 'test'], } defaults = { 'condition': None, 'depends_on': [], 'custom': False, 'status': None, } # FIXME: in_file.py manually calls str.strip so conver to str here. features_lines = str(features_text).split("\n") return InFile(features_lines, defaults, valid_values)
def __init__(self, in_file_paths): super(MakeQualifiedNamesWriter, self).__init__(None) assert len(in_file_paths) <= 2, "MakeQualifiedNamesWriter requires at most 2 in files, got %d." % len( in_file_paths ) if len(in_file_paths) == 2: self.tags_in_file = InFile.load_from_files( [in_file_paths.pop(0)], self.defaults, self.valid_values, self.default_parameters ) else: self.tags_in_file = None self.attrs_in_file = InFile.load_from_files( [in_file_paths.pop()], self.defaults, self.valid_values, self.default_parameters ) self.namespace = self._parameter("namespace") namespace_prefix = self._parameter("namespacePrefix") or self.namespace.lower() namespace_uri = self._parameter("namespaceURI") use_namespace_for_attrs = self.attrs_in_file.parameters["attrsNullNamespace"] is None self._outputs = { (self.namespace + "Names.h"): self.generate_header, (self.namespace + "Names.cpp"): self.generate_implementation, } self._template_context = { "attrs": self.attrs_in_file.name_dictionaries, "export": self._parameter("export"), "namespace": self.namespace, "namespace_prefix": namespace_prefix, "namespace_uri": namespace_uri, "tags": self.tags_in_file.name_dictionaries if self.tags_in_file else [], "use_namespace_for_attrs": use_namespace_for_attrs, }
def __init__(self, in_file_path): # Assume that the class should be called the same as the file. self.class_name, _ = os.path.splitext(os.path.basename(in_file_path)) defaults = { 'condition' : None, 'depends_on' : [], 'default': 'false', 'custom': False, } self._all_features = InFile.load_from_path(in_file_path, defaults).name_dictionaries # Make sure the resulting dictionaries have all the keys we expect. for feature in self._all_features: feature['first_lowered_name'] = self._lower_first(feature['name']) # Most features just check their isFooEnabled bool # but some depend on more than one bool. enabled_condition = "is%sEnabled" % feature['name'] for dependant_name in feature['depends_on']: enabled_condition += " && is%sEnabled" % dependant_name feature['enabled_condition'] = enabled_condition self._non_custom_features = filter(lambda feature: not feature['custom'], self._all_features)
def __init__(self, in_file_path): # Assume that the class should be called the same as the file. self.class_name, _ = os.path.splitext(os.path.basename(in_file_path)) defaults = { 'condition': None, 'depends_on': [], 'default': 'false', 'custom': False, } self._all_features = InFile.load_from_path(in_file_path, defaults).name_dictionaries # Make sure the resulting dictionaries have all the keys we expect. for feature in self._all_features: feature['first_lowered_name'] = self._lower_first(feature['name']) # Most features just check their isFooEnabled bool # but some depend on more than one bool. enabled_condition = "is%sEnabled" % feature['name'] for dependant_name in feature['depends_on']: enabled_condition += " && is%sEnabled" % dependant_name feature['enabled_condition'] = enabled_condition self._non_custom_features = filter( lambda feature: not feature['custom'], self._all_features)
def test_basic_parse(self): contents = """ name1 arg=value, arg2=value2, arg2=value3 name2 """ lines = contents.split("\n") defaults = { 'arg': None, 'arg2': [], } in_file = InFile(lines, defaults, None) expected_values = [ { 'name': 'name1', 'arg': 'value', 'arg2': ['value2', 'value3'] }, { 'name': 'name2', 'arg': None, 'arg2': [] }, ] self.assertEquals(in_file.name_dictionaries, expected_values)
def __init__(self, in_file_path): self.in_file = InFile.load_from_path(in_file_path, self.defaults, self.default_parameters)