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)
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])
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)))
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)
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)
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()))
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)
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)
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)