Exemplo n.º 1
0
def test_patch_strip_level(testing_workdir, monkeypatch):
    patchfiles = set(('some/common/prefix/one.txt',
                      'some/common/prefix/two.txt',
                      'some/common/prefix/three.txt'))
    folders = ('some', 'common', 'prefix')
    files = ('one.txt', 'two.txt', 'three.txt')
    os.makedirs(os.path.join(*folders))
    for file in files:
        with open(os.path.join(os.path.join(*folders), file), 'w') as f:
            f.write('hello\n')
    assert _guess_patch_strip_level(patchfiles, os.getcwd()) == (0, False)
    monkeypatch.chdir(folders[0])
    assert _guess_patch_strip_level(patchfiles, os.getcwd()) == (1, False)
    monkeypatch.chdir(folders[1])
    assert _guess_patch_strip_level(patchfiles, os.getcwd()) == (2, False)
    monkeypatch.chdir(folders[2])
    assert _guess_patch_strip_level(patchfiles, os.getcwd()) == (3, False)
    monkeypatch.chdir(testing_workdir)
Exemplo n.º 2
0
def test_patch_strip_level(testing_workdir, monkeypatch):
    patchfiles = set(('some/common/prefix/one.txt',
                      'some/common/prefix/two.txt',
                      'some/common/prefix/three.txt'))
    folders = ('some', 'common', 'prefix')
    files = ('one.txt', 'two.txt', 'three.txt')
    os.makedirs(os.path.join(*folders))
    for file in files:
        with open(os.path.join(os.path.join(*folders), file), 'w') as f:
            f.write('hello\n')
    assert _guess_patch_strip_level(patchfiles, os.getcwd()) == 0
    monkeypatch.chdir(folders[0])
    assert _guess_patch_strip_level(patchfiles, os.getcwd()) == 1
    monkeypatch.chdir(folders[1])
    assert _guess_patch_strip_level(patchfiles, os.getcwd()) == 2
    monkeypatch.chdir(folders[2])
    assert _guess_patch_strip_level(patchfiles, os.getcwd()) == 3
    monkeypatch.chdir(testing_workdir)
Exemplo n.º 3
0
def test_patch_strip_level():
    patchfiles = set(('some/common/prefix/one.txt',
                      'some/common/prefix/two.txt',
                      'some/common/prefix/three.txt'))
    folders = ('some', 'common', 'prefix')
    files = ('one.txt', 'two.txt', 'three.txt')
    basedir = os.getcwd()
    with TemporaryDirectory() as tmp:
        os.chdir(tmp)
        os.makedirs(os.path.join(tmp, *folders))
        for file in files:
            with open(os.path.join(os.path.join(tmp, *folders), file), 'w') as f:
                f.write('hello\n')
        assert _guess_patch_strip_level(patchfiles, os.getcwd()) == 0
        os.chdir(folders[0])
        assert _guess_patch_strip_level(patchfiles, os.getcwd()) == 1
        os.chdir(folders[1])
        assert _guess_patch_strip_level(patchfiles, os.getcwd()) == 2
        os.chdir(folders[2])
        assert _guess_patch_strip_level(patchfiles, os.getcwd()) == 3
        os.chdir(basedir)