def test_tasks_finalize(self):
        expected = '''apps:
  pipelinetest:
    command: ./bin/test
description: 'This is an example package of an autotools project built with snapcraft

  using a remote source.

  '
name: pipelinetest
parts:
  kanku:
    after:
    - libpipeline
    plugin: make
    source: kanku
  libpipeline:
    plugin: autotools
    source: libpipeline
summary: Libpipeline example
version: 1.0
'''
        self._cd_fixtures_dir()
        tasks           = TarSCM.tasks()
        if not os.path.exists(self.cli.outdir):
            os.makedirs(self.cli.outdir)
        tasks.generate_list(self.cli)
        tasks.finalize(self.cli)
        i = 0
        self._restore_cwd()
        sf  = open(os.path.join(self.cli.outdir,'_service:snapcraft:snapcraft.yaml'),'r')
        got = sf.read()
        sf.close()
        self.assertEqual(got,expected)
    def test_tasks_finalize(self):
        expected = '''\
apps:
  pipelinetest:
    command: ./bin/test
description: 'This is an example package of an autotools project built with snapcraft

  using a remote source.

  '
name: pipelinetest
parts:
  kanku:
    after:
    - libpipeline
    plugin: make
    source: kanku
  libpipeline:
    plugin: autotools
    source: libpipeline
summary: Libpipeline example
version: 1.0
'''  # noqa
        self._cd_fixtures_dir()
        if not os.path.exists(self.cli.outdir):
            os.makedirs(self.cli.outdir)
        tasks = TarSCM.Tasks(self.cli)
        tasks.generate_list()
        tasks.finalize()
        self._restore_cwd()
        snf = os.path.join(self.cli.outdir,'_service:snapcraft:snapcraft.yaml')
        with open(snf, 'r', encoding='utf-8') as scf:
            got = scf.read()
        self.assertEqual(got, expected)
 def test_generate_tl_multi_tasks(self):
     expected = {
         'libpipeline': {
             'changesgenerate': False,
             'clone_prefix': '_obs_',
             'filename': 'libpipeline',
             'outdir': self.cli.outdir,
             'revision': None,
             'scm': 'bzr',
             'snapcraft': True,
             'url': 'lp:~mterry/libpipeline/printf',
             'use_obs_scm': True
         },
         'kanku': {
             'changesgenerate': False,
             'clone_prefix': '_obs_',
             'filename': 'kanku',
             'outdir': self.cli.outdir,
             'revision': None,
             'scm': 'git',
             'snapcraft': True,
             'url': '[email protected]:M0ses/kanku',
             'use_obs_scm': True
         }
     }
     self._cd_fixtures_dir()
     tasks = TarSCM.Tasks(self.cli)
     tasks.generate_list()
     # test values in the objects instead of objects
     for got in tasks.task_list:
         got_f = got.__dict__['filename']
         for key in expected[got_f].keys():
             self.assertEqual(got.__dict__[key], expected[got_f][key])
     self._restore_cwd()
 def test_get_version(self):
     scm              = FakeSCM('0.0.1')
     tasks            = TarSCM.Tasks(self.cli)
     tasks.scm_object = scm
     ver              = tasks.get_version()
     self.assertEqual(ver, '0.0.1')
     self.cli.versionprefix = "r"
     ver              = tasks.get_version()
     self.assertEqual(ver, 'r.0.0.1')
 def test_get_version_with_versionrw(self):
     '''Test for get_version with versionrewrite'''
     self.cli.versionrewrite_pattern = r'v(\d[\d\.]*)'
     self.cli.versionrewrite_replacement = '\\1-stable'
     scm     = FakeSCM('v0.0.1')
     tasks   = TarSCM.Tasks(self.cli)
     tasks.scm_object = scm
     ver     = tasks.get_version()
     self.assertEqual(ver, '0.0.1-stable')
 def test_generate_task_list_single_task(self):
     expected = {'scm': 'bzr', 'clone_prefix': '_obs_', 'snapcraft': True,
             'revision': None, 'url': 'lp:~mterry/libpipeline/printf',
             'filename': 'libpipeline', 'use_obs_scm': True,
             'jailed': 0, 'outdir': self.cli.outdir,'changesgenerate': False}
     self._cd_fixtures_dir()
     tasks           = TarSCM.tasks()
     tasks.generate_list(self.cli)
     self._restore_cwd()
     for k in expected.keys():
         self.assertEqual(tasks.task_list[0].__dict__[k],expected[k])
     self.assertEqual(len(tasks.task_list),1)
    def test_get_version(self):
        class FakeSCM():
            def detect_version(self, args):
                return '0.0.1'

        scm     = FakeSCM()
        tasks   = TarSCM.tasks()
        v       = tasks.get_version(scm, self.cli)
        self.assertEqual(v,'0.0.1')
        self.cli.versionprefix = "r"
        v       = tasks.get_version(scm, self.cli)
        self.assertEqual(v,'r.0.0.1')
 def test_cleanup(self):
     tasks           = TarSCM.tasks()
     if not os.path.exists(self.tmp_dir):
         os.mkdir(self.tmp_dir)
     if not os.path.exists(os.path.join(self.tmp_dir,self.__class__.__name__)):
         os.mkdir(os.path.join(self.tmp_dir,self.__class__.__name__))
     os.mkdir(os.path.join(self.tmp_dir,self.__class__.__name__,'test1'))
     tasks.cleanup_dirs.append(os.path.join(self.tmp_dir,self.__class__.__name__,'test1'))
     tasks.cleanup_dirs.append(os.path.join(self.tmp_dir,self.__class__.__name__,'does not exits'))
     tasks.cleanup_dirs.append(os.path.join(self.tmp_dir,self.__class__.__name__))
     tasks.cleanup()
     self.assertEqual(os.path.exists(os.path.join(self.tmp_dir,self.__class__.__name__)),False)
 def test_generate_tl_single_task(self):
     expected = {
         'scm': 'bzr', 'clone_prefix': '_obs_', 'snapcraft': True,
         'revision': None, 'url': 'lp:~mterry/libpipeline/printf',
         'filename': 'libpipeline', 'use_obs_scm': True,
         'outdir': self.cli.outdir, 'changesgenerate': False}
     self._cd_fixtures_dir()
     tasks = TarSCM.Tasks(self.cli)
     tasks.generate_list()
     self._restore_cwd()
     for k in expected:  # pylint: disable=C0206
         self.assertEqual(tasks.task_list[0].__dict__[k], expected[k])
     self.assertEqual(len(tasks.task_list), 1)
 def test_cleanup(self):
     tasks  = TarSCM.Tasks(self.cli)
     cln    = self.__class__.__name__
     cn_dir = os.path.join(self.tmp_dir, cln)
     if not os.path.exists(self.tmp_dir):
         os.mkdir(self.tmp_dir)
     if not os.path.exists(cn_dir):
         os.mkdir(cn_dir)
     os.mkdir(os.path.join(cn_dir, 'test1'))
     tasks.cleanup_dirs.append(os.path.join(cn_dir, 'test1'))
     tasks.cleanup_dirs.append(os.path.join(cn_dir, 'does not exits'))
     tasks.cleanup_dirs.append(cn_dir)
     tasks.cleanup()
     self.assertEqual(os.path.exists(cn_dir), False)
