示例#1
0
def test(shell):
    from tempfile import mkdtemp
    from shutil import rmtree
    from os import makedirs, getcwd, chdir
    from os.path import exists, join
    from pylada.jobfolder import JobFolder
    from pylada import interactive
    from dummy import functional

    root = JobFolder()
    for type, trial, size in [('this', 0, 10), ('this', 1, 15),
                              ('that', 2, 20), ('that', 1, 20)]:
        job = root / type / str(trial)
        job.functional = functional
        job.params['indiv'] = size
        if type == 'that':
            job.params['value'] = True

    origdir = getcwd()
    directory = mkdtemp()
    if exists(directory) and directory == '/tmp/test':
        rmtree(directory)
    if not exists(directory):
        makedirs(directory)
    try:
        shell.user_ns['jobfolder'] = root
        shell.magic("explore jobfolder")
        shell.magic("savefolders {0}/dict".format(directory))
        for name, job in root.items():
            result = job.compute(outdir=join(directory, name))
            assert result.success
            assert {
                'this/0': 10,
                'this/1': 15,
                'that/1': 20,
                'that/2': 20,
                'this/0/another': 25
            }[name] == result.indiv

        shell.magic("explore {0}/dict".format(directory))
        shell.magic("goto this/0")
        assert getcwd() == '{0}/this/0'.format(directory)
        assert interactive.jobfolder.name == '/this/0/'
        shell.magic("goto ../1")
        assert getcwd() == '{0}/this/1'.format(directory)
        assert interactive.jobfolder.name == '/this/1/'
        shell.magic("goto /that")
        assert getcwd() == '{0}/that'.format(directory)
        assert interactive.jobfolder.name == '/that/'
        shell.magic("goto 2")
        assert getcwd() == '{0}/that/2'.format(directory)
        assert interactive.jobfolder.name == '/that/2/'
        shell.magic("goto /")
        shell.magic("goto next")
        assert getcwd() == '{0}/that/1'.format(directory)
        assert interactive.jobfolder.name == '/that/1/'
        shell.magic("goto next")
        assert getcwd() == '{0}/that/2'.format(directory)
        assert interactive.jobfolder.name == '/that/2/'
        shell.magic("goto previous")
        assert getcwd() == '{0}/that/1'.format(directory)
        assert interactive.jobfolder.name == '/that/1/'
        shell.magic("goto next")
        assert getcwd() == '{0}/this/0'.format(directory)
        assert interactive.jobfolder.name == '/this/0/'
        shell.magic("goto next")
        assert getcwd() == '{0}/this/1'.format(directory)
        assert interactive.jobfolder.name == '/this/1/'
        shell.magic("goto next")  # no further jobs
        assert getcwd() == '{0}/this/1'.format(directory)
        assert interactive.jobfolder.name == '/this/1/'
        shell.magic("goto /")  # go back to root to avoid errors

    finally:
        chdir(origdir)
        try:
            if directory != '/tmp/test':
                rmtree(directory)
        except:
            pass
