Esempio n. 1
0
 def setUp(self):
     Shell.run('rm -rf {}'.format(test_dir))
     self.prepare_test_dir(test_local_dir)
     nvim.command('silent tabe {}'.format(test_local_dir))
     self.ensure_buf_no_expand()
     # Clear all previous selection
     nvim.input('u')
Esempio n. 2
0
    def test_size_display(self):
        Shell.run('echo {} > {}'.format('a' * 1035, 'a'))
        Shell.run('echo {} > {}'.format('b' * 1024, 'b'))

        nvim.command('edit .')
        nvim.input('Gk')

        self.assertEqual('1.01 K', self.clineinfo.size_str)

        nvim.input('j')
        self.assertEqual('1 K', self.clineinfo.size_str)
Esempio n. 3
0
def test_bookmark():
    Shell.run('rm -f {}'.format(nvim.vars['NETRBookmarkFile']))

    nvim.input('mal')
    nvim.input("'a")
    assert_content('dir')

    nvim.input('lemjrb')
    nvim.command('exit')
    time.sleep(0.5)
    nvim.input("'b")
    assert_content('dir')
Esempio n. 4
0
    def setUp(self):

        Shell.run('rm -rf {}'.format(test_dir))
        self.prepare_test_dir(test_local_dir)
        self.prepare_test_dir(test_remote_dir)
        Shell.run('rm -rf {}/*'.format(test_remote_cache_dir))
        nvim.command('NETRemoteList')
        # There is only one remote configure by netrtest_rclone.conf
        nvim.input('l')
        nvim.command('NETRemotePull')
        nvim.command('call cursor(2, 1)')
        self.ensure_buf_no_expand()
        # Clear all previous selection
        nvim.input('u')
Esempio n. 5
0
def test_sort():
    # only test extension, mtime, size
    # extension: [a, a.a, a.b]
    # size: [a.b, a.a, a]
    # mtime: [a, a.b, a.a]
    Shell.run('echo {} > dir/{}'.format('a' * 3, 'a'))
    Shell.run('echo {} > dir/{}'.format('a' * 2, 'a.a'))
    Shell.run('echo {} > dir/{}'.format('a' * 1, 'a.b'))
    time.sleep(0.01)
    Shell.run('touch dir/a.a')

    nvim.input('zaSe')
    assert_content('dir', ind=0, hi='dir', level=0)
    assert_content('a', ind=3, hi='file', level=1)
    assert_content('a.a', ind=4, hi='file', level=1)
    assert_content('a.b', ind=5, hi='file', level=1)
    assert_content('dir2', ind=6, hi='dir', level=0)

    nvim.input('SE')
    assert_content('dir2', ind=0, hi='dir', level=0)
    assert_content('dir', ind=1, hi='dir', level=0)
    assert_content('a.b', ind=2, hi='file', level=1)
    assert_content('a.a', ind=3, hi='file', level=1)
    assert_content('a', ind=4, hi='file', level=1)

    nvim.input('Ss')
    assert_content('dir2', ind=0, hi='dir', level=0)
    assert_content('dir', ind=1, hi='dir', level=0)
    assert_content('a.b', ind=4, hi='file', level=1)
    assert_content('a.a', ind=5, hi='file', level=1)
    assert_content('a', ind=6, hi='file', level=1)

    nvim.input('SS')
    assert_content('dir', ind=0, hi='dir', level=0)
    assert_content('a', ind=1, hi='file', level=1)
    assert_content('a.a', ind=2, hi='file', level=1)
    assert_content('a.b', ind=3, hi='file', level=1)
    assert_content('dir2', ind=6, hi='dir', level=0)

    nvim.input('Sm')
    assert_content('dir2', ind=0, hi='dir', level=0)
    assert_content('dir', ind=1, hi='dir', level=0)
    assert_content('a', ind=4, hi='file', level=1)
    assert_content('a.b', ind=5, hi='file', level=1)
    assert_content('a.a', ind=6, hi='file', level=1)

    nvim.input('SM')
    assert_content('dir', ind=0, hi='dir', level=0)
    assert_content('a.a', ind=1, hi='file', level=1)
    assert_content('a.b', ind=2, hi='file', level=1)
    assert_content('a', ind=3, hi='file', level=1)
    assert_content('dir2', ind=6, hi='dir', level=0)
    nvim.input('Sd')
Esempio n. 6
0
    def assert_fs(self, d, expect, root=test_local_dir):
        """
        Test whether 'expect' exists in directory root/d.
        """
        real = None
        for i in range(10):
            real = Shell.run(
                f'ls --group-directories-first {root}/{d}').split()
            if real == expect:
                return
            time.sleep(0.05)

        self.assertEqual(expect, real)
