def mock_open(data=None):
    if not data:
        data = {}

    namespace = '__builtin__.open' if is_python_2() else 'builtins.open'

    mock_open = mock.mock_open(read_data=json.dumps(data))
    with mock.patch(namespace, mock_open):
        yield mock_open
Exemplo n.º 2
0
def test_version(capsys):
    with pytest.raises(SystemExit) as e:
        ServerParserBuilder().parse_args(['--version'])

    assert str(e.value) == '0'

    # Oh, the joys of writing compatible code
    if is_python_2():  # pragma: no cover
        assert capsys.readouterr().err.strip() == detect_secrets_server.__version__
    else:  # pragma: no cover
        assert capsys.readouterr().out.strip() == detect_secrets_server.__version__
Exemplo n.º 3
0
import hashlib
import os
import subprocess
from abc import ABCMeta
from abc import abstractmethod

from detect_secrets.core.log import log

from .core import git
from detect_secrets_server.util.version import is_python_2

if is_python_2():  # pragma: no cover
    FileNotFoundError = IOError
    import urlparse
else:
    import urllib.parse as urlparse


class BaseStorage(object):
    """The base class handles git interactions with the local copy
    of the git repositories.

    Structure:
        root
          |- repos      # This is where git repos are cloned to
    """
    __metaclass__ = ABCMeta

    def __init__(self, base_directory):
        self.root = base_directory