Example #11
0
    def test_get_version_with_versionrw(self):
        '''Test for get_version with versionrewrite'''
        class FakeSCM():
            # pylint: disable=unused-argument,no-self-use,no-init,
            # pylint: disable=too-few-public-methods
            def detect_version(self, args):
                return 'v0.0.1'

        self.cli.versionrewrite_pattern = r'v(\d[\d\.]*)'
        self.cli.versionrewrite_replacement = '\\1-stable'
        scm = FakeSCM()
        tasks = TarSCM.tasks()
        ver = tasks.get_version(scm, self.cli)
        self.assertEqual(ver, '0.0.1-stable')
Example #12
0
    def test_get_version(self):
        class FakeSCM():
            # pylint: disable=unused-argument,no-self-use,no-init,
            # pylint: disable=too-few-public-methods
            def detect_version(self, args):
                return '0.0.1'

        scm = FakeSCM()
        tasks = TarSCM.tasks()
        ver = tasks.get_version(scm, self.cli)
        self.assertEqual(ver, '0.0.1')
        self.cli.versionprefix = "r"
        ver = tasks.get_version(scm, self.cli)
        self.assertEqual(ver, 'r.0.0.1')
    def test_calc_dir_to_clone_to(self):
        scm = 'git'
        outdir = '/out/'

        clone_dirs = [
            '/local/repo.git',
            '/local/repo/.git',
            '/local/repo/.git/',
            'http://remote/repo.git;param?query#fragment',
            'http://remote/repo/.git;param?query#fragment',
        ]

        for cd in clone_dirs:
            scm = TarSCM.git(url=cd)
            clone_dir = scm._calc_dir_to_clone_to("", outdir)
            self.assertEqual(clone_dir, os.path.join(outdir, 'repo'))
    def test_calc_dir_to_clone_to(self):
        scm = 'git'
        outdir = '/out/'


        clone_dirs = [
            '/local/repo.git',
            '/local/repo/.git',
            '/local/repo/.git/',
            'http://remote/repo.git;param?query#fragment',
            'http://remote/repo/.git;param?query#fragment',
        ]

        for cd in clone_dirs:
            scm = TarSCM.git(url=cd)
            clone_dir = scm._calc_dir_to_clone_to("", outdir)
            self.assertEqual(clone_dir, os.path.join(outdir, 'repo'))
 def test_generate_tl_st_appimage(self):
     '''Test generates task list with single task from appimage.yml'''
     self.cli.snapcraft = False
     self.cli.appimage = True
     expected = {
         'scm': 'git', 'appimage': True,
         'revision': None,
         'url': 'https://github.com/probonopd/QtQuickApp.git',
         'use_obs_scm': True,
         'outdir': self.cli.outdir,
         'changesgenerate': False
     }
     self._cd_fixtures_dir()
     tasks = TarSCM.Tasks(self.cli)
     tasks.generate_list()
     self._restore_cwd()
     for k in expected:  # pylint: disable=C0206
         self.assertEqual(tasks.task_list[0].__dict__[k], expected[k])
     self.assertEqual(len(tasks.task_list), 1)
 def test_generate_task_list_multi_tasks(self):
     expected        = {
         'libpipeline' : {
             'changesgenerate': False,
             'clone_prefix': '_obs_',
             'filename': 'libpipeline',
             'jailed': 0,
             'outdir': self.cli.outdir,
             'revision': None,
             'scm': 'bzr',
             'snapcraft': True,
             'url': 'lp:~mterry/libpipeline/printf',
             'use_obs_scm': True
         },
         'kanku' : {
             'changesgenerate': False,
             'clone_prefix': '_obs_',
             'filename': 'kanku',
             'jailed': 0,
             'outdir': self.cli.outdir,
             'revision': None,
             'scm': 'git',
             'snapcraft': True,
             'url': '[email protected]:M0ses/kanku',
             'use_obs_scm': True
         },
     }
     self._cd_fixtures_dir()
     tasks           = TarSCM.tasks()
     tasks.generate_list(self.cli)
     # test values in the objects instead of objects
     for got in tasks.task_list:
         gf = got.__dict__['filename']
         for k in expected[gf].keys():
             self.assertEqual(got.__dict__[k],expected[gf][k])
     self._restore_cwd()
 def test_appimage_empty_build_git(self):
     self.cli.snapcraft = False
     self.cli.appimage = True
     self._cd_fixtures_dir()
     tasks = TarSCM.Tasks(self.cli)
     tasks.generate_list()
 def _prepare_cli(self):
     self.cli = TarSCM.Cli()
     if not os.path.exists(self.outdir):
         os.makedirs(self.outdir)
     self.cli.parse_args(['--outdir', self.outdir, '--scm', 'git'])
     self.cli.snapcraft  = True
 def test_process_list(self):
     self.cli.snapcraft = False
     tasks = TarSCM.Tasks(self.cli)
     tasks.process_single_task = MagicMock(name='process_single_task')
     tasks.generate_list()
     tasks.process_list()
 def test__git_log_cmd_without_args(self, safe_run_mock):
     scm = TarSCM.git(url=None)
     new_cmd = scm._log_cmd([], None, '')
     safe_run_mock.assert_called_once_with(['git', 'log'], cwd=None)
 def test__git_log_cmd_with_subdir(self, safe_run_mock):
     scm = TarSCM.git(url=None)
     new_cmd = scm._log_cmd(['-n1'], None, 'subdir')
     safe_run_mock.assert_called_once_with(['git', 'log', '-n1',
                                            '--', 'subdir'], cwd=None)
 def test_process_list(self):
     tasks   = TarSCM.tasks()
     self.cli.snapcraft = False
     tasks._process_single_task = MagicMock(name='_process_single_task')
     tasks.generate_list(self.cli)
     tasks.process_list()
 def _prepare_cli(self):
     self.cli = TarSCM.cli()
     if not os.path.exists(self.outdir):
         os.makedirs(self.outdir)
     self.cli.parse_args(['--outdir',self.outdir,'--scm','git'])
     self.cli.snapcraft  = True
 def test__git_log_cmd_with_subdir(self, safe_run_mock):
     scm = TarSCM.git(url=None)
     new_cmd = scm._log_cmd(['-n1'], None, 'subdir')
     safe_run_mock.assert_called_once_with(
         ['git', 'log', '-n1', '--', 'subdir'], cwd=None)
 def test__git_log_cmd_without_args(self, safe_run_mock):
     scm = TarSCM.git(url=None)
     new_cmd = scm._log_cmd([], None, '')
     safe_run_mock.assert_called_once_with(['git', 'log'], cwd=None)