示例#2
0
def test(shell, tmpdir, functional):
    from os.path import join
    from os import getcwd
    from pylada.jobfolder import JobFolder
    from pylada import interactive

    root = JobFolder()
    for type, trial, size in [
        ("this", 0, 10),
        ("this", 1, 15),
        ("that", 2, 20),
        ("that", 1, 20),
    ]:
        job = root / type / str(trial)
        job.functional = functional
        job.params["indiv"] = size
        if type == "that":
            job.params["value"] = True

    shell.user_ns["jobfolder"] = root
    shell.magic("explore jobfolder")
    shell.magic("savefolders {0}/dict".format(tmpdir))
    for name, job in root.items():
        result = job.compute(outdir=str(tmpdir.join(name)))
        assert result.success
        assert {
            "this/0": 10,
            "this/1": 15,
            "that/1": 20,
            "that/2": 20,
            "this/0/another": 25,
        }[name] == result.indiv

    shell.magic("explore {0}/dict".format(tmpdir))
    shell.magic("goto this/0")
    assert getcwd() == "{0}/this/0".format(tmpdir)
    assert interactive.jobfolder.name == "/this/0/"
    shell.magic("goto ../1")
    assert getcwd() == "{0}/this/1".format(tmpdir)
    assert interactive.jobfolder.name == "/this/1/"
    shell.magic("goto /that")
    assert getcwd() == "{0}/that".format(tmpdir)
    assert interactive.jobfolder.name == "/that/"
    shell.magic("goto 2")
    assert getcwd() == "{0}/that/2".format(tmpdir)
    assert interactive.jobfolder.name == "/that/2/"
    shell.magic("goto /")
    shell.magic("goto next")
    assert getcwd() == "{0}/that/1".format(tmpdir)
    assert interactive.jobfolder.name == "/that/1/"
    shell.magic("goto next")
    assert getcwd() == "{0}/that/2".format(tmpdir)
    assert interactive.jobfolder.name == "/that/2/"
    shell.magic("goto previous")
    assert getcwd() == "{0}/that/1".format(tmpdir)
    assert interactive.jobfolder.name == "/that/1/"
    shell.magic("goto next")
    assert getcwd() == "{0}/this/0".format(tmpdir)
    assert interactive.jobfolder.name == "/this/0/"
    shell.magic("goto next")
    assert getcwd() == "{0}/this/1".format(tmpdir)
    assert interactive.jobfolder.name == "/this/1/"
    shell.magic("goto next")  # no further jobs
    assert getcwd() == "{0}/this/1".format(tmpdir)
    assert interactive.jobfolder.name == "/this/1/"
    shell.magic("goto /")  # go back to root to avoid errors
示例#3
0
def test(shell):
    from tempfile import mkdtemp
    from shutil import rmtree
    from os import makedirs, getcwd, chdir
    from os.path import exists, join
    from pylada.jobfolder import JobFolder
    from pylada import interactive
    from dummy import functional

    root = JobFolder()
    for type, trial, size in [('this', 0, 10), ('this', 1, 15), ('that', 2, 20), ('that', 1, 20)]:
        job = root / type / str(trial)
        job.functional = functional
        job.params['indiv'] = size
        if type == 'that':
            job.params['value'] = True

    origdir = getcwd()
    directory = mkdtemp()
    if exists(directory) and directory == '/tmp/test':
        rmtree(directory)
    if not exists(directory):
        makedirs(directory)
    try:
        shell.user_ns['jobfolder'] = root
        shell.magic("explore jobfolder")
        shell.magic("savefolders {0}/dict".format(directory))
        for name, job in root.items():
            result = job.compute(outdir=join(directory, name))
            assert result.success
            assert {'this/0': 10, 'this/1': 15, 'that/1': 20,
                    'that/2': 20, 'this/0/another': 25}[name] == result.indiv

        shell.magic("explore {0}/dict".format(directory))
        shell.magic("goto this/0")
        assert getcwd() == '{0}/this/0'.format(directory)
        assert interactive.jobfolder.name == '/this/0/'
        shell.magic("goto ../1")
        assert getcwd() == '{0}/this/1'.format(directory)
        assert interactive.jobfolder.name == '/this/1/'
        shell.magic("goto /that")
        assert getcwd() == '{0}/that'.format(directory)
        assert interactive.jobfolder.name == '/that/'
        shell.magic("goto 2")
        assert getcwd() == '{0}/that/2'.format(directory)
        assert interactive.jobfolder.name == '/that/2/'
        shell.magic("goto /")
        shell.magic("goto next")
        assert getcwd() == '{0}/that/1'.format(directory)
        assert interactive.jobfolder.name == '/that/1/'
        shell.magic("goto next")
        assert getcwd() == '{0}/that/2'.format(directory)
        assert interactive.jobfolder.name == '/that/2/'
        shell.magic("goto previous")
        assert getcwd() == '{0}/that/1'.format(directory)
        assert interactive.jobfolder.name == '/that/1/'
        shell.magic("goto next")
        assert getcwd() == '{0}/this/0'.format(directory)
        assert interactive.jobfolder.name == '/this/0/'
        shell.magic("goto next")
        assert getcwd() == '{0}/this/1'.format(directory)
        assert interactive.jobfolder.name == '/this/1/'
        shell.magic("goto next")  # no further jobs
        assert getcwd() == '{0}/this/1'.format(directory)
        assert interactive.jobfolder.name == '/this/1/'
        shell.magic("goto /")  # go back to root to avoid errors

    finally:
        chdir(origdir)
        try:
            if directory != '/tmp/test':
                rmtree(directory)
        except:
            pass
