예제 #1
0
파일: conftest.py 프로젝트: jshwi/pyaud
    def _init_test_repo():
        with pyaud.Git(pyaud.environ.env["PROJECT_DIR"]) as git:
            git.init(devnull=True)

        pathlib.Path(pyaud.environ.env["README_RST"]).touch()

        with pyaud.Git(pyaud.environ.env["PROJECT_DIR"]) as git:
            git.add(".")
            git.commit("-m", "Initial commit", devnull=True)
예제 #2
0
파일: conftest.py 프로젝트: jshwi/pyaud
    def _make_deploy_env():
        init_test_repo()
        make_written.readme()
        pathlib.Path(pyaud.environ.env["PROJECT_DIR"], "emptyfile").touch()
        with pyaud.Git(pyaud.environ.env["PROJECT_DIR"]) as git:
            git.add(".", devnull=True)
            git.commit("-m", "empty commit", devnull=True)

        with pyaud.Git(pyaud.environ.env["PROJECT_DIR"]) as git:
            git.remote("add", "origin", "origin", devnull=True)
예제 #3
0
def test_out_of_range_unversioned(tmpdir, main, other_dir, patch_sp_call):
    """Test that ``pyaud.pyitems.items`` populates when running on a
    path outside the user's "$PWD". If no properly populated an
    IndexError like the following would be raised:

        File "/*/**/python3.8/site-packages/pyaud/src/__init__.py",
        line 62, in exclude_unversioned
        self.items.pop(count)
        IndexError: pop index out of range

    :param tmpdir:              ``pytest`` ``tmpdir`` fixture for
                                creating and returning a temporary
                                directory.
    :param main:                Fixture for mocking ``pyaud.main``.
    :param other_dir:           Random directory existing in ``tmpdir``.
    :param patch_sp_call:       Patch ``pyaud.Subprocess.call``.
    """
    def empty_func(*_, **__):
        # this is meant to be empty
        pass

    project_clone = os.path.join(tmpdir, "pyaud")
    with pyaud.Git(project_clone) as git:
        git.clone(tests.REAL_REPO)
    patch_sp_call(0, empty_func)
    items = [
        os.path.join(project_clone, "pyaud"),
        os.path.join(project_clone, "setup.py"),
        os.path.join(project_clone, "tests"),
    ]
    with pyaud.EnterDir(other_dir):
        main("lint", "--path", "../pyaud")
        for item in items:
            assert item in pyaud.pyitems.items
예제 #4
0
def test_get_branch_unique(init_test_repo):
    """Test that ``pyaud.pyaud.get_branch`` returns a unique
    timestamped branch after checkout out new branch from ``master``.
    """
    init_test_repo()
    branch = datetime.datetime.now().strftime("%d%m%YT%H%M%S")
    with pyaud.Git(pyaud.environ.env["PROJECT_DIR"]) as git:
        git.checkout("-b", branch, devnull=True)
        assert pyaud.get_branch() == branch
예제 #5
0
def test_get_branch_initial_commit(init_test_repo):
    """Test that ``pyaud.pyaud.get_branch`` returns None when run from
    the a commit with no parent commits i.e. initial commit.
    """
    init_test_repo()
    with pyaud.Git(pyaud.environ.env["PROJECT_DIR"]) as git:
        git.config("advice.detachedHead", "false")
        git.rev_list("--max-parents=0", "HEAD", capture=True)
        git.checkout(git.stdout.strip(), devnull=True)
        assert pyaud.get_branch() is None
예제 #6
0
def test_git_clone(tmpdir):
    """Test that the ``pyaud.Git`` class can properly clone a
    repository

    :param tmpdir:  ``pytest`` ``tmpdir`` fixture for creating and
                    returning a temporary directory.
    """
    with pyaud.Git(os.path.join(tmpdir, "cloned_repo")) as git:
        git.clone(tests.REAL_REPO)

    assert filecmp.dircmp(tests.REAL_REPO, pyaud.environ.env["PROJECT_DIR"])
