예제 #1
0
def test_line_splitter_unterminated():
    # Expect two lines split at "x", after the second process-call
    line_splitter = LineSplitter("x")
    lines = line_splitter.process("first line")
    assert_equal(lines, [])
    lines = line_splitter.process("xsecond linex")
    assert_equal(lines, ["first line", "second line"])
    assert_is_none(line_splitter.finish_processing())
예제 #2
0
def test_batched_close_abandon():
    # Expect a timeout if the process runs longer than timeout and the config
    # for "datalad.runtime.stalled-external" is "abandon".
    bc = BatchedCommand(cmd=[sys.executable, "-i", "-u", "-q", "-"],
                        timeout=.1)
    # Send at least one instruction to start the subprocess
    response = bc("import time; print('a')")
    assert_equal(response, "a")
    bc.stdin_queue.put("time.sleep(2); exit(1)\n".encode())
    with unittest.mock.patch("datalad.cfg") as cfg_mock:
        cfg_mock.configure_mock(**{"obtain.return_value": "abandon"})
        bc.close(return_stderr=False)
        assert_true(bc.wait_timed_out is True)
        assert_is_none(bc.return_code)
예제 #3
0
def test_command_fail_2():
    # Expect that the return code of a failing command is caught,
    # that None is returned as result and that the process is restarted,
    # if the batched command is called again.
    bc = BatchedCommand(cmd=py2cmd("""
print(a*b)
            """))

    # Send something to start the process
    result = bc("line one")
    assert_not_equal(bc.return_code, 0)
    assert_is_none(result)
    result = bc("line two")
    assert_not_equal(bc.return_code, 0)
    assert_is_none(result)
    bc.close(return_stderr=False)
예제 #4
0
def test_line_splitter_separator():
    line_splitter = LineSplitter("X")
    lines = line_splitter.process(
        "first line\nX"
        "second line\r\nX"
        "third line\nX"
        "\nX"
    )

    assert_equal(lines, [
        "first line\n",
        "second line\r\n",
        "third line\n",
        "\n"
    ])

    assert_is_none(line_splitter.finish_processing())
예제 #5
0
def test_line_splitter_basic():
    line_splitter = LineSplitter()
    lines = line_splitter.process(
        "first line\n"
        "second line\r\n"
        "third line\n"
        "\n"
    )

    assert_equal(
        lines,
        [
            "first line",
            "second line",
            "third line",
            ""
        ])

    assert_is_none(line_splitter.finish_processing())
예제 #6
0
def test_line_splitter_continue():
    line_splitter = LineSplitter()
    lines = line_splitter.process(
        "first line\n"
        "second line\r\n"
        "third line\n"
        "fourth "
    )

    assert_equal(lines, [
        "first line",
        "second line",
        "third line"
    ])

    assert_equal(line_splitter.remaining_data, "fourth ")

    lines = line_splitter.process("line\n")
    assert_equal(lines, ["fourth line"])
    assert_is_none(line_splitter.finish_processing())
예제 #7
0
def test_symlinked_dataset_properties(repo1=None,
                                      repo2=None,
                                      repo3=None,
                                      non_repo=None,
                                      symlink=None):

    ds = Dataset(repo1).create()

    # now, let ds be a symlink and change that symlink to point to different
    # things:
    ar2 = AnnexRepo(repo2)
    ar3 = AnnexRepo(repo3)
    assert_true(os.path.isabs(non_repo))

    os.symlink(repo1, symlink)
    ds_link = Dataset(symlink)
    assert_is(ds_link.repo, ds.repo)  # same Repo instance
    assert_is_not(ds_link, ds)  # but not the same Dataset instance
    assert_is(ds_link.config, ds.repo.config)
    assert_true(ds_link._cfg_bound)
    assert_is_not_none(ds_link.id)
    # same id, although different Dataset instance:
    assert_equal(ds_link.id, ds.id)

    os.unlink(symlink)
    os.symlink(repo2, symlink)

    assert_is(ds_link.repo, ar2)  # same Repo instance
    assert_is(ds_link.config, ar2.config)
    assert_true(ds_link._cfg_bound)
    # id is None again, since this repository is an annex but there was no
    # Dataset.create() called yet.
    assert_is_none(ds_link.id)

    os.unlink(symlink)
    os.symlink(repo3, symlink)

    assert_is(ds_link.repo, ar3)  # same Repo instance
    assert_is(ds_link.config, ar3.config)
    assert_true(ds_link._cfg_bound)
    # id is None again, since this repository is an annex but there was no
    # Dataset.create() called yet.
    assert_is_none(ds_link.id)

    os.unlink(symlink)
    os.symlink(non_repo, symlink)

    assert_is_none(ds_link.repo)
    assert_is_not(ds_link.config, ar3.config)
    assert_false(ds_link._cfg_bound)
    assert_is_none(ds_link.id)
예제 #8
0
def test_property_reevaluation(repo1=None):
    ds = Dataset(repo1)
    assert_is_none(ds.repo)
    assert_is_not_none(ds.config)
    first_config = ds.config
    assert_false(ds._cfg_bound)
    assert_is_none(ds.id)

    ds.create()
    assert_repo_status(repo1)
    # after creation, we have `repo`, and `config` was reevaluated to point
    # to the repo's config:
    assert_is_not_none(ds.repo)
    assert_is_not_none(ds.config)
    second_config = ds.config
    assert_true(ds._cfg_bound)
    assert_is(ds.config, ds.repo.config)
    assert_is_not(first_config, second_config)
    assert_is_not_none(ds.id)
    first_id = ds.id

    ds.drop(what='all', reckless='kill', recursive=True)
    # repo is gone, and config is again reevaluated to only provide user/system
    # level config:
    assert_false(lexists(ds.path))
    assert_is_none(ds.repo)
    assert_is_not_none(ds.config)
    third_config = ds.config
    assert_false(ds._cfg_bound)
    assert_is_not(second_config, third_config)
    assert_is_none(ds.id)

    ds.create()
    assert_repo_status(repo1)
    # after recreation everything is sane again:
    assert_is_not_none(ds.repo)
    assert_is_not_none(ds.config)
    assert_is(ds.config, ds.repo.config)
    forth_config = ds.config
    assert_true(ds._cfg_bound)
    assert_is_not(third_config, forth_config)
    assert_is_not_none(ds.id)
    assert_not_equal(ds.id, first_id)