示例#4
0
def test(shell):
    from tempfile import mkdtemp
    from shutil import rmtree
    from os import makedirs
    from os.path import exists, join
    from pylada.jobfolder import JobFolder
    import pylada
    from dummy import functional

    root = JobFolder()
    for type, trial, size in [('this', 0, 10), ('this', 1, 15),
                              ('that', 2, 20), ('that', 1, 20)]:
        jobfolder = root / type / str(trial)
        jobfolder.functional = functional
        jobfolder.params['indiv'] = size
        if type == 'that':
            jobfolder.params['value'] = True

    directory = mkdtemp()
    if exists(directory) and directory == '/tmp/test':
        rmtree(directory)
    if not exists(directory):
        makedirs(directory)
    try:
        shell.user_ns['jobfolder'] = root
        shell.magic("explore jobfolder")
        jobfolder = pylada.interactive.jobfolder
        assert 'this/0' in jobfolder and 'this/1' in jobfolder and 'that/2' in jobfolder and 'that/1'
        assert '0' in jobfolder['this'] and '1' in jobfolder['this']
        assert '1' in jobfolder['that'] and '2' in jobfolder['that']
        assert 'other' not in jobfolder
        for job in jobfolder.values():
            assert repr(job.functional) == repr(functional)
        assert getattr(jobfolder['this/0'], 'indiv', 0) == 10
        assert getattr(jobfolder['this/1'], 'indiv', 0) == 15
        assert getattr(jobfolder['that/1'], 'indiv', 0) == 20
        assert getattr(jobfolder['that/2'], 'indiv', 0) == 20
        assert not hasattr(jobfolder['this/0'], 'value')
        assert not hasattr(jobfolder['this/1'], 'value')
        assert getattr(jobfolder['that/1'], 'value', False)
        assert getattr(jobfolder['that/2'], 'value', False)
        assert pylada.interactive.jobfolder_path is None
        assert 'jobparams' in shell.user_ns
        assert jobfolder is shell.user_ns['jobparams'].jobfolder

        shell.magic("savefolders {0}/dict".format(directory))
        pylada.interactive.jobfolder = None
        pylada.interactive.jobfolder_path = None
        shell.magic("explore {0}/dict".format(directory))
        jobfolder = pylada.interactive.jobfolder
        assert 'this/0' in jobfolder and 'this/1' in jobfolder and 'that/2' in jobfolder and 'that/1'
        assert '0' in jobfolder['this'] and '1' in jobfolder['this']
        assert '1' in jobfolder['that'] and '2' in jobfolder['that']
        assert 'other' not in jobfolder
        for job in jobfolder.values():
            assert repr(job.functional) == repr(functional)
        assert getattr(jobfolder['this/0'], 'indiv', 0) == 10
        assert getattr(jobfolder['this/1'], 'indiv', 0) == 15
        assert getattr(jobfolder['that/1'], 'indiv', 0) == 20
        assert getattr(jobfolder['that/2'], 'indiv', 0) == 20
        assert not hasattr(jobfolder['this/0'], 'value')
        assert not hasattr(jobfolder['this/1'], 'value')
        assert getattr(jobfolder['that/1'], 'value', False)
        assert getattr(jobfolder['that/2'], 'value', False)
        assert pylada.interactive.jobfolder_path is not None
        assert 'jobparams' in shell.user_ns
        assert jobfolder is shell.user_ns['jobparams'].jobfolder
        assert jobfolder is shell.user_ns['collect'].jobfolder

        for name, job in root.items():
            if name == 'this/1':
                continue
            job.compute(outdir=join(directory, name))

        shell.magic("explore results".format(directory))
        assert {'/this/0/', '/that/1/', '/that/2/'} \
            == set(shell.user_ns['collect'].keys())
        shell.magic("explore errors".format(directory))
        assert len(shell.user_ns['collect']) == 0
        shell.magic("explore all".format(directory))
        shell.magic("explore errors".format(directory))
        assert set(shell.user_ns['collect'].keys()) == {'/this/1/'}

    finally:
        if directory != '/tmp/test':
            rmtree(directory)
        pass