Esempio n. 7
0
def test_size_wide_char_display():
    # This vsplit is a rather ad-hoc work around in case of the screen is too
    # wide such that the following echo command failed because of too long
    # file name
    nvim.command('vsplit')

    width = nvim.current.window.width

    Shell.run('echo {} > {}'.format('a' * 1035, '測' * width + '.pdf'))
    Shell.run('echo {} > {}'.format('b' * 1024, '試' * width))

    nvim.command('edit .')
    nvim.input('Gk')
    assert cLine_ends_with(
        '~.pdf 1.01 K'), 'size display abbreviation fail: a~.pdf {}'.format(
            nvim.current.line[-10:])
    nvim.input('j')
    assert cLine_ends_with(
        '試~    1 K'), 'size display abbreviation fail: b~ {}'.format(
            nvim.current.line[-10:])

    # close the vsplit
    nvim.command('quit')
Esempio n. 8
0
def assert_fs(d, expected, root=None):
    """
    Test whether 'expected' exists in directory cwd/d, where
    cwd is /tmp/netrtest/local when testing local functions and
    cwd is /tmp/netrtest/remote when testing remote functions.
    """

    if root:
        old_cwd = os.getcwd()
        os.chdir(root)

    real = None
    for i in range(10):
        real = Shell.run('ls --group-directories-first ' + d).split()
        if real == expected:
            return
        time.sleep(0.05)

    assert real == expected, 'expected: {}, real: {}'.format(expected, real)

    if root:
        os.chdir(old_cwd)
Esempio n. 9
0
def test_NETRForceDeleteSingle():
    Shell.run('chmod u-w dir/a')
    nvim.input('zajjjXX')
    wait_for_fs_free()
    assert_content('dir2', ind=3, hi='dir', hi_fg=True)
Esempio n. 10
0
def do_test(fn=None, fn_remote=None):
    """
    Note on the mecahnism of testing rclone on localhost:
    1. Tester run rclone to create a "local" remote named netrtest (must be
       exact this name)
    2. In default.py, the vim variable 'NETRemoteRoots' is set to
       {test_remote_name: test_remote_dir}, which defaults to
       {'netrtest', '/tmp/netrtest/remote'}.
    3. 'NETRemoteRoots' is passed to Rclone constructor, so that the rpath
       of the netrtest remote is mapped to '/tmp/netrtest/remote'.
    4. This just works in netranger. In cmd line, running
       'rclone lsl netrtest:/' still shows you the content of the root
       directory of the localhost.
    """
    old_cwd = os.getcwd()
    Shell.run('rm -rf {}'.format(test_dir))

    def prepare_test_dir(dirname):
        Shell.mkdir(dirname)
        os.chdir(dirname)
        Shell.mkdir('dir/subdir')
        Shell.mkdir('dir/subdir/subsubdir')
        Shell.mkdir('dir/subdir2')
        Shell.touch('dir/a')
        Shell.touch('.a')
        Shell.mkdir('dir2/')

        # The following should be removed when rclone fix "not copying empty
        # directories" bug.
        Shell.touch('dir/subdir/subsubdir/placeholder')
        Shell.touch('dir/subdir2/placeholder')
        Shell.touch('dir/subdir2/placeholder')

    prepare_test_dir(test_local_dir)
    if fn is not None:
        nvim.command('silent tabe {}'.format(test_local_dir))
        ensure_buf_no_expand()
        fn()
        print('== {} success =='.format(str(fn.__name__)))

    prepare_test_dir(test_remote_dir)
    Shell.run('rm -rf {}/*'.format(test_remote_cache_dir))
    if fn_remote is not None:
        nvim.command('NETRemoteList')
        found_remote = False
        for i, line in enumerate(nvim.current.buffer):
            if re.findall('.+(netrtest)', line):
                nvim.command('call cursor({}, 1)'.format(i + 1))
                found_remote = True
                break

        assert found_remote, 'You must set up an rclone remote named "{}" \
            to test remote function'.format(test_remote_name)
        nvim.input('l')
        nvim.command('NETRemotePull')
        nvim.command('call cursor(2, 1)')
        ensure_buf_no_expand()
        fn_remote()
        print('== {} success =='.format(str(fn_remote.__name__)))

    while nvim.eval('&ft') == 'netranger':
        nvim.command('bwipeout')
    os.chdir(old_cwd)
Esempio n. 11
0
 def test_NETRForceDeleteSingle(self):
     Shell.run('chmod u-w dir/a')
     nvim.input('zajjjXX')
     self.wait_for_fs_free()
     self.assert_content('dir2', ind=3, hi='dir')