Exemple #1
0
 def _property_to_node(clazz, properties_node, key, properties):
     assert isinstance(properties_node, node)
     assert key in properties
     value = properties[key]
     if key in ['export_compilation_flags_requirements', 'extra_cflags']:
         properties_node.children.append(
             clazz._system_specific_property_to_node(key, properties))
     elif key in ['download_url', 'pkg_config_name']:
         properties_node.children.append(node('%s=%s' % (key, value)))
     else:
         if clazz.CHECK_UNKNOWN_PROPERTIES:
             raise RuntimeError('Unknown property: %s' % (key))
         else:
             properties_node.children.append(node('%s=%s' % (key, value)))
     del properties[key]
Exemple #2
0
  def test_to_string(self):
    n = node('root')
    n.add_child('fruits')
    fruits = n.find_child_by_data('fruits')
    fruits.add_child('kiwi')
    fruits.add_child('strawberry')
    fruits.add_child('melons')
    melons = fruits.find_child_by_data('melons')
    melons.add_child('watermelon')
    melons.add_child('canteloupe')
    n.add_child('cheeses')
    cheeses = n.find_child_by_data('cheeses')
    cheeses.add_child('gouda')
    cheeses.add_child('brie')

    expected='''root
  fruits
    kiwi
    strawberry
    melons
      watermelon
      canteloupe
  cheeses
    gouda
    brie
'''
    self.assertEqual( expected, str(n) )
Exemple #3
0
 def _to_node(self):
     'A convenient way to make a recipe string is to build a graph first.'
     root = node(
         'package %s %s %s' %
         (self.descriptor.name, self.descriptor.version.upstream_version,
          self.descriptor.version.revision))
     if self.enabled != '':
         root.add_child('enabled=%s' % (self.enabled))
         root.add_child('')
     if self.variables:
         root.children.append(
             self._masked_value_list_to_node('variables', self.variables))
         root.add_child('')
     if self.properties:
         root.children.append(self._properties_to_node(self.properties))
         root.add_child('')
     if self.requirements:
         root.children.append(
             self._requirements_to_node('requirements', self.requirements))
         root.add_child('')
     root.children.append(self._steps_to_node(self.steps))
     if self.load:
         root.add_child('')
         root.children.append(self._load_to_node(self.load))
     return root
Exemple #4
0
 def test_flat_paths(self):
   r = node('root')
   r.ensure_path([ 'cheese', 'blue' ])
   r.ensure_path([ 'cheese', 'brie' ])
   r.ensure_path([ 'cheese', 'gouda' ])
   r.ensure_path([ 'foo' ])
   r.ensure_path([ 'fruit', 'apple' ])
   r.ensure_path([ 'fruit', 'kiwi' ])
   r.ensure_path([ 'fruit', 'melon', 'canteloupe' ])
   r.ensure_path([ 'fruit', 'melon', 'watermelon' ])
   r.ensure_path([ 'wine', 'chianti' ])
   r.ensure_path([ 'wine', 'sancere' ])
   paths = sorted(r.flat_paths())
   self.assertEqual( [
     [ 'root', 'cheese', 'blue' ],
     [ 'root', 'cheese', 'brie' ],
     [ 'root', 'cheese', 'gouda' ],
     [ 'root', 'foo' ],
     [ 'root', 'fruit', 'apple' ],
     [ 'root', 'fruit', 'kiwi' ],
     [ 'root', 'fruit', 'melon', 'canteloupe' ],
     [ 'root', 'fruit', 'melon', 'watermelon' ],
     [ 'root', 'wine', 'chianti' ],
     [ 'root', 'wine', 'sancere' ],
   ], [ x.path for x in paths ] )
Exemple #5
0
 def _system_specific_property_to_node(clazz, key, properties):
     assert key in properties
     value = properties[key]
     check.check_masked_value_list(value)
     child = node(key)
     for i in value:
         child.add_child(i)
     return child
