Exemplo n.º 1
0
    def test_parse(self):
        recipe = \
          R(AD('foo', '1.2.3', 0, 0, 'linux', 'release', 'x86_64', 'ubuntu', '18'),
            [
              temp_item('bin/tfoo.py', '#!/usr/bin/env python\nprint(\'foo\')\nraise SystemExit(0)\n', 0o755),
              temp_item('bin/tbar.py', '#!/usr/bin/env python\nprint(\'bar\')\nraise SystemExit(0)\n', 0o755),
            ],
            [
              temp_item('tfoo_env.sh', 'export TFOO_ENV1=tfoo_env1\n', 0o755),
              temp_item('tbar_env.sh', 'export TBAR_ENV1=tbar_env1\n', 0o755),
            ],
            RL.parse('apple >= 1.2.3 orange >= 6.6.6'),
            { 'prop1': '5', 'prop2': 'hi' },
            {}
          )
        content = '''
fake_package foo 1.2.3 0 0 linux release x86_64 ubuntu 18
  
  files
    bin/tfoo.py
      \#!/usr/bin/env python
      print('foo')
      raise SystemExit(0)

    bin/tbar.py
      \#!/usr/bin/env python
      print('bar')
      raise SystemExit(0)

  env_files
    tfoo_env.sh
      export TFOO_ENV1=tfoo_env1

    tbar_env.sh
      export TBAR_ENV1=tbar_env1

  requirements
    apple >= 1.2.3
    orange >= 6.6.6

  properties
    prop1=5
    prop2=hi
'''
        actual = self._parse(content)
        self.assertEqual(recipe.metadata, actual[0].metadata)
        self.assertEqual(recipe.properties, actual[0].properties)
        self.assertEqual(recipe.requirements, actual[0].requirements)
        self.assertEqual(recipe.files, actual[0].files)
        self.assertEqual(recipe.env_files, actual[0].env_files)
 def _parse_file(self, node):
     filename, content = fake_package_recipe_parser_util.parse_file(node)
     if file_util.extension(filename) in ['sh', 'py']:
         mode = 0o755
     else:
         mode = 0o644
     return temp_item(filename, content, mode)
Exemplo n.º 3
0
    def test___str__(self):
        r = R(
            AD('foo', '1.2.3', 0, 0, 'linux', 'release', 'x86_64', 'ubuntu',
               '18'), [
                   temp_item('bin/foo.sh', '#!/bin/bash\necho foo\nexit 0\n',
                             0o755),
                   temp_item('bin/bar.sh', '#!/bin/bash\necho bar\nexit 1\n',
                             0o755),
               ], [
                   temp_item('foo_env.sh',
                             '#@REBUILD_HEAD@\nexport FOO_ENV=foo\n', 0o644),
                   temp_item('bar_env.sh',
                             '#@REBUILD_HEAD@\nexport BAR_ENV=bar\n', 0o644),
               ], RL.parse('apple >= 1.2.3 orange >= 6.6.6'), {
                   'prop1': 5,
                   'prop2': 'hi'
               }, {})
        expected = '''fake_package
  metadata
    name foo
    version 1.2.3
    revision 0
    epoch 0
    system linux
    level release
    arch ('x86_64',)
    distro ubuntu
    distro_version 18


  requirements
    all: apple >= 1.2.3
    all: orange >= 6.6.6

  properties
    prop1=5
    prop2=hi'''
        self.assertMultiLineEqual(expected, str(r))
Exemplo n.º 4
0
 def make_test_package(clazz, pm, debug = False):
   pkg_config_pc_contnet = clazz.make_pkg_config_pc_content(pm.name, pm.build_version)
   script_content = '#!/bin/bash\necho %s-%s\nexit 0\n' % (pm.name, pm.build_version)
   name = pm.name.replace('_conflict', '')
   items = [
     clazz.make_temp_item(name, pm.version, '_foo.txt', 'docs'),
     clazz.make_temp_item(name, pm.version, '_bar.txt', 'docs'),
     clazz.make_temp_item(name, pm.version, '_script.sh', 'bin', content = script_content, mode = 0o755),
     temp_item('lib/pkgconfig/%s.pc' % (name), content = pkg_config_pc_contnet)
   ]
   tmp_stage_dir = temp_file.make_temp_dir(delete = not debug)
   tmp_stage_files_dir = path.join(tmp_stage_dir, 'files')
   temp_file.write_temp_files(tmp_stage_files_dir, items)
   tmp_tarball = temp_file.make_temp_file(prefix = pm.package_descriptor.full_name, suffix = '.tar.gz', delete = not debug)
   package.create_package(tmp_tarball, pm.package_descriptor, pm.build_target, tmp_stage_dir)
   return clazz.test_package(tmp_tarball, pm)
Exemplo n.º 5
0
 def make_temp_item(clazz, name, version, suffix, location, content = None, mode = None):
   filename = '%s/%s%s' % (location, name, suffix)
   if not content:
     content = 'package=%s-%s\nfilename=%s' % (name, version, filename)
   return temp_item(filename, content = content, mode = mode)