Beispiel #1
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')))
Beispiel #2
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()))
Beispiel #3
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])
Beispiel #4
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])))
Beispiel #5
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])))
Beispiel #6
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])))
Beispiel #7
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()))
Beispiel #8
0
    def test_1a_empty_list(self):
        cfg = self._config
        exp_log_msg = r"No current-project exists yet!"

        cmd = project.LsCmd(config=cfg)
        self.assertEqual(collect_cmd(cmd.run()), None)

        cmd = project.ReportCmd(config=cfg)
        with self.assertRaisesRegex(cmdlets.CmdException, exp_log_msg):
            pump_cmd(cmd.run())
        self.assertIsNone(cmd.projects_db._current_project)

        pdb = project.ProjectsDB.instance(config=cfg)  # @UndefinedVariable
        pdb.update_config(cfg)

        pump_cmd(pdb.proj_list(verbose=1))
        self.assertIsNone(pdb._current_project)

        pump_cmd(pdb.proj_list(verbose=2))
        self.assertIsNone(pdb._current_project)
Beispiel #9
0
    def test_tparse_checks(self):
        cfg = self._config
        archive_fpath = osp.join(mydir, 'project-IP-10-AAA-2017-0000.zip')
        stamp_old_fpath = osp.join(mydir, 'stamp1-IP-10-AAA-2017-0000.txt')
        stamp_new_fpath = osp.join(mydir, 'stamp2-IP-10-AAA-2017-0000.txt')
        test_vfid = 'IP-10-AAA-2017-0000'

        pump_cmd(project.ImportCmd(config=cfg).run(archive_fpath))
        self.assertIn(test_vfid,
                      collect_cmd(project.LsCmd(config=cfg).run(test_vfid)))
        with self.assertRaisesRegex(
                cmdlets.CmdException, r"Stamp's tag"
                "\('dices/IP-10-AAA-2017-0000/0: ad5f4eb331ba5067a2e82422a1ffafdec8ea09d4'\) "
                "is different from last tag on current project"
                "\('dices/IP-10-AAA-2017-0000/0: ec86fd6986bc9ec9656a92a3c66e70eb90394461'\)"
        ):
            pump_cmd(project.TparseCmd(config=cfg).run(stamp_old_fpath))

        pump_cmd(project.TparseCmd(config=cfg).run(stamp_new_fpath))
        self.assertIn('sample',
                      collect_cmd(project.LsCmd(config=cfg).run(test_vfid)))
Beispiel #10
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()))
Beispiel #11
0
 def test_0_show_paths(self):
     from co2dice import cfgcmd
     cmd = cfgcmd.PathsCmd(config=self._config)
     pump_cmd(cmd.run())