示例#5
0
def test(shell, tmpdir, functional):
    from os.path import join
    from pylada.jobfolder import JobFolder
    import pylada

    with patch("pylada.misc.cmdl_input", return_value="y"):

        root = JobFolder()
        for type, trial, size in [
            ("this", 0, 10),
            ("this", 1, 15),
            ("that", 2, 20),
            ("that", 1, 20),
        ]:
            jobfolder = root / type / str(trial)
            jobfolder.functional = functional
            jobfolder.params["indiv"] = size
            if type == "that":
                jobfolder.params["value"] = True

        shell.user_ns["jobfolder"] = root
        shell.magic("explore jobfolder")
        jobfolder = pylada.interactive.jobfolder
        assert (
            "this/0" in jobfolder
            and "this/1" in jobfolder
            and "that/2" in jobfolder
            and "that/1"
        )
        assert "0" in jobfolder["this"] and "1" in jobfolder["this"]
        assert "1" in jobfolder["that"] and "2" in jobfolder["that"]
        assert "other" not in jobfolder
        for job in jobfolder.values():
            assert repr(job.functional) == repr(functional)
        assert getattr(jobfolder["this/0"], "indiv", 0) == 10
        assert getattr(jobfolder["this/1"], "indiv", 0) == 15
        assert getattr(jobfolder["that/1"], "indiv", 0) == 20
        assert getattr(jobfolder["that/2"], "indiv", 0) == 20
        assert not hasattr(jobfolder["this/0"], "value")
        assert not hasattr(jobfolder["this/1"], "value")
        assert getattr(jobfolder["that/1"], "value", False)
        assert getattr(jobfolder["that/2"], "value", False)
        assert pylada.interactive.jobfolder_path is None
        assert "jobparams" in shell.user_ns
        assert jobfolder is shell.user_ns["jobparams"].jobfolder

        shell.magic("savefolders {0}/dict".format(tmpdir))
        pylada.interactive.jobfolder = None
        pylada.interactive.jobfolder_path = None
        shell.magic("explore {0}/dict".format(tmpdir))
        jobfolder = pylada.interactive.jobfolder
        assert (
            "this/0" in jobfolder
            and "this/1" in jobfolder
            and "that/2" in jobfolder
            and "that/1"
        )
        assert "0" in jobfolder["this"] and "1" in jobfolder["this"]
        assert "1" in jobfolder["that"] and "2" in jobfolder["that"]
        assert "other" not in jobfolder
        for job in jobfolder.values():
            assert repr(job.functional) == repr(functional)
        assert getattr(jobfolder["this/0"], "indiv", 0) == 10
        assert getattr(jobfolder["this/1"], "indiv", 0) == 15
        assert getattr(jobfolder["that/1"], "indiv", 0) == 20
        assert getattr(jobfolder["that/2"], "indiv", 0) == 20
        assert not hasattr(jobfolder["this/0"], "value")
        assert not hasattr(jobfolder["this/1"], "value")
        assert getattr(jobfolder["that/1"], "value", False)
        assert getattr(jobfolder["that/2"], "value", False)
        assert pylada.interactive.jobfolder_path is not None
        assert "jobparams" in shell.user_ns
        assert jobfolder is shell.user_ns["jobparams"].jobfolder
        assert jobfolder is shell.user_ns["collect"].jobfolder

        for name, job in root.items():
            if name == "this/1":
                continue
            job.compute(outdir=str(tmpdir.join(name)))

        shell.magic("explore results".format(tmpdir))
        assert {"/this/0/", "/that/1/", "/that/2/"} == set(
            shell.user_ns["collect"].keys()
        )
        shell.magic("explore errors".format(tmpdir))
        assert len(shell.user_ns["collect"]) == 0
        shell.magic("explore all".format(tmpdir))
        shell.magic("explore errors".format(tmpdir))
        assert set(shell.user_ns["collect"].keys()) == {"/this/1/"}