예제 #7
0
def test_pipe_to_file():
    """Test that the ``pyaud.Subprocess`` class correctly writes to a
    file when the ``file`` keyword argument is used.
    """
    gitdir = os.path.join(pyaud.environ.env["PROJECT_DIR"], ".git") + os.sep
    piped_file = os.path.join(pyaud.environ.env["PROJECT_DIR"], "pipe.txt")
    expected = "Initialized empty Git repository in " + gitdir
    with pyaud.Git(pyaud.environ.env["PROJECT_DIR"]) as git:
        git.init(file=piped_file)

    with open(piped_file) as fin:
        assert fin.read().strip() == expected
예제 #8
0
파일: conftest.py 프로젝트: jshwi/pyaud
def fixture_mock_remote_origin(tmpdir):
    """Create a local bare repository to push to instead of a remote
    origin URL. Return the path of the 'remote' as the fixture object.

    :param tmpdir:  ``pytest`` ``tmpdir`` fixture for creating and
                    returning a temporary directory.
    """
    remote_origin = os.path.join(tmpdir, "origin.git")
    with pyaud.Git(remote_origin) as git:
        git.init("--bare", ".", devnull=True)

    return remote_origin
예제 #9
0
def test_arg_order_clone(tmpdir, patch_sp_call, nocolorcapsys):
    """Test that the clone destination is always the last argument.

    :param tmpdir:          ``pytest`` ``tmpdir`` fixture for creating
                            and returning a temporary directory.
    :param patch_sp_call:   Patch ``pyaud.Subprocess.call``.
    :param nocolorcapsys:   ``capsys`` without ANSI color codes.
    """
    patch_sp_call()
    project_clone = os.path.join(tmpdir, "pyaud")
    expected = (f"git clone --depth 1 --branch v1.1.0 {tests.REAL_REPO} "
                f"{project_clone}")
    with pyaud.Git(project_clone) as git:
        git.clone("--depth", "1", "--branch", "v1.1.0", tests.REAL_REPO)
        assert nocolorcapsys.stdout().strip() == expected
예제 #10
0
def test_git_context_no_artifact(tmpdir):
    """Ensure that no dir remains if no action occurs inside created
    dir. This functionality exists for cloning directories to keep
    ``pyaud.Git``s context action intact.

    :param tmpdir:  ``pytest`` ``tmpdir`` fixture for creating and
                    returning a temporary directory.
    """
    tmprepo = os.path.join(tmpdir, "test_repo")
    with pyaud.Git(tmprepo):

        # do nothing within repo but new dir is created in order for
        # context action of entering repo to work
        assert os.path.isdir(tmprepo)

    # ensure ``tmprepo`` has been removed
    assert not os.path.isdir(tmprepo)
예제 #11
0
def test_remove_unversioned(init_test_repo):
    """Test that when a file is not under version control and the
    ``pyaud.pyitems.exclude_unversioned`` method  is called unversioned
    files are removed from ``pyitems.items`` list.

    :param init_test_repo:  Create a git repository with an initial
                            commit.
    """
    init_test_repo()
    file_py = os.path.join(pyaud.environ.env["PROJECT_DIR"], FILES)
    pathlib.Path(file_py).touch()
    pyaud.pyitems.get_files()
    assert file_py in pyaud.pyitems.items
    pyaud.pyitems.exclude_unversioned()
    assert file_py not in pyaud.pyitems.items
    with pyaud.Git(pyaud.environ.env["PROJECT_DIR"]) as git:
        git.add(".")
        git.commit("-m", "committing file.py")

    pyaud.pyitems.get_files()
    assert file_py in pyaud.pyitems.items
    pyaud.pyitems.exclude_unversioned()
    assert file_py in pyaud.pyitems.items
예제 #12
0
파일: conftest.py 프로젝트: jshwi/pyaud
def fixture_set_git_creds():
    """Set git credentials."""
    git = pyaud.Git(pyaud.environ.env["PROJECT_DIR"])
    git.config("--global", "user.email", os.environ["PYAUD_TEST_GH_EMAIL"])
    git.config("--global", "user.name", os.environ["PYAUD_TEST_GH_NAME"])