Beispiel #1
0
    def test_4b_list_projects(self):
        cfg = self._config
        cmd = project.LsCmd(config=cfg)
        res = collect_cmd(cmd.run('.'))
        self.assertEqual(res, '* %s: empty' % proj2)

        cmd = project.LsCmd(config=cfg)
        res = collect_cmd(cmd.run())
        self.assertSequenceEqual(
            res, ['* %s: empty' % proj2,
                  '  %s: empty' % proj1])

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

        res = collect_cmd(pdb.proj_list(verbose=1))
        for ires in res:
            self.assertIsInstance(ires, dict)
            self.assertTrue(proj1 in ires or proj2 in ires, ires)
            self.assertEqual(len(next(iter(ires.values()))), 13, ires)

        res = collect_cmd(pdb.proj_list(verbose=2))
        for ires in res:
            self.assertIsInstance(ires, dict)
            self.assertTrue(proj1 in ires or proj2 in ires, ires)
            self.assertEqual(len(next(iter(ires.values()))), 17, ires)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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')
Beispiel #5
0
    def test_2c_default_infos(self):
        cfg = self._config
        cmd = project.StatusCmd(config=cfg)
        res = collect_cmd(cmd.run())
        self.assertIn(proj1, res)

        pdb = project.ProjectsDB.instance(config=cfg)  # @UndefinedVariable
        pdb.update_config(cfg)
        self._check_infos_shapes(pdb)
Beispiel #6
0
    def test_2b_list(self):
        cfg = self._config
        cmd = project.LsCmd(config=cfg)
        res = collect_cmd(cmd.run())
        self.assertEqual(res, '* %s: empty' % proj1)

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

        res = collect_cmd(pdb.proj_list(verbose=1))
        self.assertIsInstance(res, dict)
        self.assertIn(proj1, res)
        self.assertEqual(len(next(iter(res.values()))), 13, res)

        res = collect_cmd(pdb.proj_list(verbose=2))
        self.assertIsInstance(res, dict)
        self.assertIn(proj1, res)
        self.assertEqual(len(next(iter(res.values()))), 17, res)
Beispiel #7
0
    def test_1b_empty_infos(self):
        cfg = self._config
        cmd = project.StatusCmd(config=cfg)
        res = collect_cmd(cmd.run())
        self.assertIsNotNone(res)
        self.assertIsNone(cmd.projects_db._current_project)

        pdb = project.ProjectsDB.instance(config=cfg)  # @UndefinedVariable
        pdb.update_config(cfg)
        self._check_infos_shapes(pdb)
        self.assertIsNone(pdb._current_project)
Beispiel #8
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 #9
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 #10
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 #11
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 #12
0
    def test_5_open_other(self):
        cfg = self._config
        pname = proj1

        cmd = project.OpenCmd(config=self._config)
        res = collect_cmd(cmd.run(pname))
        self.assertIsInstance(res, project.Project)
        self.assertEqual(res.pname, pname)
        self.assertEqual(res.state, 'empty')

        pdb = project.ProjectsDB.instance(config=cfg)  # @UndefinedVariable
        pdb.update_config(cfg)
        res = collect_cmd(pdb.proj_list(pname))
        self.assertEqual(res, pname)

        cmd = project.LsCmd(config=cfg)
        res = collect_cmd(cmd.run('.'))
        self.assertEqual(str(res), '* %s: empty' % pname)

        pdb = project.ProjectsDB.instance(config=cfg)  # @UndefinedVariable
        pdb.update_config(cfg)
        self._check_infos_shapes(pdb)
Beispiel #13
0
    def test_2a_import_io(self):
        cfg = self._config
        pdb = project.ProjectsDB.instance(config=cfg)  # @UndefinedVariable
        pdb.update_config(cfg)
        p = pdb.current_project()

        cmd = project.AppendCmd(config=cfg,
                                inp=[test_inp_fpath],
                                out=[test_out_fpath])
        res = collect_cmd(cmd.run())
        self.assertTrue(res)

        p2 = pdb.current_project()
        self.assertIs(p, p2)
Beispiel #14
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 #15
0
    def test_parse_out(self, case):
        fname, keys_indx = case
        cmd = tstamp.ParseCmd(config=self.cfg)
        res = collect_cmd(cmd.run(osp.join(mydir, fname)))

        substrings = [
            ['model', 'project', 'project_source'],
            [
                'tag', 'issuer', 'issue_date', 'dice_date', 'hexnum',
                'percent', 'decision'
            ],
        ]
        for k in substrings[keys_indx]:
            tail = res[-500:]
            self.assertIn('%s:' % k, tail, (k, tail))
Beispiel #16
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 #17
0
    def test_paths_valid_yaml(self):
        import yaml
        res = collect_cmd(cfgcmd.PathsCmd().run())
        ystr = '\n'.join(res)

        yaml.load(ystr)