示例#6
0
def test(shell):
    from tempfile import mkdtemp
    from shutil import rmtree
    from os import makedirs
    from os.path import exists, join
    from pylada.jobfolder import JobFolder
    import pylada
    from dummy import functional

    root = JobFolder()
    for type, trial, size in [('this', 0, 10), ('this', 1, 15), ('that', 2, 20), ('that', 1, 20)]:
        jobfolder = root / type / str(trial)
        jobfolder.functional = functional
        jobfolder.params['indiv'] = size
        if type == 'that':
            jobfolder.params['value'] = True

    directory = mkdtemp()
    if exists(directory) and directory == '/tmp/test':
        rmtree(directory)
    if not exists(directory):
        makedirs(directory)
    try:
        shell.user_ns['jobfolder'] = root
        shell.magic("explore jobfolder")
        jobfolder = pylada.interactive.jobfolder
        assert 'this/0' in jobfolder and 'this/1' in jobfolder and 'that/2' in jobfolder and 'that/1'
        assert '0' in jobfolder['this'] and '1' in jobfolder['this']
        assert '1' in jobfolder['that'] and '2' in jobfolder['that']
        assert 'other' not in jobfolder
        for job in jobfolder.values():
            assert repr(job.functional) == repr(functional)
        assert getattr(jobfolder['this/0'], 'indiv', 0) == 10
        assert getattr(jobfolder['this/1'], 'indiv', 0) == 15
        assert getattr(jobfolder['that/1'], 'indiv', 0) == 20
        assert getattr(jobfolder['that/2'], 'indiv', 0) == 20
        assert not hasattr(jobfolder['this/0'], 'value')
        assert not hasattr(jobfolder['this/1'], 'value')
        assert getattr(jobfolder['that/1'], 'value', False)
        assert getattr(jobfolder['that/2'], 'value', False)
        assert pylada.interactive.jobfolder_path is None
        assert 'jobparams' in shell.user_ns
        assert jobfolder is shell.user_ns['jobparams'].jobfolder

        shell.magic("savefolders {0}/dict".format(directory))
        pylada.interactive.jobfolder = None
        pylada.interactive.jobfolder_path = None
        shell.magic("explore {0}/dict".format(directory))
        jobfolder = pylada.interactive.jobfolder
        assert 'this/0' in jobfolder and 'this/1' in jobfolder and 'that/2' in jobfolder and 'that/1'
        assert '0' in jobfolder['this'] and '1' in jobfolder['this']
        assert '1' in jobfolder['that'] and '2' in jobfolder['that']
        assert 'other' not in jobfolder
        for job in jobfolder.values():
            assert repr(job.functional) == repr(functional)
        assert getattr(jobfolder['this/0'], 'indiv', 0) == 10
        assert getattr(jobfolder['this/1'], 'indiv', 0) == 15
        assert getattr(jobfolder['that/1'], 'indiv', 0) == 20
        assert getattr(jobfolder['that/2'], 'indiv', 0) == 20
        assert not hasattr(jobfolder['this/0'], 'value')
        assert not hasattr(jobfolder['this/1'], 'value')
        assert getattr(jobfolder['that/1'], 'value', False)
        assert getattr(jobfolder['that/2'], 'value', False)
        assert pylada.interactive.jobfolder_path is not None
        assert 'jobparams' in shell.user_ns
        assert jobfolder is shell.user_ns['jobparams'].jobfolder
        assert jobfolder is shell.user_ns['collect'].jobfolder

        for name, job in root.items():
            if name == 'this/1':
                continue
            job.compute(outdir=join(directory, name))

        shell.magic("explore results".format(directory))
        assert {'/this/0/', '/that/1/', '/that/2/'} \
            == set(shell.user_ns['collect'].keys())
        shell.magic("explore errors".format(directory))
        assert len(shell.user_ns['collect']) == 0
        shell.magic("explore all".format(directory))
        shell.magic("explore errors".format(directory))
        assert set(shell.user_ns['collect'].keys()) == {'/this/1/'}

    finally:
        if directory != '/tmp/test':
            rmtree(directory)
        pass