File: test_open.py

package info (click to toggle)
thefuck 3.32-0.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,132 kB
  • sloc: python: 12,011; makefile: 5; sh: 2
file content (49 lines) | stat: -rw-r--r-- 1,418 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pytest
from thefuck.rules.open import is_arg_url, match, get_new_command
from thefuck.types import Command


@pytest.fixture
def output(script):
    return 'The file {} does not exist.\n'.format(script.split(' ', 1)[1])


@pytest.mark.parametrize('script', [
    'open foo.com',
    'open foo.edu',
    'open foo.info',
    'open foo.io',
    'open foo.ly',
    'open foo.me',
    'open foo.net',
    'open foo.org',
    'open foo.se',
    'open www.foo.ru'])
def test_is_arg_url(script):
    assert is_arg_url(Command(script, ''))


@pytest.mark.parametrize('script', ['open foo', 'open bar.txt', 'open egg.doc'])
def test_not_is_arg_url(script):
    assert not is_arg_url(Command(script, ''))


@pytest.mark.parametrize('script', [
    'open foo.com',
    'xdg-open foo.com',
    'gnome-open foo.com',
    'kde-open foo.com',
    'open nonest'])
def test_match(script, output):
    assert match(Command(script, output))


@pytest.mark.parametrize('script, new_command', [
    ('open foo.io', ['open http://foo.io']),
    ('xdg-open foo.io', ['xdg-open http://foo.io']),
    ('gnome-open foo.io', ['gnome-open http://foo.io']),
    ('kde-open foo.io', ['kde-open http://foo.io']),
    ('open nonest', ['touch nonest && open nonest',
                     'mkdir nonest && open nonest'])])
def test_get_new_command(script, new_command, output):
    assert get_new_command(Command(script, output)) == new_command