Exemplo n.º 1
0
def test_dicer_B_fail_DIFF_files(dicer, iofiles, iofiles_mov, iofiles_diff,
                                 pdb, tmpdir):
    tmpdir.chdir()
    reset_git(pdb, '%s~~' % _decided_sha1)

    ifile, ofile = iofiles
    okfiles = PFiles([ifile], [ofile], [other])

    ofileRen = tmpdir.mkdir('ren') / 'foo.xlsx'
    ofile.copy(ofileRen)

    ifile, ofile = iofiles_mov

    ## Different content `inp`
    pfiles = PFiles([iofiles_diff[0]], [ofile])
    with pytest.raises(CmdException,
                       match=r"^Project [-\w]+ files mismatched"):
        dicer.do_dice_in_one_step(pfiles)

    ## Check if diff-check had leftovers.
    dicer.do_dice_in_one_step(okfiles)
    reset_git(pdb, '%s~~' % _decided_sha1)

    ## Different name 'out'
    pfiles = PFiles([ifile], [ofileRen])
    with pytest.raises(CmdException,
                       match=r"^Project [-\w]+ files mismatched"):
        dicer.do_dice_in_one_step(pfiles)

    ## Check if diff-check had leftovers.
    dicer.do_dice_in_one_step(okfiles)
    reset_git(pdb, '%s~' % _decided_sha1)

    ## Different content `other`
    empty_init = (tmpdir / '__init__.py').ensure()
    pfiles = PFiles([ifile], [ofile], [empty_init])
    with pytest.raises(CmdException,
                       match=r"^Project [-\w]+ files mismatched"):
        dicer.do_dice_in_one_step(pfiles)

    ## Less 'other' files
    pfiles = PFiles([ifile], [ofile])
    with pytest.raises(CmdException,
                       match=r"^Project [-\w]+ files mismatched"):
        dicer.do_dice_in_one_step(pfiles)

    ## Check if diff-check had leftovers.
    dicer.do_dice_in_one_step(okfiles)
    reset_git(pdb, '%s~' % _decided_sha1)
Exemplo n.º 2
0
def test_dicer_B_ok_TAGGED(dicer, iofiles_mov, pdb):
    reset_git(pdb, '%s~' % _decided_sha1)
    ifile, ofile = iofiles_mov
    pfiles = PFiles([ifile], [ofile], [other])
    dicer.do_dice_in_one_step(pfiles)
    assert pdb.current_project().state in ('sample', 'nosample')
    assert head_sha1(pdb) != _decided_sha1
Exemplo n.º 3
0
def test_dicer_A_new(dicer, pdb, iofiles):
    global _decided_sha1

    ifile, ofile = iofiles
    pfiles = PFiles([ifile], [ofile], [other])
    dicer.do_dice_in_one_step(pfiles)
    assert pdb.current_project().state in ('sample', 'nosample')
    _decided_sha1 = head_sha1(pdb)
Exemplo n.º 4
0
    def test_8_add_nedc_files(self):
        cfg = self._config
        pdb = project.ProjectsDB.instance(config=cfg)  # @UndefinedVariable
        pdb.update_config(cfg)
        p = pdb.current_project()
        p.update_config(cfg)

        pfiles = PFiles(other=[__file__])
        res = p.do_addfiles(pfiles=pfiles)
        self.assertTrue(res)
        self.assertEqual(p.state, 'nedc')

        p2 = pdb.current_project()
        self.assertIs(p, p2)

        pfiles = PFiles(other=[osp.join(osp.dirname(__file__), '__init__.py')])
        res = p.do_addfiles(pfiles=pfiles)
        self.assertTrue(res)
        self.assertEqual(p.state, 'nedc')
Exemplo n.º 5
0
def test_dicer_B_ok_WLTPIOF_relpaths(dicer, iofiles_mov, pdb):
    reset_git(pdb, '%s~~' % _decided_sha1)
    ifile, ofile = iofiles_mov

    ## Relative paths:
    #
    ifile.dirpath().chdir()
    pfiles = PFiles([ifile.basename], [local('../out') / ofile.basename], [other])
    dicer.do_dice_in_one_step(pfiles)
    assert pdb.current_project().state in ('sample', 'nosample')
    assert head_sha1(pdb) != _decided_sha1
Exemplo n.º 6
0
def test_dicer_B_fail_DECIDED(dicer, iofiles_mov, pdb):
    ifile, ofile = iofiles_mov
    pfiles = PFiles([ifile], [ofile], [other])

    ## State: 'decided' from A above

    with pytest.raises(
            CmdException,
            match="to forbidden state-transition from '(no)?sample'!"):
        dicer.do_dice_in_one_step(pfiles)
    assert pdb.current_project().state in ('sample', 'nosample')
    assert head_sha1(pdb) == _decided_sha1
Exemplo n.º 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()))
Exemplo n.º 8
0
def test_pfiles_cli_opts(pfile: PFiles, opts):
    assert pfile.build_cmd_line(abs_path=False) == opts
Exemplo n.º 9
0
#
# Copyright 2015-2018 European Commission (JRC);
# Licensed under the EUPL (the 'Licence');
# You may not use this work except in compliance with the Licence.
# You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl

from co2dice.base import PFiles
import pytest

_ = []


@pytest.mark.parametrize(
    'pfile, opts',
    [
        (PFiles(_), []),

        ## Missing & quoting
        (PFiles(['abc']), ['--inp', 'abc']),
        (PFiles(['ab\'c']), ['--inp', '"ab\'c"']),
        (PFiles(_, _, ['b&g']), ['"b&g"']),
        ## Mumtiple = missing
        (PFiles(_, ['a', 'b']), ['--out', 'a', '--out', 'b']),

        ## Other
        (PFiles(_, ['a', 'b g']), ['--out', 'a', '--out', '"b g"']),

        ## Multiple IO, balanced
        (PFiles(['a'], ['b g']), ['--inp', 'a', '--out', '"b g"']),
        (PFiles(['a', 'b'], ['aa', 'bb']),
         ['--inp', 'a', '--out', 'aa', '--inp', 'b', '--out', 'bb']),