コード例 #1
0
 def test_1_add_project(self):
     cmd = project.InitCmd(config=self._config)
     pname = test_vfid
     res = collect_cmd(cmd.run(pname))
     self.assertIsInstance(res, project.Project)
     self.assertEqual(res.pname, pname)
     self.assertEqual(res.state, 'empty')
コード例 #2
0
 def test_backup_no_dir(self):
     cfg = self._config
     pump_cmd(project.InitCmd(config=cfg).run(proj1))
     cmd = project.BackupCmd(config=cfg)
     with tempfile.TemporaryDirectory() as td:
         with self.assertRaisesRegex(
                 cmdlets.CmdException,
                 r"Folder '.+__BAD_FOLDER' to store archive does not exist!"
         ):
             pump_cmd(cmd.run(osp.join(td, '__BAD_FOLDER', 'foo')))
コード例 #3
0
    def test_init_with_files(self):
        cmd = project.InitCmd(config=self._config,
                              inp=[test_inp_fpath],
                              out=[test_out_fpath])
        pump_cmd(cmd.run())

        pdb, _ = self.get_cwp()

        self.assertEqual(len(list(pdb.repo.head.commit.tree.traverse())), 5,
                         list(pdb.repo.head.commit.tree.traverse()))
コード例 #4
0
    def test_3a_add_same_project__fail(self):
        cfg = self._config
        cmd = project.InitCmd(config=cfg)
        with self.assertRaisesRegex(cmdlets.CmdException,
                                    r"Project '%s' already exists!" % proj1):
            pump_cmd(cmd.run(proj1))

        cmd = project.LsCmd(config=cfg)
        res = list(cmd.run('.'))
        self.assertEqual(res, ['* %s: empty' % proj1])
コード例 #5
0
 def test_backup_folder_only(self):
     cfg = self._config
     pump_cmd(project.InitCmd(config=cfg).run(proj2))
     cmd = project.BackupCmd(config=cfg)
     with tempfile.TemporaryDirectory() as td:
         archive_fpath = td + '\\'
         res = collect_cmd(cmd.run(archive_fpath))
         self.assertIn(archive_fpath, res)
         self.assertIn('co2mpas', res)
         self.assertTrue(osp.isfile(res),
                         (res, os.listdir(osp.split(res)[0])))
コード例 #6
0
 def test_backup_cwd(self):
     cfg = self._config
     pump_cmd(project.InitCmd(config=cfg).run(proj1))
     cmd = project.BackupCmd(config=cfg)
     with tempfile.TemporaryDirectory() as td:
         with chdir(td):
             res = collect_cmd(cmd.run())
             self.assertIn(td, res)
             self.assertIn(os.getcwd(), res)
             self.assertTrue(osp.isfile(res),
                             (res, os.listdir(osp.split(res)[0])))
コード例 #7
0
 def test_backup_fullpath(self):
     cfg = self._config
     pump_cmd(project.InitCmd(config=cfg).run(proj1))
     cmd = project.BackupCmd(config=cfg)
     with tempfile.TemporaryDirectory() as td:
         archive_fpath = osp.join(td, 'foo')
         res = collect_cmd(cmd.run(archive_fpath))
         self.assertIn(td, res)
         self.assertIn('foo.txz', res)
         self.assertNotIn('co2mpas', res)
         self.assertTrue(osp.isfile(res),
                         (res, os.listdir(osp.split(res)[0])))
コード例 #8
0
    def test_init_without_files(self):
        cmd = project.InitCmd(config=self._config)
        pump_cmd(cmd.run(test_vfid))

        pdb, p = self.get_cwp()

        assert len(list(pdb.repo.head.commit.tree.traverse())) == 1

        p.do_addfiles(
            pfiles=PFiles(inp=[test_inp_fpath], out=[test_out_fpath]))
        self.assertEqual(len(list(pdb.repo.head.commit.tree.traverse())), 5,
                         list(pdb.repo.head.commit.tree.traverse()))
コード例 #9
0
    def test_4a_add_another_project(self):
        cfg = self._config
        pname = proj2
        cmd = project.InitCmd(config=cfg)
        res = collect_cmd(cmd.run(pname))
        self.assertIsInstance(res, project.Project)
        self.assertEqual(res.pname, pname)
        self.assertEqual(res.state, 'empty')

        cmd = project.LsCmd(config=cfg)
        res = collect_cmd(cmd.run('.'))
        self.assertEqual(res, '* %s: empty' % pname)
コード例 #10
0
    def test_2a_add_project(self):
        cfg = self._config
        cmd = project.InitCmd(config=cfg)
        pname = proj1
        res = collect_cmd(cmd.run(pname))
        self.assertIsInstance(res, project.Project)
        self.assertEqual(res.pname, pname)
        self.assertEqual(res.state, 'empty')

        cmd = project.LsCmd(config=cfg)
        res = collect_cmd(cmd.run())
        self.assertEqual(str(res), '* %s: empty' % proj1)
コード例 #11
0
    def test_export_import(self):
        import git
        import zipfile

        def suffix_exist(sufix, words):
            return any(w.endswith(sufix) for w in words)

        cfg = self._config
        pump_cmd(
            project.InitCmd(
                config=cfg,
                inp=[test_inp_fpath],
                out=[test_out_fpath],
            ).run())
        r = git.Repo(cfg.ProjectsDB.repo_path)
        r.create_tag('new_tag', message="just to be real tag")

        with tempfile.TemporaryDirectory() as td:
            archive_fpath = osp.join(td, 'proj.zip')

            pump_cmd(
                project.ExportCmd(config=cfg,
                                  out=archive_fpath,
                                  erase_afterwards=True).run())
            self.assertIsNone(collect_cmd(project.LsCmd(config=cfg).run()))

            with zipfile.ZipFile(archive_fpath) as zfile:
                file_list = [f.filename for f in zfile.infolist()]

            assert suffix_exist('refs/heads/projects/%s' % test_vfid,
                                file_list)
            assert suffix_exist('refs/tags/new_tag', file_list)
            assert not suffix_exist('refs/remotes/projects', file_list)

            pump_cmd(project.ImportCmd(config=cfg).run(archive_fpath))
            self.assertIn(test_vfid,
                          collect_cmd(project.LsCmd(config=cfg).run()))