Exemple #6
0
 def _temp_item_seq_to_node(clazz, label, items):
     result = node(label)
     for item in items:
         check.check_temp_item(item)
         item_node = result.add_child(item.filename)
         for line in item.content.split('\n'):
             item_node.add_child(line)
     return result
Exemple #7
0
 def _to_node(self):
   'A convenient way to make a recipe string is to build a graph first.'
   root = node(self.name)
   for key, value in sorted(self.flags.items()):
     root.add_child(key).add_child(value)
   requires_node = root.add_child('requires')
   for req in sorted(self.requires):
     requires_node.add_child(req)
   return root
  def test_simple1(self):
    self.maxDiff = None
    text = '''
fruits
  apple
  kiwi
'''
    expected = node(TDATA('root', 0))
    expected.ensure_path([ TDATA('fruits', 2), TDATA('apple', 3) ])
    expected.ensure_path([ TDATA('fruits', 2), TDATA('kiwi', 4) ])

    self.assertMultiLineEqual( expected.to_string(data_func = self._data_func), self._parse(text) )
  def test_strip_quote_in_comments(self):
    self.maxDiff = None
    text = '''
fruits
  apple
  kiwi
###              fprintf(stderr, "Usage: cut.exe args\\n");
'''
    expected = node(TDATA('root', 0))
    expected.ensure_path([ TDATA('fruits', 2), TDATA('apple', 3) ])
    expected.ensure_path([ TDATA('fruits', 2), TDATA('kiwi', 4) ])

    self.assertMultiLineEqual( expected.to_string(data_func = self._data_func), self._parse(text, strip_comments = True) )
Exemple #10
0
 def _steps_to_node(clazz, steps):
     result = node('steps')
     for step in steps:
         step_node = result.add_child(step.name)
         for value in step.values:
             if len(value.values) == 1 and value.values[0].mask is None:
                 step_node.add_child(str(value))
             else:
                 value_node = step_node.add_child(value.key)
                 for masked_value in value.values:
                     masked_value_node = value_node.add_child(
                         masked_value.to_string(quote=False))
         result.add_child('')
     return result
  def test_strip_comments(self):
    self.maxDiff = None
    text = '''
# comment
fruits # comment
  # comment
  apple
  # comment
  kiwi
# comment
'''
    expected = node(TDATA('root', 0))
    expected.ensure_path([ TDATA('fruits', 3), TDATA('apple', 5) ])
    expected.ensure_path([ TDATA('fruits', 3), TDATA('kiwi', 7) ])

    self.assertMultiLineEqual( expected.to_string(data_func = self._data_func), self._parse(text, strip_comments = True) )
 def _to_node(self):
     'A convenient way to make a string is to build a graph first.'
     root = node(self.filename)
     if self.sources:
         sources_node = root.add_child('sources')
         for source in self.sources:
             sources_node.children.append(source.to_node())
     if self.headers:
         headers_node = root.add_child('headers')
         for source in self.headers:
             headers_node.children.append(source.to_node())
     if self.ldflags:
         ldflags_node = root.add_child('ldflags')
         for ldflag in self.ldflags:
             ldflag_node.children.append(ldflag)
     return root
  def test_indent_mixed_tabs_spaces(self):
    text = '''
fruits
  apple
  berries
  \tblueberries
  \tstrawberries
  melons
  \twatermelon
cheeses
  parmessan
  asiago
'''
    expected = node(TDATA('root', 0))
    expected.ensure_path([ TDATA('fruits', 2), TDATA('apple', 3) ])
    expected.ensure_path([ TDATA('fruits', 2), TDATA('berries', 4), TDATA('blueberries', 5) ])
    expected.ensure_path([ TDATA('fruits', 2), TDATA('berries', 4), TDATA('strawberries', 6) ])
    expected.ensure_path([ TDATA('fruits', 2), TDATA('melons', 7), TDATA('watermelon', 8) ])
    expected.ensure_path([ TDATA('cheeses', 9), TDATA('parmessan', 10) ])
    expected.ensure_path([ TDATA('cheeses', 9), TDATA('asiago', 11) ])
    
    self.assertMultiLineEqual( str(expected), self._parse(text) )
  def test_simple2(self):
    self.maxDiff = None
    text = '''
fruits
  apple
  berries
    blueberries
    strawberries
  melons
    watermelon
cheeses
  parmessan
  asiago
'''
    expected = node(TDATA('root', 0))
    expected.ensure_path([ TDATA('fruits', 2), TDATA('apple', 3) ])
    expected.ensure_path([ TDATA('fruits', 2), TDATA('berries', 4), TDATA('blueberries', 5) ])
    expected.ensure_path([ TDATA('fruits', 2), TDATA('berries', 4), TDATA('strawberries', 6) ])
    expected.ensure_path([ TDATA('fruits', 2), TDATA('melons', 7), TDATA('watermelon', 8) ])
    expected.ensure_path([ TDATA('cheeses', 9), TDATA('parmessan', 10) ])
    expected.ensure_path([ TDATA('cheeses', 9), TDATA('asiago', 11) ])

    self.assertMultiLineEqual( expected.to_string(data_func = self._data_func), self._parse(text) )
