예제 #1
0
def testpathmv_relativereplace():
    """
    Verify that the code also matches and replace ~/paths as opposed to just /home/user1/paths
    """
    testpathmv_setup()
    # verify this test can be performed - only possible if this project is saved somewhere in the current user's home directory
    if not str(__projectdir__).startswith(os.path.expanduser('~') + os.sep):
        print(
            'TEST NOT POSSIBLE for testpathmv_relativereplace. To do this test, project needs to be saved in user\'s home directory on a UNIX system.'
        )
        return (None)

    # adjust writing in the file
    with open(__projectdir__ / Path('testpathmv/file1.txt'), 'w') as f:
        f.write(
            str(__projectdir__ / Path('testpathmv/file1.txt')).replace(
                os.path.expanduser('~') + '/', '', 1))

    pathmv_main([
        str(__projectdir__ / Path('testpathmv/file1.txt')),
        str(__projectdir__ / Path('testpathmv/file2.txt'))
    ], [str(__projectdir__ / Path('testpathmv/file1.txt'))])

    with open(__projectdir__ / Path('testpathmv/file2.txt')) as f:
        text = f.read()
    if 'file2.txt' not in text:
        raise ValueError('Match failed')
예제 #2
0
def testpathmv_basic():
    testpathmv_setup()

    pathmv_main([
        str(__projectdir__ / Path('testpathmv/file1.txt')),
        str(__projectdir__ / Path('testpathmv/file2.txt'))
    ], [str(__projectdir__ / Path('testpathmv/file1.txt'))])

    with open(__projectdir__ / Path('testpathmv/file2.txt')) as f:
        text = f.read()
    if 'file2.txt' not in text:
        raise ValueError('Match failed')
예제 #3
0
def testpathmv_relpathinputs():
    """
    Verify that when relative paths are inputted into pathmv, it performs correctly
    """
    testpathmv_setup()

    pathmv_main([
        os.path.relpath(str(__projectdir__ / Path('testpathmv/file1.txt'))),
        os.path.relpath(str(__projectdir__ / Path('testpathmv/file2.txt')))
    ], [os.path.relpath(str(__projectdir__ / Path('testpathmv/file1.txt')))])

    with open(__projectdir__ / Path('testpathmv/file2.txt')) as f:
        text = f.read()
    if 'file2.txt' not in text:
        raise ValueError('Match failed')