Ejemplo n.º 1
0
def test_touch():
    path = os.path.join(test_data_dir, 'touch')
    if exists(path):
        remove(path)
    ensure_dir(path)

    for file in ['a.txt', 'b.txt', 'c.txt']:
        touch(file, path=path)
    for file in ['a.txt', 'b.txt', 'c.txt']:
        assert exists(os.path.join(path, file))
    remove(path)
Ejemplo n.º 2
0
def test_touch():
    path = os.path.join('data', 'touch')
    if exists(path, connection=leibniz1):
        remove(path, connection=leibniz1)
    ensure_dir(path, connection=leibniz1)

    for file in ['a.txt', 'b.txt', 'c.txt']:
        touch(file, path=path, connection=leibniz1)
    for file in ['a.txt', 'b.txt', 'c.txt']:
        p = os.path.join(path, file)
        assert exists(p, connection=leibniz1)

    remove(path, connection=leibniz1)
Ejemplo n.º 3
0
def test_ensure_dir_inexisting():
    # make sure that inexisting does not yet exists
    inexisting = os.path.join(test_data_dir, 'inexisting')
    if exists(inexisting):
        remove(inexisting)
    assert not exists(inexisting)

    # make inexisting and check
    ensure_dir(inexisting)
    assert exists(inexisting)
    # clean up
    remove(inexisting)
    assert not exists(inexisting)
Ejemplo n.º 4
0
def test_ensure_dir_inexisting():
    # make sure that inexisting does not yet exists
    inexisting = os.path.join('data', 'inexisting')
    if exists(inexisting, connection=leibniz1):
        remove(inexisting, connection=leibniz1)
    assert not exists(inexisting, connection=leibniz1)

    # make inexisting and check
    ensure_dir(inexisting, connection=leibniz1)

    assert exists(inexisting, connection=leibniz1)

    # clean up
    remove(inexisting, connection=leibniz1)
    assert not exists(inexisting, connection=leibniz1)
Ejemplo n.º 5
0
def test_rename():
    # set up
    test_dir = os.path.join(test_data_dir, 'rename')
    ensure_dir(test_dir)
    old = os.path.join(test_dir, 'old.txt')
    touch(old)
    assert exists(old)

    # test
    new = os.path.join(test_dir, 'new.txt')
    rename(old, new)
    assert not exists(old)
    assert exists(new)

    # clean up
    remove(test_dir)
Ejemplo n.º 6
0
def test_rename():
    # set up
    test_dir = os.path.join('data', 'rename')
    ensure_dir(test_dir, connection=leibniz1)
    old = os.path.join(test_dir, 'old.txt')
    touch(old, connection=leibniz1)
    assert exists(old, connection=leibniz1)

    # test
    new = os.path.join(test_dir, 'new.txt')
    rename(old, new, connection=leibniz1)
    assert not exists(old, connection=leibniz1)
    assert exists(new, connection=leibniz1)

    # clean up
    remove(test_dir, connection=leibniz1)
Ejemplo n.º 7
0
def test_repeated_execution_succeeds():
    newdir = os.path.join(test_data_dir, 'newdir')
    try:
        remove(newdir)
    except:
        pass

    # this command should succeeds the second time
    cmd = "./test_succeeds_the_second_time.sh"
    result = run(cmd,
                 working_directory=test_data_dir,
                 attempts=3,
                 verbose=True,
                 wait=.5)
    assert result.attempts == 2
    assert exists(newdir)

    # clean up
    remove(newdir)
Ejemplo n.º 8
0
def test_repeated_execution_succeeds():
    # setup
    newdir = os.path.join('data', 'newdir')
    try:
        remove(newdir, leibniz1)
    except:
        pass
    assert not exists(newdir, leibniz1)

    src_sh = os.path.join(test_data_dir, 'test_succeeds_the_second_time.sh')
    assert exists('data', leibniz1)
    dst_sh = os.path.join('data', 'test_succeeds_the_second_time.sh')
    remove(dst_sh, leibniz1)
    copy_local_to_remote(leibniz1, src_sh, dst_sh)
    assert exists(dst_sh, leibniz1)
    assert not exists(dst_sh, leibniz1, operator='-x')
    run('chmod +x test_succeeds_the_second_time.sh',
        leibniz1,
        working_directory='data')
    assert exists(dst_sh, leibniz1, operator='-x')

    # test
    # this command should succeeds the second time
    cmd = "./test_succeeds_the_second_time.sh"
    result = run(cmd,
                 leibniz1,
                 working_directory='data',
                 attempts=3,
                 wait=.5,
                 verbose=True)
    assert result.attempts == 2
    assert exists(newdir, leibniz1)

    # clean up
    remove(newdir, leibniz1)
    assert not exists(newdir, leibniz1)
    remove(dst_sh, leibniz1)
    assert not exists(dst_sh, leibniz1)
Ejemplo n.º 9
0
def test_glob():
    path = os.path.join(test_data_dir, 'glob')
    if exists(path):
        remove(path)
    ensure_dir(path)
    files = ['a.txt', 'b.txt', 'c.txt', 'aa.txt']
    for file in files:
        touch(file, path=path)
    dirs = ['a.tx', 'd.txt']
    for folder in dirs:
        ensure_dir(os.path.join(path, folder))

    result = glob('*.txt', path=path)
    assert len(result) == 4
    for file in result:
        assert file in files

    result = glob('?.txt', path=path)
    assert len(result) == 3
    for file in result:
        assert file in files

    # clean up
    remove(path)
Ejemplo n.º 10
0
def test_ensure_dir_existing():
    assert exists(test_data_dir)
    ensure_dir(test_data_dir)
    assert exists(test_data_dir)
Ejemplo n.º 11
0
def test_exists_inexisting():
    assert not exists(os.path.join(test_data_dir, 'inexisting'))
Ejemplo n.º 12
0
def test_exists_existing():
    assert exists(test_data_dir)
Ejemplo n.º 13
0
def test_ensure_dir_existing():
    assert exists('data', connection=leibniz1)
    ensure_dir('data', connection=leibniz1)
    assert exists('data', connection=leibniz1)
Ejemplo n.º 14
0
def test_exists_inexisting():
    assert not exists('inexisting', connection=leibniz1)
Ejemplo n.º 15
0
def test_exists_existing():
    assert exists('data', connection=leibniz1)