Exemple #15
0
 def _to_node(self):
     'A convenient way to make a recipe string is to build a graph first.'
     root = node('fake_package')
     metadata = root.add_child('metadata')
     for field in self.metadata._fields:
         value = getattr(self.metadata, field)
         metadata.add_child('{field} {value}'.format(field=field,
                                                     value=getattr(
                                                         self.metadata,
                                                         field)))
     if self.files:
         self._temp_item_seq_to_node('files', self.files)
         root.add_child('')
     if self.env_files:
         self._temp_item_seq_to_node('env_files', self.env_files)
         root.add_child('')
     if self.requirements:
         root.children.append(
             self._requirements_to_node('requirements', self.requirements))
         root.add_child('')
     if self.properties:
         root.children.append(self._properties_to_node(self.properties))
         root.add_child('')
     return root
Exemple #16
0
 def _property_to_node(clazz, properties_node, key, properties):
     assert isinstance(properties_node, node)
     assert key in properties
     value = properties[key]
     properties_node.children.append(node('%s=%s' % (key, value)))
Exemple #17
0
 def _properties_to_node(clazz, properties):
     properties_node = node('properties')
     for key in sorted([key for key in properties.keys()]):
         clazz._property_to_node(properties_node, key, properties)
     return properties_node
Exemple #18
0
 def _load_to_node(clazz, load):
     result = node('load')
     for l in load:
         result.add_child(l)
     return result
Exemple #19
0
 def _make_tree(self, paths):
   n = node('root')
   for p in paths:
     n.ensure_path(p.split('/'))
   return n
Exemple #20
0
 def test_add_child(self):
   n = node('root')
   n.add_child('fruits')
   self.assertEqual( 1, n.num_children() )
   self.assertEqual( node('fruits'), n.find_child_by_data('fruits') )
Exemple #21
0
 def to_node(self):
   'A convenient way to make a string is to build a graph first.'
   root = node(self.filename)
   for line in self.source_code.split('\n'):
     root.add_child(line)
   return root
Exemple #22
0
 def test___init__(self):
   n = node('root')
   self.assertEqual( 0, n.num_children() )
   self.assertEqual( 'root', n.data )
   self.assertEqual( None, n.find_child_by_data('notthere') )
Exemple #23
0
 def _requirements_to_node(clazz, label, requirements):
     result = node(label)
     for req in requirements:
         result.add_child(req.to_string_colon_format())
     return result
Exemple #24
0
 def _masked_value_list_to_node(clazz, key, mvl):
     result = node(key)
     for mv in mvl:
         result.add_child(mv.to_string())
     return result