Esempio n. 1
0
def _get_all_environments():
    root = Path('~/.virtualenvs').expanduser()
    if not root.is_dir():
        return

    for child in root.iterdir():
        if child.is_dir():
            yield child.name
Esempio n. 2
0
def test_get_rules_rule_exception(mocker, glob):
    load_source = mocker.patch(
        'thedarn.types.load_source',
        side_effect=ImportError("No module named foo..."))
    glob([Path('git.py')])
    assert not corrector.get_rules()
    load_source.assert_called_once_with('git', 'git.py')
Esempio n. 3
0
def settings(request):
    def _reset_settings():
        conf.settings.clear()
        conf.settings.update(const.DEFAULT_SETTINGS)

    request.addfinalizer(_reset_settings)
    conf.settings.user_dir = Path('~/.thedarn')
    return conf.settings
Esempio n. 4
0
 def test_get_rules(self, glob, settings, paths, conf_rules, exclude_rules,
                    loaded_rules):
     glob([Path(path) for path in paths])
     settings.update(rules=conf_rules,
                     priority={},
                     exclude_rules=exclude_rules)
     rules = corrector.get_rules()
     self._compare_names(rules, loaded_rules)
Esempio n. 5
0
def get_new_command(command):
    destination = _get_destination(command)
    paths = _get_all_absolute_paths_from_history(command)

    return [
        replace_argument(command.script, destination, path) for path in paths
        if path.endswith(destination) and Path(path).expanduser().exists()
    ]
Esempio n. 6
0
 def test_from_path(self, mocker):
     match = object()
     get_new_command = object()
     load_source = mocker.patch('thedarn.types.load_source',
                                return_value=Mock(
                                    match=match,
                                    get_new_command=get_new_command,
                                    enabled_by_default=True,
                                    priority=900,
                                    requires_output=True))
     rule_path = os.path.join(os.sep, 'rules', 'bash.py')
     assert (Rule.from_path(Path(rule_path)) == Rule('bash',
                                                     match,
                                                     get_new_command,
                                                     priority=900))
     load_source.assert_called_once_with('bash', rule_path)
Esempio n. 7
0
 def test_from_path_excluded_rule(self, mocker, settings):
     load_source = mocker.patch('thedarn.types.load_source')
     settings.update(exclude_rules=['git'])
     rule_path = os.path.join(os.sep, 'rules', 'git.py')
     assert Rule.from_path(Path(rule_path)) is None
     assert not load_source.called
Esempio n. 8
0
 def test_from_path_rule_exception(self, mocker):
     load_source = mocker.patch(
         'thedarn.types.load_source',
         side_effect=ImportError("No module named foo..."))
     assert Rule.from_path(Path('git.py')) is None
     load_source.assert_called_once_with('git', 'git.py')
Esempio n. 9
0
def source_root():
    return Path(__file__).parent.parent.resolve()
Esempio n. 10
0
def _get_missing_file(command):
    pathspec = re.findall(
        r"error: pathspec '([^']*)' "
        r'did not match any file\(s\) known to git.', command.output)[0]
    if Path(pathspec).exists():
        return pathspec
Esempio n. 11
0
def _get_actual_scm():
    for path, scm in path_to_scm.items():
        if Path(path).is_dir():
            return scm