Example #1
0
def test_get_rules():
    with patch('thefuck.main.Path.glob') as glob, \
            patch('thefuck.main.load_source',
                  lambda x, _: Mock(match=x, get_new_command=x)):
        glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
        assert main.get_rules(Path('~'), Mock(rules=None)) == [
            main.Rule('bash', 'bash'),
            main.Rule('lisp', 'lisp'),
            main.Rule('bash', 'bash'),
            main.Rule('lisp', 'lisp')
        ]
        assert main.get_rules(Path('~'), Mock(rules=['bash'])) == [
            main.Rule('bash', 'bash'),
            main.Rule('bash', 'bash')
        ]
Example #2
0
def test_get_rules():
    with patch('thefuck.main.Path.glob') as glob, \
            patch('thefuck.main.load_source',
                  lambda x, _: Mock(match=x, get_new_command=x)):
        glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
        assert main.get_rules(
            Path('~'),
            Mock(rules=None)) == [main.Rule('bash', 'bash'),
                                  main.Rule('lisp', 'lisp'),
                                  main.Rule('bash', 'bash'),
                                  main.Rule('lisp', 'lisp')]
        assert main.get_rules(
            Path('~'),
            Mock(rules=['bash'])) == [main.Rule('bash', 'bash'),
                                      main.Rule('bash', 'bash')]
Example #3
0
 def test_get(self, monkeypatch, glob, conf_rules, rules):
     glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
     monkeypatch.setattr('thefuck.main.load_source',
                         lambda x, _: Rule(x))
     assert self._compare_names(
         main.get_rules(Path('~'), Mock(rules=conf_rules, priority={})),
         rules)
Example #4
0
def test_get_rules(monkeypatch, conf_rules, rules):
    monkeypatch.setattr(
        'thefuck.main.Path.glob',
        lambda *_: [PosixPath('bash.py'), PosixPath('lisp.py')])
    monkeypatch.setattr('thefuck.main.load_source',
                        lambda x, _: Mock(match=x, get_new_command=x,
                                          enabled_by_default=True))
    assert list(main.get_rules(Path('~'), Mock(rules=conf_rules))) == rules
Example #5
0
def test_get_rules():
    with patch('thefuck.main.Path.glob') as glob, \
            patch('thefuck.main.load_source',
                  lambda x, _: Mock(match=x, get_new_command=x,
                                    enabled_by_default=True)):
        glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
        assert list(main.get_rules(
            Path('~'),
            Mock(rules=conf.DEFAULT_RULES))) \
               == [Rule('bash', 'bash', 'bash'),
                   Rule('lisp', 'lisp', 'lisp'),
                   Rule('bash', 'bash', 'bash'),
                   Rule('lisp', 'lisp', 'lisp')]
        assert list(main.get_rules(
            Path('~'),
            Mock(rules=types.RulesNamesList(['bash'])))) \
               == [Rule('bash', 'bash', 'bash'),
                   Rule('bash', 'bash', 'bash')]
Example #6
0
def test_get_rules():
    with patch('thefuck.main.Path.glob') as glob, \
            patch('thefuck.main.load_source',
                  lambda x, _: Mock(match=x, get_new_command=x,
                                    enabled_by_default=True)):
        glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
        assert list(main.get_rules(
            Path('~'),
            Mock(rules=conf.DEFAULT_RULES))) \
               == [types.Rule('bash', 'bash', 'bash', True),
                   types.Rule('lisp', 'lisp', 'lisp', True),
                   types.Rule('bash', 'bash', 'bash', True),
                   types.Rule('lisp', 'lisp', 'lisp', True)]
        assert list(main.get_rules(
            Path('~'),
            Mock(rules=types.RulesNamesList(['bash'])))) \
               == [types.Rule('bash', 'bash', 'bash', True),
                   types.Rule('bash', 'bash', 'bash', True)]
Example #7
0
 def test_ordered_by_priority(self, monkeypatch, unordered, ordered):
     monkeypatch.setattr('thefuck.main._get_loaded_rules',
                         lambda *_: unordered)
     assert self._compare_names(main.get_rules(Path('~'), Mock()), ordered)
Example #8
0
 def test_ordered_by_priority(self, monkeypatch, priority, unordered,
                              ordered):
     monkeypatch.setattr('thefuck.main._get_loaded_rules',
                         lambda *_: unordered)
     assert self._compare_names(
         main.get_rules(Path('~'), Mock(priority=priority)), ordered)
Example #9
0
 def test_get(self, monkeypatch, glob, conf_rules, rules):
     glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
     monkeypatch.setattr('thefuck.main.load_source', lambda x, _: Rule(x))
     assert self._compare_names(
         main.get_rules(Path('~'), Mock(rules=conf_rules, priority={})),
         rules)